Greasy Fork is available in English.

Discussions » Development

Can't return dictionary/json key value data on tampermonkey storage

§
Posted: 22.07.2021
Edited: 22.07.2021

Nothing I've tried returns the name,FavIcon neither the searchUrl.
Is this possible to be done?

// ==UserScript==
// @name ..
// @namespace ...
// @version 0.1
// @description ...
// @author hacker09
// @include *
// @run-at document-end
// @grant GM_deleteValue
// @grant GM_listValues
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==

GM_setValue("animeflv",{
"name": "animeflv",
"FavIcon": "https://www.google.com/s2/favicons?domain=animeflv.net",
"searchUrl": "https://animeflv.net/browse?q="
})

GM_setValue("Crunchyroll", {
"name": "Crunchyroll",
"FavIcon": "https://www.google.com/s2/favicons?domain=www.crunchyroll.com",
"searchUrl": "http://www.crunchyroll.com/search?q="
})

GM_listValues().forEach(function(pageSearch){

//for (var key in pageSearch) {
//var page = pageSearch[key];
alert(GM_listValues()[0].searchUrl)
//}

});

§
Posted: 24.07.2021
GM_setValue("animeflv",{
  "name": "animeflv",
  "FavIcon": "https://www.google.com/s2/favicons?domain=animeflv.net",
  "searchUrl": "https://animeflv.net/browse?q="
})

GM_setValue("Crunchyroll", {
  "name": "Crunchyroll",
  "FavIcon": "https://www.google.com/s2/favicons?domain=www.crunchyroll.com",
  "searchUrl": "http://www.crunchyroll.com/search?q="
})

const output = {};

for (const key of GM_listValues()) {
  output[key] = GM_getValue(key);
}

alert(JSON.stringify(output, null, 2));
§
Posted: 24.07.2021
Edited: 24.07.2021

@Konf

Thank you!

Interesting... When I tried that it didn't work. Anyways, do you think the best way to loop that would be like this? (after the for loop)

Object.entries(output).forEach(value => {

alert(value[1].FavIcon);

});

§
Posted: 24.07.2021
Edited: 24.07.2021

@hacker09

Doesn't matter much

§
Posted: 24.07.2021

Thanks

Post reply

Sign in to post a reply.