下面是附加元件 Noise 的使用例。套用 ACQUIRE 遊戲的音效,算是湊個 theme 吧。
※播放中覺得吵是正常的,因為真的有點吵……
這份設定檔也放在 noise_theme_acquire_rdf.7z (DivShare)——僅 RDF,不分享聲音檔。
封存
下面是附加元件 Noise 的使用例。套用 ACQUIRE 遊戲的音效,算是湊個 theme 吧。
※播放中覺得吵是正常的,因為真的有點吵……
這份設定檔也放在 noise_theme_acquire_rdf.7z (DivShare)——僅 RDF,不分享聲音檔。
功能類似 Extension List Dumper 和 ListZilla 兩個套件,把附加元件清單匯出成檔案。
輸出格式可用樣板(是我參考 Ext JS 寫的陽春版)方式調整,但要改原始碼、比較麻煩就是了。
Bookmarklet 在這裡 → 匯出附加元件列表(僅支援 Firefox 3 系列)
為了調整輸出格式,需要修改原始碼;可自製幾支不同的樣板,存成不同的 bookmarklet 備用(不會壓製 bookmarklet 的話可參考前文)。原始碼附在文末,重要部分如下:
樣板由 template_prefix、template_item、template_suffix 組成,輸出時會把頭(_prefix)接上一連串的項目(_item)再接上尾(_suffix)。
樣板字串中 ${foo} 型式的元素,會被代換成實際值,例如 ${name} 會變成套件名稱。
※要注意的是 _prefix、_suffix 和 _item 能用的 ${foo} 不同。預設 _prefix、_suffix 專用的是 ${date} 和 ${total},其他則是 _item 專用。
清單資料會儲存在 data 陣列裡面,要過濾的話得在 data = data.filter(function(item, idx, arr){ 內處理。例如 return item['hidden']!='true'; 會把隱藏的項目拿掉。
樣板字串可以用 ${foo:helper} 這樣的元素來修改資料,例如 ${isDisabled:isTrue( 「已停用」,)} 會在套件停用時顯示「已停用」。
相應原始碼在 var helpers = { 裡面有幾個函數,傳回值就是要輸出的字串。
template_item 可用的函數,基本型為: 函數名稱 : function( item, value[, 參數1, 參數2, …] ){}
${foo:helper} 之中 foo 的實際值,例如 ${name:helper} 傳回的是套件名稱。 ${foo:helper(參數1,參數2)} 型式傳進來的。 var leqExtDumper = {
dump: function(){
if(typeof(gExtensionsView)=='undefined') return(alert('出了點狀況,無法繼續;\n\n請在 Firefox 3 的\nchrome://mozapps/content/extensions/extensions.xul\n執行這支 bookmarklet.'));
var txt = '';
var data = [];
// 樣板
var template_prefix = '附加元件列表 (${total}) - ${date}\n<ul>';
var template_item = '<li>\n'
+ '${homepageURL:addLink} - ${version} - <small>${optionsURL}</small>'
+ '${isDisabled:isTrue( (已停用),)} ${compatible:isFalse( (與應用程式不相容),)}'
+ '<br />\n'
+ '適用於: Firefox ${min} - ${max}\n'
+ '<p>${description}</p>\n'
+ '</li>\n';
var template_suffix = '</ul>';
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(Components.interfaces.nsIFilePicker);
var charset = "UTF-8";
var os = Components.classes["@mozilla.org/intl/converter-output-stream;1"].createInstance(Components.interfaces.nsIConverterOutputStream);
var fos = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
fp.init(window, null, fp.modeSave);
fp.defaultExtension='txt';
fp.defaultString='附加元件列表';
fp.appendFilters(fp.filterText | fp.filterHTML);
gExtensionsView.children.forEach(
function(i){
var item = gExtensionManager.getItemForID(getIDFromResourceURI(i.getAttribute('id')));
data.push({
name : i.getAttribute('name'), // 套件名稱
id : i.getAttribute('id'), // 套件 id
min : item ? item.minAppVersion : '', // 支援的最低 Firefox 版本
max : item ? item.maxAppVersion : '', // 支援的最高 Firefox 版本
iconURL : i.getAttribute('iconURL'), // 套件的圖示位址
version : i.getAttribute('version'), // 套件版本
description : i.getAttribute('description'), // 套件的敘述
homepageURL : i.getAttribute('homepageURL'), // 套件首頁
optionsURL : i.getAttribute('optionsURL'), // 套件的選項位址
hidden : i.getAttribute('hidden'), // 是否為隱藏套件
isDisabled : i.getAttribute('isDisabled'), // 是否已停用
compatible : i.getAttribute('compatible') // 是否與目前 Firefox 版本相容
});
}, this
);
// 過濾不要列出的項目 (return false 的資料會被排除)
data = data.filter(function(item, idx, arr){
return item['hidden']!='true';
});
var helpers = {
isTrue : function(item, value, strTrue, strFalse){
return value=='true' ? strTrue : strFalse;
},
isFalse : function(item, value, strTrue, strFalse){
return value=='false' ? strTrue : strFalse;
},
addLink : function(item, value){
return value=='' ? item['name'] : '<a href="' + value + '">' + item['name'] + '</a>';
},
// 以下僅適用於 template_prefix 與 template_suffix
date : function(){
return (new Date()).toLocaleString();
},
total : function(){
return data.length;
}
};
// template_prefix
// 取代 ${key} 形式的字串
txt = template_prefix.replace( /\$\{([\w-]+)\}/g, function(m, key){ return helpers[key].apply(this); } );
data.forEach(
function(i){
// template_item
// 取代 ${key:format(args)} 形式的字串 - 參考自 Ext.Template library - http://www.extjs.com
txt += template_item.replace( /\$\{([\w-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g, function(m, key, format, args){
if(format){
args = [i, i[key]].concat(args.split(','));
return helpers[format].apply(this, args);
}
else {
return i[key] !== undefined ? i[key] : "";
}
});
}, this
);
// template_suffix
txt += template_suffix.replace( /\$\{([\w-]+)\}/g, function(m, key){ return helpers[key].apply(this); } );
if(!confirm('請選擇匯出檔案的位置:')) return;
if (fp.show() != fp.returnCancel) {
if (fp.file.exists()) fp.file.remove(true);
fos.init(fp.file, 0x02 | 0x08 | 0x20, 0666, 0);
os.init(fos, charset, 0, 0x0000);
os.writeString(txt);
os.close();
fos.close();
alert('資料已匯出至 ' + fp.file.path);
}
}
};
leqExtDumper.dump();