gm-xmlhttprequest

Promise not returning value of request

狂风中的少年 提交于 2019-12-02 07:13:11
I have this promise: function getAPI(token) { return new Promise((resolve, reject) => { console.log("Request API"); GM_xmlhttpRequest({ method: "GET", url: "URL"+token, onload: function(response) { console.log(response.responseText); if( response.responseText == "NOT_ANSWER" || response.responseText.indexOf("ERRO") > -1 ){ console.log(response.responseText + " - Calling Myself in 5 Seconds"); setTimeout(function(){ getAPI(token); },5000); } else{ console.log('Call API - Giving Result'); resolve(response.responseText.split("_")[1]); } } }); }); } I call it inside of itself when the answer is

Looping GM_xmlhttpRequest gives “TypeError Null” on a variable

和自甴很熟 提交于 2019-12-02 04:16:45
I have some links in a page. I want to count the responses of each link and insert the numbers in front of the links. Here is what I have: var links = document.evaluate('..../td[1]/font//a[@href]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); var headings = document.evaluate('.../td[1]',document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null) for(var i = 0; i < links.snapshotLength; i++){ var urls = links.snapshotItem(i).href; GM_xmlhttpRequest({ method: 'GET', url: urls, onload function (res){ var dt = document.implementation.createDocumentType("html", "-//W3C//DTD HTML

Synchronous GM_xmlhttpRequest acting asynchronously?

牧云@^-^@ 提交于 2019-11-28 02:16:43
I'm trying to get a GM_xmlhttpRequest call to behave synchronously, but I can't get it to work like I expect: function myFunction (arg) { var a; GM_xmlhttpRequest ( { method: "GET", url: "http://example.com/sample/url", synchronous: true, onload: function (details) { a = details.responseText; } } ); return a; } b = myFunction (); alert (b); I never get anything back for b here; it's undefined. Is there some step that I'm missing here? I'm using v0.9.13 of Greasemonkey, and v9.0.1 of Firefox. Just stumbled upon this topic in Google. Synchronous GM_xmlhttpRequest RETURN the result instead of

“getElementById not a function” when trying to parse an AJAX response?

笑着哭i 提交于 2019-11-27 02:13:15
I'm running GM_xmlhttpRequest (in a Greasemonkey script) and storing the responseText into a newly created HTML element: var responseHTML = document.createElement('HTML'); ... onload: function() { responseHTML.innerHTML = response.responseText; } And then I am trying to find an element in responseHTML : console.log(responseHTML.getElementsByTagName('div')); console.log(responseHTML.getElementById('result_0')); The first works fine, but not the second. Any ideas? getElementById is not a method of HTML elements. It is a method of the document node. As such you can't do: div.getElementById('foo')

Synchronous GM_xmlhttpRequest acting asynchronously?

为君一笑 提交于 2019-11-26 23:39:34
问题 I'm trying to get a GM_xmlhttpRequest call to behave synchronously, but I can't get it to work like I expect: function myFunction (arg) { var a; GM_xmlhttpRequest ( { method: "GET", url: "http://example.com/sample/url", synchronous: true, onload: function (details) { a = details.responseText; } } ); return a; } b = myFunction (); alert (b); I never get anything back for b here; it's undefined. Is there some step that I'm missing here? I'm using v0.9.13 of Greasemonkey, and v9.0.1 of Firefox.