1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

GreaseMonkey: Fix GM_listValues() listing nothing

The function GM_listValues() got broken when the source file "values.js"
was minimized into "values.min.js" because the optimizing tool was not
aware that the string containing the placeholder (%1) is not final and
will be changed later. It optimized away the expression which gets the
length of the string and replaced it with its static value (2). This was
a problem because not the length of the placeholder (%1) but the length
of the current script id is needed to extract prefixes from the keys in
the local storage. Failing to correctly extract the prefixes prevented
finding the entries for the current script. This was fixed by comparing
prefixes without extracting new strings. It works around the need to get
the length of the id string and therefore the breaking optimization.

An unrelated and redundant variable declaration was also removed.
This commit is contained in:
Philipp Wiesemann 2015-10-23 22:45:21 +02:00
parent 88dba5e5ab
commit 0e47899791
2 changed files with 3 additions and 5 deletions

View File

@ -13,13 +13,11 @@ function GM_getValue(aKey, aDefault) {
}
function GM_listValues() {
var prefixLen = "%1".length;
var values = [];
var i = 0;
for (var i = 0; i < localStorage.length; i++) {
var k = localStorage.key(i);
if (k.substr(0, prefixLen) === "%1") {
values.push(k.substr(prefixLen));
if (k.indexOf("%1") === 0) {
values.push(k.replace("%1", ""));
}
}
return values;

View File

@ -1 +1 @@
function GM_deleteValue(b){localStorage.removeItem("%1"+b)}function GM_getValue(b,a){var c=localStorage.getItem("%1"+b);return null===c&&"undefined"!=typeof a?a:c}function GM_listValues(){for(var b=[],a=0,a=0;a<localStorage.length;a++){var c=localStorage.key(a);"%1"===c.substr(0,2)&&b.push(c.substr(2))}return b}function GM_setValue(b,a){localStorage.setItem("%1"+b,a)};
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)};