// ==UserScript==
// @name 0001.アドオン有効状態を保存.S.js
// @namespace http://efcl.info/
// @description 拡張機能の有効状態を保存/復元
// @author azu
// @note userMenu.jsが必要です
// @version 2010-05-10 作成
// ==/UserScript==
// 大部分は0001.アドオン有効状態を保存.S.jsが元になっています。
(function(){
//CSS
function addStyle(doc, css){
var head = doc.getElementsByTagName('head')[0]; if(!head) return;
var style = doc.createElement('style');
style.type = 'text/css';
style.textContent = css;
head.appendChild(style);
}
//プラグインのリストを得る
function plugins_find(){
var phs = Components.classes["@mozilla.org/plugin/host;1"]
.getService(Components.interfaces.nsIPluginHost);
var plugins = phs.getPluginTags({ });
// Locale sensitive sort
function compare(a, b) {
return String.localeCompare(a.name, b.name);
}
plugins.sort(compare);
var gPlugins = { };
var retVal = [];
for (var i = 0; i < plugins.length; i++) {
var plugin = plugins[i];
var name = plugin.name;
var version = plugin.version;
if (!(name in gPlugins))
gPlugins[name] = { };
// Removes all html markup in a plugin's description
var description = plugin.description.replace(/<\/?[a-z][^>]*>/gi, " ");
if (!(description in gPlugins[name])) {
var disabled = plugin.disabled;
gPlugins[name][description] = { name:name, disabled:disabled, description:description, version:version};
}
}
for (var pluginName in gPlugins) {
for (var pluginDesc in gPlugins[pluginName]) {
retVal.push(gPlugins[pluginName][pluginDesc]);
}
}
return retVal;
}
//拡張機能とテーマのリストを得る
function exts_find(aOptions,restoremode) {
const PREFIX_ITEM_URI = "urn:mozilla:item:";
const PREFIX_NS_EM = "http://www.mozilla.org/2004/em-rdf#";
var prefService = Components.classes[ "@mozilla.org/preferences-service;1" ]
.getService( Components.interfaces.nsIPrefBranch );
var extmgr = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
var retVal = [];
var items = extmgr.getItemList(aOptions, {});
// 復元処理
if(restoremode){
var extsDisable = GM_getValue("extsDisable" , false);
if(extsDisable){
extsDisable = JSON.parse(extsDisable);
}else{
return false;
}
for (var i = 0; i < items.length; i++) {
var aItem = items[i];
// 追加されたaddonはundefinedになる
if(extsDisable[aItem.id]){
extmgr.disableItem(aItem.id);
}else if(typeof extsDisable[aItem.id] != "undefined"){ // falseのもの
extmgr.enableItem(aItem.id);
}
}
return true;
}
for (var i = 0; i < items.length; i++) {
var aItem = items[i];
var disabled = false;
var description = "";
var homepageURL = "";
var minVersion = "";
var maxVersion = "";
var targetApplication = null;
var rdf = Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);
var itemResource = rdf.GetResource(PREFIX_ITEM_URI + aItem.id);
if (itemResource) {
var ds = extmgr.datasource;
var target = ds.GetTarget(itemResource, rdf.GetResource(PREFIX_NS_EM + "isDisabled"), true);
if (target && target instanceof Ci.nsIRDFLiteral)
disabled = (target.Value == "true");
target = ds.GetTarget(itemResource, rdf.GetResource(PREFIX_NS_EM + "description"), true);
if (target && target instanceof Ci.nsIRDFLiteral)
description = target.Value;
target = ds.GetTarget(itemResource, rdf.GetResource(PREFIX_NS_EM + "homepageURL"), true);
if (target && target instanceof Ci.nsIRDFLiteral)
homepageURL = target.Value;
target = ds.GetTarget(itemResource, rdf.GetResource(PREFIX_NS_EM + "resource"), true);
if (target && target instanceof Ci.nsIRDFLiteral)
targetApplication = target.Value;
}
var myaddon = extmgr.getItemForID(aItem.id);
var update = true;
try{
update = prefService.getBoolPref("extensions."+aItem.id+".update.enabled");
}catch(e){}
var newExt = {id :aItem.id,
name :aItem.name,
homepageURL :homepageURL,
version :aItem.version,
disabled :disabled,
description :description,
minVersion :myaddon.minAppVersion,
maxVersion :myaddon.maxAppVersion,
updatedsabled: !update};
retVal.push(newExt);
}
return retVal;
}
// https://developer-stage.mozilla.org/ja/Code_snippets/Dialogs_and_Prompts
// https://developer-stage.mozilla.org/en/nsIPromptService#confirmEx%28%29
var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var check = {value: false}; // default the checkbox to false
var flags = prompts.BUTTON_POS_0 * prompts.BUTTON_TITLE_SAVE +
prompts.BUTTON_POS_1 * prompts.BUTTON_TITLE_CANCEL +
prompts.BUTTON_POS_2 * prompts.BUTTON_TITLE_IS_STRING;
// This value of flags will create 3 buttons. The first will be "Save", the
// second will be the value of aButtonTitle1, and the third will be "Cancel"
var button = prompts.confirmEx(null, "Title of this Dialog", "What do you want to do?",
flags, "","","\u5fa9\u5143", null, check);
// 保存:0 キャンセル:1 復元:2
var extObj = {};
if(button == 0){
exts_find(Ci.nsIUpdateItem.TYPE_EXTENSION).map( function(e,i) extObj[e.id] = e.disabled);
try{
GM_setValue("extsDisable",JSON.stringify(extObj));
}catch(e){
prompts.alert(window, "\u51e6\u7406\u7d50\u679c", e.description);
}
prompts.alert(window, "\u51e6\u7406\u7d50\u679c", "\u4fdd\u5b58\u3057\u307e\u3057\u305f\uff01");
}else if(button == 2){
var result = exts_find(Ci.nsIUpdateItem.TYPE_EXTENSION , true);
if(result){
prompts.alert(window, "\u51e6\u7406\u7d50\u679c", "\u5fa9\u5143\u306b\u6210\u529f\u3057\u307e\u3057\u305f\uff01\n\u518d\u8d77\u52d5\u3057\u3066\u4e0b\u3055\u3044\uff01");
}else{
prompts.alert(window, "\u51e6\u7406\u7d50\u679c", "\u5fa9\u5143\u306b\u5931\u6557\u3057\u307e\u3057\u305f\uff01");
}
return;
}else if(button == 1){
return;
}
// タブ作成
var w = gBrowser.getBrowserForTab(gBrowser.addTab());
w.addEventListener('load', function(e) {
w.removeEventListener('load', arguments.callee, true);
var aDate = new Date();
var str = "
Listing Date " + aDate.getFullYear().toString()+"/"+(aDate.getMonth()+1).toString()+"/"+aDate.getDate().toString()+" "+aDate.getHours().toString()+":"+aDate.getMinutes().toString()+":"+aDate.getSeconds().toString()+"."+aDate.getMilliseconds().toString()+"
";
str += "EXTENSION
No. | Name | Version | Description | Enabled | Update | App Version" + exts_find(Ci.nsIUpdateItem.TYPE_EXTENSION).map( function(e,i) " |
---|
"+(i+1)+" | "+ e.name+" | "+e.version+" | "+e.description+" | "+(e.disabled?"(disabled)":"")+" | "+(e.updatedsabled?"(disabled)":"")+" | "+e.minVersion+"-"+e.maxVersion).join("")+" |
";
str += "THEME
No. | Name | Version | Description | Enabled | Update | App Version" + exts_find(Ci.nsIUpdateItem.TYPE_THEME).map( function(e,i) " |
---|
"+(i+1)+" | "+ e.name+" | "+e.version+" | "+e.description+" | "+(e.disabled?"(disabled)":"")+" | "+(e.updatedsabled?"(disabled)":"")+" | "+e.minVersion+"-"+e.maxVersion).join("")+" |
";
str += "PLUGINS
No. | Name | Version | Description | Enabled" + plugins_find().map( function(e,i) " |
---|
"+(i+1)+" | "+ e.name+" | "+e.version+" | "+e.description+" | "+(e.disabled?"(disabled)":"")).join("")+" |
";
var doc = w.contentDocument;
doc.body.innerHTML = str;
addStyle(doc, "table,td,th{border:1px green solid;empty-cells:show;} ");
doc.title = 'Add-ons List';
gBrowser.selectedTab = gBrowser.mTabs[gBrowser.getBrowserIndexForDocument(doc)]
}, true);
})();