From 0e47899791c580564e90a195135b721d875106ba Mon Sep 17 00:00:00 2001 From: Philipp Wiesemann Date: Fri, 23 Oct 2015 22:45:21 +0200 Subject: [PATCH] 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. --- src/plugins/GreaseMonkey/data/values.js | 6 ++---- src/plugins/GreaseMonkey/data/values.min.js | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/plugins/GreaseMonkey/data/values.js b/src/plugins/GreaseMonkey/data/values.js index 637c288dd..e7e6d70b2 100644 --- a/src/plugins/GreaseMonkey/data/values.js +++ b/src/plugins/GreaseMonkey/data/values.js @@ -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; diff --git a/src/plugins/GreaseMonkey/data/values.min.js b/src/plugins/GreaseMonkey/data/values.min.js index d10c11965..2ebaffbcd 100644 --- a/src/plugins/GreaseMonkey/data/values.min.js +++ b/src/plugins/GreaseMonkey/data/values.min.js @@ -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