开发者

How would I make this bookmarklet run on an interval?

开发者 https://www.devze.com 2023-03-05 11:04 出处:网络
I have a great bookmarklet that reloads the css for the projects I\'m working on. Right now I need to click the bookmark every time I want it to reload. What I want it to do is just set an interval.

I have a great bookmarklet that reloads the css for the projects I'm working on. Right now I need to click the bookmark every time I want it to reload. What I want it to do is just set an interval.

This is it:

javascript:void(function(){var i,a,s;a=document.g开发者_StackOverflowetElementsByTagName('link');for(i=0;i<a.length;i++){s=a[i];if(s.rel.toLowerCase().indexOf('stylesheet')>=0&&s.href) {var h=s.href.replace(/(&|%5C?)forceReload=\d+/,'');s.href=h+(h.indexOf('?')>=0?'&':'?')+'forceReload='+(new Date().valueOf())}}})();

This is what I tried:

javascript:void(

setInterval(
    function(){
        var i,a,s;
        a=document.getElementsByTagName('link');
        for(i=0;i<a.length;i++){
            s=a[i];
            if(s.rel.toLowerCase().indexOf('stylesheet')>=0&&s.href) {
                var h=s.href.replace(/(&|%5C?)forceReload=\d+/,'');
                s.href=h+(h.indexOf('?')>=0?'&':'?')+'forceReload='+(new Date().valueOf())
            }
        }
    }, 500 
);

)();

Any ideas? I've never worked with bookmarklets.

Thanks!


I'd try to name the function then pass it to setInterval:

javascript: myfun = function() {...}; setInterval(myfun, 500);
0

精彩评论

暂无评论...
验证码 换一张
取 消