简体   繁体   English

Tampermonkey脚本来编辑源代码中的链接

[英]Tampermonkey script to edit links in source

I've recently started working at a company as a student where the workload is minimal. 我最近开始在一家学生公司工作,工作量很少。 Many of the jobs they do manually, I can solve with a simple script, thus giving me loads of free time. 他们可以手动完成许多工作,我可以用一个简单的脚本来解决,因此给了我大量的空闲时间。

The downside to this is my account does not have internet access outside the website relevant to my workplace. 不利的一面是我的帐户在与我的工作场所相关的网站之外无法访问互联网。 I've been sniffing around and notice their redirect proxy server has a really amateurish system to block websites, it basically scans the web address and looks for certain keywords. 我一直在嗅探,发现他们的重定向代理服务器有一个非常业余的系统来阻止网站,它基本上会扫描网址并查找某些关键字。 By simply adding ?google to a web address, I can access it without issue. 只需将?google添加到网址中,我就可以毫无问题地访问它。

But, every single link has to be edited with "?google" at the end, which is not really efficient. 但是,每个链接的末尾都必须使用“?google”进行编辑,这并不是很有效。 So I'm looking to write a script that looks up links (CSS/JS/Pictures/etc..) and automatically adds ?google at the end. 因此,我希望编写一个脚本来查找链接(CSS / JS / Pictures /等),并在末尾自动添加?google

For example: 例如:

https://cdn.sstatic.net/stackoverflow/all.css?v=4a57bb936dd5

would become: 会成为:

https://cdn.sstatic.net/stackoverflow/all.css?v=4a57bb936dd5?google

Since I haven't worked yet with Tampermonkey yet I wonder if anyone knows a simple and efficient way to do this? 由于我尚未与Tampermonkey合作,我想知道是否有人知道一种简单有效的方法?

Well after fiddling a bit I managed to write a script, here's the code if anyone's interested. 好了一段时间之后,我设法编写了一个脚本,如果有人感兴趣,这里是代码。

// ==UserScript==
// @name          Google Add
// @namespace     
// @description   
// @include       *
// ==/UserScript==

var srcs = document.links;
var links = document.getElementsByTagName("link");
var scripts = document.getElementsByTagName("script");
var imgs = document.getElementsByTagName("img");
var iframes = document.getElementsByTagName("iframe");


for (i = 0; i < links.length; i++ ) {
    links[i].href = links[i].href+'?google';        
}

for (i = 0; i < scripts.length; i++ ) {
    scripts[i].src = scripts[i].src+'?google'; 
}

for (i = 0; i < imgs.length; i++ ) {
    imgs[i].src = imgs[i].src+'?google'; 
}

for (i=0; i<srcs.length; i++)
{
    srcs[i].href = srcs[i].href+'?google';
}

for (i=0; i<iframes.length; i++){

    iframes[i].src = iframes[i].src+'?google'; 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM