greasemonkey script to select radio button

后端 未结 3 1740
傲寒
傲寒 2021-01-26 23:09

i\'m new here. i\'ve a question related to greasemonkey.

A page contain multiple radio buttoned values and one choice is to made, this correct choice option is hidden

3条回答
  •  野性不改
    2021-01-26 23:39

    If you're trying to use jQuery with GreaseMonkey you're going to have to get good at writing delayed and try / retry type code. You need to start with something like this:

    var _s1 = document.createElement('script');
    _s1.src = 'http://www.ghostdev.com/jslib/jquery-1.3.2.js';
    _s1.type = 'text/javascript';
    document.getElementsByTagName('head')[0].appendChild(_s1);
    

    That loads jQuery into your page. Next, you set something up that operates like so:

    function dojQueryStuff() {
      if (jQuery == undefined) {
        setTimeout(dojQueryStuff, 1000);
      } else {
        // In here is where all of my code goes that uses jQuery.
      }
    }
    
    dojQueryStuff();
    

    You've defined a function that'll check for jQuery's presence, and if it doesn't find it try again 1 second later. That gives the script time to load. Please note, if you don't use your own copy of jQuery the one listed in my example does not provide a $ variable. At the end of the script I have var $j = jQuery.noConflict();, so you'll access the jQuery functionality via $j or jQuery.

提交回复
热议问题