gm_getvalue/setvalue is not defined?
- You're granting
GM.getValue
but you're trying to useGM_getValue
- see the difference? - JavaScript is case-sensitive so you can't use
gm_setvalue
orgm_getvalue
- it should beGM_setValue
andGM_getValue
- You have a typo:
GM_etValue
If your script manager is Tampermonkey, simply replace .
with _
in both declarations.
If your script manager is Greasemonkey 4, you'll need to rework the code a bit as shown in the documentation.
@wOxxOm 说道:
- You're granting
GM.getValue
but you're trying to useGM_getValue
- see the difference?- JavaScript is case-sensitive so you can't use
gm_setvalue
orgm_getvalue
- it should beGM_setValue
andGM_getValue
- You have a typo:
GM_etValue
If your script manager is Tampermonkey, simply replace
.
with_
in both declarations.If your script manager is Greasemonkey 4, you'll need to rework the code a bit as shown in the documentation.
OMG, today I learned so much and assembled many versions, just did not realize these. Thanks so much for your help!
......
@wOxxOm Learned a lot from this case. Till now the only explanation I could think of is, allow me to make it clear: I thought it's a 2 urls case, but it's about 3 urls --- when link clicked, page url turns into that link's url, then jump to 3rd url - captured by a downloader with help of a chrome extension thus the url is like "chrome-extension://xxxxx", then jump back to link's url ( I was thinking it will jump back to the very first url, but lots of tests showed no matter what conditions I added( such of cookie or GM Value) to prevent infinite downloading, it will jump to 3rd url again and again, so a 2nd url must be the culprit, 'coz my condition is on 1st url).
Here is a working solution. Any improvement please let me know. [code]// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js // @require https://gist.github.com/raw/2625891/waitForKeyElements.js // @run-at document-end // ==/UserScript== //- The @grant directives are needed to restore the proper sandbox. /* global $, waitForKeyElements */ var flag = null; setTimeout(main, 1000);
function main() { // wait for link appears waitForKeyElements("#download-url", clickNode, true); }
function clickNode(jNode) { // wait for link unhide flag = setInterval(opt, 500); }
function opt() { var yc = $("#download-url").is(":hidden") ? "not there" : "appear"; console.log(yc); if (yc == "appear") { clearInterval(flag); var url = document.getElementById("download-url").href; // here for download I open new window/tab openWin(url); } }
function openWin(url) { $('body').append($('')) document.getElementById("openWin").click(); $('#openWin').remove(); }[/code]
ooops, the last function should be:
gm_getvalue/setvalue is not defined?
The above script is simply waiting for a link show up and click it. The problem is after clicking, my download tool will make url redirect and download begins and redirect back, make this script triggered again and click again, thus an infinite loop. My first attempt is to use cookies, I append part of url to the cookie, and this script will stop clicking link if that part is already in cookie. This method I did well in another script, but I failed this one, don't know why yet. Now I try 2nd method: gm_setvalue/getvalue method, as shown in the code, but I get "undefined" error for them both. I've googled and tried wrapping it like:
Still get "undefined". I also tried 3rd method: window.postmessage and addeventlistener, but too complicated for me, failed. Don't know what to do now, could anybody please give me some help?