Subscribed unsubscribe Subscribe Subscribe

枕を欹てて聴く

香炉峰の雪は簾を撥げて看る

GM_listValues, GM_deleteValue, @unwrap

Greasemonkey 0.8.20090123.l

# Added translations: ar-SA, bn-IN, hu-HU, id-ID, ro-RO, sr-RS, vi-VN.
# Fix for ticket #111 (anomalous separators in the monkey menu).
# Add GM_deleteValue() and GM_listValues() APIs (#38).
# Restore the anonymous function wrapper around scripts, and thus the same behavior as versions prior to 0.8 (by default, removable with the @unwrap metadata imperative, #108).
# Improved interaction with the Firebug console (#122, #204).

http://www.greasespot.net/2009/01/greasemonkey-release-08200901231.html

GM_listValues

GM_listValues - GreaseSpot Wiki
test code

GM_setValue('mariya', 'man');
GM_setValue('kanako', 'woman');
GM_setValue('nyankosensei', 'cat');
var arry = GM_listValues();
console.log(arry);                 // => ['mariya', 'kanako', 'nyankosensei']
console.log(arry.map(GM_getValue)) // => ['man', 'woman', 'cat']

code at

var pref = Components.classes["@mozilla.org/preferences-service;1"]
                     .getService(Components.interfaces.nsIPrefService)
                     .getBranch(startPoint);
/*
 * ......
 */
this.listValues = function() {
  return pref.getChildList("", {});
}

XulPlanet

GM_deleteValue

GM_deleteValue - GreaseSpot Wiki
test code

GM_setValue('mariya', 'man');
GM_setValue('kanako', 'woman');
GM_deleteValue('mariya');
console.log(GM_getValue('mariya')); // => undefined
console.log(GM_getValue('kanako')); // => woman

code at

GM_ScriptStorage.prototype.deleteValue = function(name) {
  return this.prefMan.remove(name);
}

code at

var pref = Components.classes["@mozilla.org/preferences-service;1"]
                     .getService(Components.interfaces.nsIPrefService)
                     .getBranch(startPoint);
/*
 * ......
 */
  this.remove = function(prefName) {
 	   pref.deleteBranch(prefName);
  };

XulPlanet

あと, unsafeWindow.consoleする必要がなくなったのと, "(function(){"+ scriptSrc +"})()"; のやつが By default (原文まま)でつくようになった.

metadata @unwrap指定で, はずせる.

けど, もしもはずしたときにreturn関連のエラーが出たら, wrapされて再実行される. => 二度手間

test code

// ==UserScript==
// @name           test unwrap1
// @include        *
// @unwrap
// ==/UserScript==
(function(){
  console.log(arguments.callee.caller);// => null
})();

or

// ==UserScript==
// @name           test unwrap2
// @include        *
// ==/UserScript==
(function(){
  console.log(arguments.callee.caller);// => UserScript Source
})();