Giter Site home page Giter Site logo

tampermonkey's Introduction

Tampermonkey油猴脚本集合

脚本集合

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);
});

tampermonkey's People

Contributors

ahaochan avatar

Watchers

James Cloos avatar OMG avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.