🏠 Home 

讨论 » 开发

Firefox "blocks" this GM script and doesn't even appear in the debugger

§
发表于:2022-08-22
编辑于:2022-08-22

This code, for some reason causes firefox to not even reconize this script (does not execute it, nor will it show up on debugger sources), can anyone tell me why?

// ==UserScript==
// @name     Unnamed Script 692044
// @version  1
// @grant    GM.setValue
// @grant    GM.getValue
// @include      *
// ==/UserScript==
'use strict';
(function() {
const ListOfURLs = `
https://google.com
https://wikipedia.org
`
window.addEventListener('load', LoadURLAfterTimer)
function LoadURLAfterTimer() {
console.log("test")
setTimeout(LoadAnotherPage, 5000)
}
function LoadAnotherPage() {
let URL_index = await GM.getValue("URLIndex", -1);
URL_index++
await GM.setValue("URLIndex", URL_index);
location.href = ListOfURLs.match(/http(s)?\:\/\/(?!data:)[^\s\"\']+/g)[URL_index] //Code stops executing after this executes.
}
})();

I'm trying to write a code that causes the browser to go from one URL to another URL after a delay, without opening any additional tabs.

§
发表于:2022-08-23
编辑于:2022-08-23

At least one reason - the use of 'await' - does this help? :: https://stackoverflow.com/questions/53939882/why-isnt-await-working-with-async-on-firefox

§
发表于:2022-08-23

At least one reason - the use of 'await' - does this help? :: https://stackoverflow.com/questions/53939882/why-isnt-await-working-with-async-on-firefox

Well, another problem: NaN. Updated code.

// ==UserScript==
// @name     Unnamed Script 692044
// @version  1
// @grant    GM.setValue
// @grant    GM.getValue
// @include      *
// ==/UserScript==
'use strict';
(function() {
const ListOfURLs = `
https://google.com
https://wikipedia.org
`
window.addEventListener('load', LoadURLAfterTimer)
function LoadURLAfterTimer() {
console.log("test")
setTimeout(LoadAnotherPage, 5000)
}
function LoadAnotherPage() {
let URL_index = GM.getValue("URLIndex", -1).then();
URL_index++
GM.setValue("URLIndex", URL_index).then();
location.href = ListOfURLs.match(/http(s)?\:\/\/(?!data:)[^\s\"\']+/g)[URL_index] //Code stops executing after this executes.
}
})();

for some reason, URL_index is supposed to be set to -1 by default if there is no value for it: https://wiki.greasespot.net/GM.getValue

发表回复

登录以发表回复。