gpt4 book ai didi

greasemonkey - 包括跨多个域的 Greasemonkey 脚本

转载 作者:行者123 更新时间:2023-12-03 20:18:21 26 4
gpt4 key购买 nike

这是一个有点奇怪的具体问题。

我正在编写一个可以跨十个域运行的 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 列为 @include s。

所以我想知道是否有办法做这样的事情:
// 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

如果这样的事情可能,它会削减 @include 的列表s 从 30 降到 3。

那么这是可能的,还是我在做梦?

附言我知道我可以 @include http://first-domain.com/*然后使用 if在该域内的某些路径上运行脚本的某些部分的语句,但是脚本打算运行的页面数量只有站点的 2% 左右,因此将脚本包含在每个页面的每个页面上似乎很浪费网站。

最佳答案

引用:

  • Greasemonkey Include and exclude rules
  • Match Patterns
  • Match patterns and globs

  • 适用于 Greasemonkey(即 Firefox)的解决方案在 Chrome 和 Tampermonkey 上可能有所不同。
    三种基本方法:
  • 使用 30 种不同的 @include线路 :虽然这在剪切和粘贴编码方面可能令人不快,但它是一种跨浏览器工作相同且浏览器性能最佳的方法。其他方法要求浏览器对访问的每个页面或 iframe 进行(更多)检查。
  • 使用正则表达式 @include :
    @include /^http:\/\/(1stDomain\.com|2ndDomain\.com|3rdDomain\.net|etc.)\/(admin\/edit|blog|user\/.+?\/history)/

  • 这是一条线,性能相当好,但这条线可能会变得笨重,这将 仅适用于 Greasemonkey 和 Tampermonkey (并且可能是脚本式的)。
  • 使用 @match 的各种组合, @include@exclude : 我只提到这种可能性。这是直接 Chrome 上性能最好的方法,但对于这种事情不是很跨浏览器。对于 Greasemonkey 或 Tampermonkey,请使用方法 1 或方法 2。

  • 我建议您尽可能避免使用前导通配符。它们最能降低浏览器的速度。 EG,不要使用类似 @include /^.+ .../ 的东西, 或 @include http:/*/*如果你能避免它。

    关于greasemonkey - 包括跨多个域的 Greasemonkey 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17168395/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com