1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

GreaseMonkey: Return undefined when value was not found in GM_getValue

This commit is contained in:
David Rosca 2018-06-01 12:57:44 +02:00
parent 5ba2dce127
commit 35d8f25fd4
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
2 changed files with 2 additions and 2 deletions

View File

@ -8,7 +8,7 @@ function GM_deleteValue(aKey) {
function GM_getValue(aKey, aDefault) {
var val = localStorage.getItem("%1" + aKey)
if (null === val && 'undefined' != typeof aDefault) return aDefault;
if (null === val) return aDefault;
return val;
}

View File

@ -1,4 +1,4 @@
function GM_deleteValue(a){localStorage.removeItem("%1"+a)}function GM_getValue(a,b){var c=localStorage.getItem("%1"+a);return null===c&&"undefined"!=typeof b?b:c}function GM_listValues(){for(var a=[],b=0;b<localStorage.length;b++){var c=localStorage.key(b);0===c.indexOf("%1")&&a.push(c.replace("%1",""))}return a}function GM_setValue(a,b){localStorage.setItem("%1"+a,b)}
function GM_deleteValue(a){localStorage.removeItem("%1"+a)}function GM_getValue(a,b){var c=localStorage.getItem("%1"+a);return null===c?b:c}function GM_listValues(){for(var a=[],b=0;b<localStorage.length;b++){var c=localStorage.key(b);0===c.indexOf("%1")&&a.push(c.replace("%1",""))}return a}function GM_setValue(a,b){localStorage.setItem("%1"+a,b)}
var asyncCall=function(a){window._falkon_external?a():document.addEventListener("_falkon_external_created",a)},decode=function(a){a=String(a);if(!a.length)return a;var b=a.substr(1);if("b"==a[0])return"true"==b?!0:!1;if("i"==a[0])return Number(b);if("s"==a[0])return b},encode=function(a){return"boolean"==typeof a?"b"+(a?"true":"false"):"number"==typeof a?"i"+String(a):"string"==typeof a?"s"+a:""};
GM.deleteValue=function(a){return new Promise(function(b,c){asyncCall(function(){external.extra.greasemonkey.deleteValue("%1",a,function(a){a?b():c()})})})};GM.getValue=function(a,b){return new Promise(function(c){asyncCall(function(){external.extra.greasemonkey.getValue("%1",a,encode(b),function(a){c(decode(a))})})})};GM.setValue=function(a,b){return new Promise(function(c,d){asyncCall(function(){external.extra.greasemonkey.setValue("%1",a,encode(b),function(a){a?c():d()})})})};
GM.listValues=function(){return new Promise(function(a){asyncCall(function(){external.extra.greasemonkey.listValues("%1",a)})})};