- 慕课网-找回路径课程:https://greasyfork.org/zh-CN/scripts/28115
- 慕课网-下载视频:https://greasyfork.org/zh-CN/scripts/28327
在脚本中定义函数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')";
在http://m.imooc.com/video/14388
中底部写死了mp4
的url
,判断依据是禁用js
仍然在html
源代码中发现了这个url
。
课程所在位置是http://www.imooc.com/learn/814
。属于跨域访问的问题,使用GM_xmlhttpRequest可以解决。
来自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);
});