How to run a selector on a dynamically generated page?

后端 未结 2 440
既然无缘
既然无缘 2021-01-26 00:51

I have a selector which works in GM_addStyle but not in jQuery. I want to use jQuery :contains() which is not available in CSS3.

But, it appear

2条回答
  •  我在风中等你
    2021-01-26 01:31

    Waiting for the element:

    function waitForElement(id, callback, timeout){
        if('undefined' == typeof timeout) timeout = 30;
        timeout = timeout * 1000;
        var time = 0;
        var poops = setInterval(function(){
            if(time >= timeout) clearInterval(poops);
            if(document.getElementById(id)){
                clearInterval(poops);
                callback();
            }
            time += 100;
        }, 100);
    }
    

    One way to include jQuery:

    (function(callback) {
      var script = document.createElement("script");
      script.setAttribute("src", "//code.jquery.com/jquery-1.11.3.min.js");
      script.addEventListener('load', callback);
      document.body.appendChild(script);
    })
    
    // main codez go in here
    (function(){
      window.alert($('a').length+" Links");
    });
    

提交回复
热议问题