An API for listening to GM value changes is useful for implement a polyfill for old sync GM_getValue, GM_setValue, ect. And TM already provided a similar one. If such API may be added, then it is possible to create GM_*value polyfills. Thats seems the fastest (maybe only possible) way to port some large userscripts written for old APIs work.
Something polyfill like this: (not tested)
if (!GM_getValue) {
GM.listValues().then(function (keys) {
var values = new Map();
Promise.all(keys.map(function () {
return GM.getValue(key).then(function (value) {
if (value !== void 0) values.set(key, value);
GM.onValueChange(key, function (newValue) {
values.set(key, newValue);
});
});
})).then(function () {
doTheMainStuff();
});
GM_getValue = function (key, defaultValue) {
if (values.has(key)) return values.get(key);
return defaultValue;
};
GM_setValue = function (key, value) {
values.set(key, value);
return GM.setValue(key, value);
};
GM_deleteValue = function (key) {
values.delete(key);
return GM.deleteValue;
};
});
}
An API for listening to GM value changes is useful for implement a polyfill for old sync
GM_getValue
,GM_setValue
, ect. And TM already provided a similar one. If such API may be added, then it is possible to createGM_*value
polyfills. Thats seems the fastest (maybe only possible) way to port some large userscripts written for old APIs work.Something polyfill like this: (not tested)