举例:
通过油猴下载 https://www.cocoacontrols.com/
的 GitHub
代码
// ==UserScript==
// @name cocoacontrols.com下载代码
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author CoderWGB
// @match https://www.cocoacontrols.com/*
// @match https://www.cocoacontrols.com
// @icon https://www.google.com/s2/favicons?sz=64&domain=cocoacontrols.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
//获取所有的a标签
var listNodes = document.querySelectorAll('a');
// 遍历修改使用镜像下载
listNodes.forEach((item)=>{
//此时a标签的链接地址形如 xcode://clone?repo=http://github.com/abc/xxx
// 通过截取'='拿github地址 进行镜像拼接成新地址进行替换即可 之后再点击那个按钮则会走油猴的逻辑
if(item.href.indexOf('xcode://clone') != -1){
var urlArr = item.href.split('=');
var urlStr = `https://gh.api.99988866.xyz/${decodeURIComponent(urlArr[1])}/archive/refs/heads/master.zip`
item.href = urlStr;
}
});
})();
标签:www,github,cocoacontrols,替换,item,https,com,油猴
From: https://www.cnblogs.com/wgb1234/p/17486482.html