我无法在网络上找到任何GM _ addValueChangeListener
示例。我想为Chrome(Tampermonkey)添加一个简单的监听器,以查看是否已设置GM值。如果不是chrome我改为设置间隔。
if (!!window.chrome && window.navigator.vendor === "Google Inc."){
console.log("GM_addValueChangeListener supported.");
GM_addValueChangeListener(name, update);
function update(name, old_value, new_value, from_remote) {
console.log(arguments);
if( getStorage() ) { //gets GM stored data
//update fields
removeStorage(); //removes GM stored data
} else alert("No data exported.");
}
} else {
console.log("not chrome, using setInterval");
setInterval(function(){
if( getStorage() ) { //gets GM stored data
//update fields
removeStorage(); //removes GM stored data
} else console.log("no data yet...")
}, 2000);
}
答案 0 :(得分:1)
// ==UserScript==
// @name Test GM_addValueChangeListener
// @grant GM_addValueChangeListener
// @grant GM_setValue
// ==/UserScript==
GM_addValueChangeListener("abc", function() { console.log(arguments) });
GM_setValue("abc",123);