【问题标题】:Greasemonkey script to change all links that match to a different domainGreasemonkey 脚本更改与不同域匹配的所有链接
【发布时间】:2017-07-13 12:41:40
【问题描述】:

我需要一个greasemonkey 脚本,它将所有youtube.com 和youtu.be 实例替换为hooktube.com 并保持watch?v=vidID 完好无损。我已经尝试修改 stackoverflow 上的其他示例,但它们比我需要的更复杂,而且我对 javascript 几乎一无所知。我一直在尝试修改这个:Script to modify a URL in greasemonkey 但我无法让它做任何事情,我不知道如何调试它。

【问题讨论】:

  • 我实际上有一些几乎可以工作的东西。当我修复它时会更新。

标签: javascript youtube greasemonkey


【解决方案1】:

这似乎可以解决问题。希望它可以帮助将来的人......

var links,thisLink;
links = document.evaluate("//a[@href]",
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null);

for (var i=0;i<links.snapshotLength;i++) {
    var thisLink = links.snapshotItem(i);

  thisLink.href = thisLink.href.replace(RegExp('https?://www\\.youtube\\.com/(.*)'),
                                      'https://www\.hooktube\.com/$1');

  thisLink.href = thisLink.href.replace(RegExp('https?://youtu\\.be/(.*)'),
                                      'https://www\.hooktube\.com/watch\?v=$1');
}

感谢Script to modify a URL in greasemonkey

【讨论】:

  • 如何把这个放到 Greasemonkey 中?
猜你喜欢
  • 2013-09-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-29
  • 1970-01-01
  • 2019-04-29
  • 1970-01-01
  • 2014-09-26
相关资源
最近更新 更多