【发布时间】:2013-06-14 15:20:22
【问题描述】:
这是一个有点奇怪的具体问题。
我正在编写一个将跨十个域运行的 Greasemonkey 脚本。这些网站都有相同的结构,但每个网站的域名不同。例如,脚本将运行在:
http://first-domain.com/
http://another-one.com/
http://you-get-the-point.com/
我还需要它在同一域的其他页面上运行,因此这些域中的一个的列表将类似于:
http://first-domain.com/admin/edit/*
http://first-domain.com/blog/*
http://first-domain.com/user/*/history
显然,如果我为所有十个域都包含这三个路径,那么我需要将 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
如果可能发生这样的事情,它会将@includes 的列表从 30 个减少到 3 个。
这可能吗,还是我在做梦?
PS 我知道我可以只使用@include http://first-domain.com/* 然后使用if 语句在该域中的某些路径上运行脚本的某些部分,但脚本的预期页数运行只占网站的 2% 左右,因此在每个网站的每个页面上都包含脚本似乎很浪费。
【问题讨论】: