油猴脚本集合

Greasy Fork

Greasy Fork脚本集合 慕课网-找回路径课程:https://greasyfork.org/zh-CN/scripts/28115 慕课网-下载视频(失效):https://greasyfork.org/zh-CN/scripts/28327 获取行政区划代码: https://greasyfork.org/zh-CN/scripts/31888 Pixiv-增强: https://greasyfork.org/zh-CN/scripts/34153 Greasy Fork 替换原图: https://greasyfork.org/zh-CN/scripts/35062 Google翻译 替换: https://greasyfork.org/zh-CN/scripts/35072 Fuck天猫: https://greasyfork.org/zh-CN/scripts/369391 问卷星 自动随机填写: https://greasyfork.org/zh-CN/scripts/369392 坑 1、函数在页面中点击执行

在脚本中定义函数function abc(){ alert("helloWorld"); },注入onclick事件<a id="a" onclick="abc();">HelloWorld</a>。 爆出函数未定义的错误Function is not defined。 在mozillazine了解到Tampermonkey的js脚本是在sandbox中的,在html中访问不到。 使用下面的例子可以完成这个功能

unsafeWindow.abc = function(msg) { alert(msg); }; document.getElementById("a").onclick = "window.abc('helloWorld')"; 2、跨域访问

http://m.imooc.com/video/14388中底部写死了mp4url,判断依据是禁用js仍然在html源代码中发现了这个url。 课程所在位置是http://www.imooc.com/learn/814。属于跨域访问的问题,使用GM_xmlhttpRequest可以解决。

3、模拟事件

来自stackoverflow,原生js实现的模拟点击事件. trigger对非JQuery绑定的事件无效。

$('#downTip').click(function(){ //$('#js-signin-btn').trigger('click'); var clickEvent = document.createEvent ('MouseEvents'); clickEvent.initEvent ('click', true, true); document.getElementById('js-signin-btn').dispatchEvent (clickEvent); }); 4、拦截Ajax请求的url路径

(function (open) { XMLHttpRequest.prototype.open = function () { this.addEventListener("readystatechange", function () { if (this.responseURL.indexOf('.hxk') >= 0) { console.log(this.responseURL); } }, false); open.apply(this, arguments); }; })(XMLHttpRequest.prototype.open); 5、Ajax跨域请求多图并压缩为Zip

依赖JSZip、FileSaver, 具体实现参考Pixiv-增强

var zip = new JSZip(); for (var i = 0; i < 16; i++) { (function (index) { var url = 'https://i.pximg.net/img-master/img' + param + '_p' + index + '_master1200.jpg'; GM_xmlhttpRequest({ method: 'GET', headers: {referer: 'https://www.pixiv.net/'}, // pixiv加了防盗链referer overrideMimeType: 'text/plain; charset=x-user-defined', url: url, onload: function (xhr) { var r = xhr.responseText, data = new Uint8Array(r.length), i = 0; while (i < r.length) { data[i] = r.charCodeAt(i); i++; } var blob = new Blob([data], {type: 'image/jpeg'}); // 转为Blob类型 zip.file('pic_' + index + '.jpg', blob, {binary: true}); // 压入zip中 } }); })(i); } // 注意GM_xmlhttpRequest的ajax请求不是同步的 $('按钮').click(function(){ zip.generateAsync({type: "blob", base64: true}).then(function (content) { // see FileSaver.js' saveAs(content, "pic.zip"); }); });

版权声明:

1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。
2、网站不提供资料下载,如需下载请到原作者页面进行下载。