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:
parent
5ba2dce127
commit
35d8f25fd4
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
2
src/plugins/GreaseMonkey/data/values.min.js
vendored
2
src/plugins/GreaseMonkey/data/values.min.js
vendored
|
@ -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)})})};
|
||||
|
|
Loading…
Reference in New Issue
Block a user