让油猴脚本只执行一次
脚本循环执行的是 (function(){})(); 中 {} 里的内容,所以在这个函数外定义一个计数变量,函数执行时修改这个计数变量即可。
代码如下:
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match *://*/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
var i=1;
(function() {
'use strict';
if(i==1){
//your code here
i++;
}
})();