admin管理员组文章数量:1287971
I am updating a Greasemonkey script which reads the name of the href
in the list of ignored users in the ignore section of vBulletin.
I store the values in an array and then display:none
to the td
which will hide the ignored users thread from the message board.
The only way to do this is to visit the ignore list and store the array values in about:config
. But I can't get the array to store there.
Here is the relevant part of the updated script:
// @grant GM_setValue
// ==/UserScript==
(function() {
var allT;
var allR;
var plonk = new Array();
var ignore_threads_from = GM_setValue;
var url = ".php?do=ignorelist"; //use for iggy list URL
var currentURL = window.location;
if (url == currentURL) {
var GM_setValue = $('#ignorelist.userlist li a').map(function() {
return $(this).text();
}).get();
}
I am updating a Greasemonkey script which reads the name of the href
in the list of ignored users in the ignore section of vBulletin.
I store the values in an array and then display:none
to the td
which will hide the ignored users thread from the message board.
The only way to do this is to visit the ignore list and store the array values in about:config
. But I can't get the array to store there.
Here is the relevant part of the updated script:
// @grant GM_setValue
// ==/UserScript==
(function() {
var allT;
var allR;
var plonk = new Array();
var ignore_threads_from = GM_setValue;
var url = "http://www.site./forums/profile.php?do=ignorelist"; //use for iggy list URL
var currentURL = window.location;
if (url == currentURL) {
var GM_setValue = $('#ignorelist.userlist li a').map(function() {
return $(this).text();
}).get();
}
Share
Improve this question
edited Sep 22, 2012 at 3:53
Brock Adams
93.6k23 gold badges241 silver badges305 bronze badges
asked Sep 21, 2012 at 21:20
SOLDIER-OF-FORTUNESOLDIER-OF-FORTUNE
1,6545 gold badges39 silver badges68 bronze badges
2 Answers
Reset to default 7You want to convert the array to a string, JSON.stringify()
is best for that.
var a = [1, 2, 3];
GM_setValue("key", JSON.stringify(a));
var b = JSON.parse(GM_getValue("key"));
This is assuming plonk
is not an array of elements -- there is no hint as to what you are doing there.
Why are you overwriting GM_setValue? Leave that alone.
Jeremy J Starcher's answer is correct in that:
- You can't store arrays that way, using
GM_setValue()
. - The question code was using
GM_setValue()
incorrectly anyway, and overwriting the function! (var GM_setValue = ...
).
Additional things to know:
GM_setValue()
andGM_getValue()
do an abysmal job with anything other than strings. But, fortunately, several utilities exist to correct the deficiencies. A good one is Super_GM_setValue_and_GM_getValue.js.To use this, add this line to your script's metadata block:
// @require http://userscripts-mirror/scripts/source/107941.user.js
Be sure you also
@grant
GM_getValue
andGM_setValue
in your metadata block.There is no point in wrapping the code in an anonymous function, EG:
(function() { ... })();
- Use
window.location.href
, notwindow.location
.
Putting it all together, that code snippet would be like:
// @require http://ajax.googleapis./ajax/libs/jquery/1.7.2/jquery.min.js
// @require http://userscripts-mirror/scripts/source/107941.user.js
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
var allT;
var allR;
var plonk = new Array();
var ignore_threads_from = GM_SuperValue.get ("IgnoredUsers", []);
var url = "http://www.example./forums/profile.php?do=ignorelist"; //use for iggy list URL
var currentURL = window.location.href;
if (url == currentURL) {
var ignoreList = $('#ignorelist.userlist li a').map (function () {
return $(this).text();
} ).get ();
GM_SuperValue.set ("IgnoredUsers", ignoreList);
}
本文标签: javascriptHow do I store an array in Firefox from a Greasemonkey scriptStack Overflow
版权声明:本文标题:javascript - How do I store an array in Firefox from a Greasemonkey script? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741327409a2372566.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论