这是一个奇怪的具体问题.
我正在编写一个将在十个域中运行的Greasemonkey脚本.这些网站都具有相同的结构,但每个网站的域名不同.例如,脚本将在以下位置运行:
http://first-domain.com/
http://another-one.com/
http://you-get-the-point.com/
Run Code Online (Sandbox Code Playgroud)
我还需要它在相同域中的其他页面上运行,因此这些域中的一个域的列表将类似于:
http://first-domain.com/admin/edit/*
http://first-domain.com/blog/*
http://first-domain.com/user/*/history
Run Code Online (Sandbox Code Playgroud)
显然,如果我为所有十个域包含这三个路径,那么我需要列出30个URL作为@includes.
所以我想知道是否有办法做一些事情:
// Obviously fake code:
var list_of_sites = ["first-domain", "another-one", "you-get-the-point"];
@include http:// + list_of_sites[any] + .com/admin/edit/*
@include http:// + list_of_sites[any] + .com/blog/*
@include http:// + list_of_sites[any] + .com/user/*/history
Run Code Online (Sandbox Code Playgroud)
如果这样的事情成为可能,它会将@includes 的列表从30减少到3.
这是可能的,还是我在做梦?
PS我知道我可以只@include http://first-domain.com/*使用if语句在该域内的某些路径上运行脚本的某些部分,但脚本要运行的页面数量仅占网站的2%左右,因此看起来很浪费在每个网站的每个页面上包含脚本.