Last active
September 26, 2015 00:47
-
-
Save 958/1011984 to your computer and use it in GitHub Desktop.
[keysnail]Firefox addon manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Info | |
let PLUGIN_INFO = | |
<KeySnailPlugin> | |
<name>Firefox addon manager</name> | |
<description>Firefox addon manager</description> | |
<description lang="ja">Firefox のアドオン管理</description> | |
<updateURL>https://gist.github.com/958/1011984/raw/firefox-addon-manager.ks.js</updateURL> | |
<iconURL>https://sites.google.com/site/958site/Home/files/firefox-addon-manager.ks.png</iconURL> | |
<author>958</author> | |
<version>0.0.8.0</version> | |
<license>GPL 2.0</license> | |
<minVersion>1.8.0</minVersion> | |
<include>main</include> | |
<detail lang="ja"><![CDATA[ | |
=== 使い方 === | |
Firefox のアドオンの管理を行えます | |
※Firefox 4 以降でのみ動作します | |
エクステ 'firefox-addon-manager-show' を実行するとアドオンの一覧が表示されます | |
この際の表示スタイルの意味は以下の通りです | |
薄く表示: | |
無効アドオン | |
取り消し線: | |
アンインストールアドオン | |
チェックアイコン: | |
アップデート済みアドオン | |
太字: | |
Firefox の再起動後に状態が反映 | |
エクステ 'firefox-addon-manager-toggle', 'firefox-addon-manager-enable', 'firefox-addon-manager-disable' は、パラメータで指定したアドオンの有効・無効を瞬時に切り替えます | |
パラメータにはアドオン名の正規表現を指定してください | |
以下のように使用します | |
>|| | |
ext.exec('firefox-addon-manager-toggle', 'adobe acrobat'); | |
ext.exec('firefox-addon-manager-enable', 'shockwave|silverlight'); | |
ext.exec('firefox-addon-manager-disable', 'shockwave|silverlight'); | |
||< | |
エクステ 'firefox-addon-manager-show' のキーマップを変更したい人は、次のような設定を .keysnail.js の PRESERVE エリアへ | |
>|| | |
plugins.options["firefox_addon_manager.keymap"] = { | |
"C-z" : "prompt-toggle-edit-mode", | |
"SPC" : "prompt-next-page", | |
"b" : "prompt-previous-page", | |
"j" : "prompt-next-completion", | |
"k" : "prompt-previous-completion", | |
"g" : "prompt-beginning-of-candidates", | |
"G" : "prompt-end-of-candidates", | |
"q" : "prompt-cancel", | |
// Firefox addon manager specific actions | |
"T" : "toggle-state", | |
"O" : "option", | |
"U" : "toggle-uninstall", | |
"P" : "toggle-update", | |
"M" : "open-addon-manager", | |
}; | |
||< | |
]]></detail> | |
</KeySnailPlugin>; | |
// Option | |
let pOptions = plugins.setupOptions("firefox_addon_manager", { | |
"keymap": { | |
preset: { | |
"T" : "toggle-state", | |
"O" : "option", | |
"U" : "toggle-uninstall", | |
"P" : "toggle-update", | |
"M" : "open-addon-manager", | |
}, | |
description: M({ | |
ja: "メイン画面の操作用キーマップ", | |
en: "Local keymap for manipulation" | |
}) | |
}, | |
"sort_col": { | |
preset: "name", | |
description: M({ | |
ja: "ソート時に使用するカラム (name, updateDate) (初期値: name)", | |
en: "Sort column (name, updateDate) (default: name)" | |
}) | |
}, | |
"sort_type": { | |
preset: "ASC", | |
description: M({ | |
ja: "ソート方法 (ASC, DESC) (初期値: ASC)", | |
en: "Sort type (ASC, DESC) (default: ASC)" | |
}) | |
}, | |
}, PLUGIN_INFO); | |
// Add ext | |
let pm = (function() { | |
function getaddons(callback) { | |
let am = {}; | |
Components.utils.import("resource://gre/modules/AddonManager.jsm", am); | |
am.AddonManager.getAddonsByTypes(["extension"], function (addons) { | |
let values = addons.map(function (a) { | |
return { | |
icon: a.iconURL || "chrome://mozapps/skin/extensions/extensionGeneric.png", | |
name: a.name, | |
version: a.version, | |
updateDate: a.updateDate, | |
description: a.description, | |
get isPendingOperation() (a.pendingOperations != 0), | |
get disabled() a.userDisabled, | |
set disabled(val) a.userDisabled = val, | |
get uninstalled() a.pendingOperations & am.AddonManager.PENDING_UNINSTALL, | |
get updated() a.pendingOperations & am.AddonManager.PENDING_UPGRADE, | |
uninstall: a.uninstall, | |
cancelUninstall: a.cancelUninstall, | |
id: a.id, | |
optionsURL: a.optionsURL, | |
get isInlineOption() a.optionsType == 2, | |
homepageURL: a.homepageURL, | |
findUpdates: function() a.findUpdates(updateCheckListener, am.AddonManager.UPDATE_WHEN_USER_REQUESTED), | |
cancelUpdates: function() a.pendingUpgrade.install.cancel(), | |
}; | |
}); | |
callback(values); | |
}); | |
} | |
let updateCheckListener = { | |
onUpdateAvailable: function(aAddon, aInstall) { | |
display.notify([aInstall.name, aInstall.version].join(' '), [{ | |
label: 'Update', | |
callback: function (aNotifycation) { | |
try { | |
aNotifycation.close(); | |
} catch (e) { } | |
aInstall.install(); | |
}, | |
accessKey: 'u' | |
}], aInstall.iconURL); | |
}, | |
onNoUpdateAvailable: function(aAddon) { | |
display.notify(aAddon.name + ' is no update.', null, aAddon.iconURL); | |
}, | |
onUpdateFinished: function(aAddon, aError) { | |
if (aError != 0) { | |
util.message('Update error: Error no=' + aError); | |
display.notify('Error : ' + aAddon.name + ' update check.', null, aAddon.iconURL); | |
} | |
} | |
}; | |
function formatDate(date) { | |
return [date.getYear() + 1900, date.getMonth() + 1, date.getDate()].join('/'); | |
} | |
function sort(addons, name, asc) { | |
function sort_string(a, b) { | |
let ret; | |
if (asc) | |
ret = (a[name].toLowerCase() < b[name].toLowerCase()) ? -1 : 1; | |
else | |
ret = (a[name].toLowerCase() > b[name].toLowerCase()) ? -1 : 1; | |
return ret; | |
} | |
function sort_date(a, b) { | |
let ret; | |
if (asc) | |
ret = (a[name].getTime() < b[name].getTime()) ? -1 : 1; | |
else | |
ret = (a[name].getTime() > b[name].getTime()) ? -1 : 1; | |
return ret; | |
} | |
let sortFunc = (name == 'name') ? sort_string : sort_date; | |
addons.sort(sortFunc); | |
return addons; | |
} | |
function copyList(){ | |
getaddons(function(addons){ | |
let collection = sort(addons, pOptions['sort_col'], (pOptions['sort_type'] == 'ASC')).map(function(p){ | |
return p.name + " " + p.version + | |
(p.isPendingOperation ? (p.uninstalled ? " (ToBeDeleted)" | |
: (p.disabled ? " (ToBeDisabled)" | |
: (p.updated ? " (ToBeUpdated)" | |
: " (ToBeEnabled)"))) | |
: (p.disabled ? " (Disabled)" : "")) + | |
"\n " + p.homepageURL; | |
}); | |
command.setClipboardText(collection.join("\n") + "\n"); | |
display.echoStatusBar(String(collection.length) + " addons information was copied to clipboard."); | |
}); | |
} | |
function showList() { | |
getaddons(function(addons) { | |
let collection = sort(addons, pOptions['sort_col'], (pOptions['sort_type'] == 'ASC')).map(function(p) [ | |
p.isPendingOperation, | |
p.disabled, | |
p.uninstalled, | |
p.updated, | |
p.icon, | |
p.name, | |
p.version, | |
formatDate(p.updateDate), | |
p.description | |
]); | |
prompt.selector({ | |
message : "pattern:", | |
collection : collection, | |
flags : [HIDDEN | IGNORE, HIDDEN | IGNORE, HIDDEN | IGNORE, HIDDEN | IGNORE, ICON | IGNORE, 0, 0, 0, 0], | |
style : [0, 0, 0, style.prompt.description], | |
header : ["Name", "Version", "Update date", "Description"], | |
width : [30, 10, 10, 50], | |
keymap : pOptions["keymap"], | |
stylist : function(args, n, current) { | |
let style = ""; | |
if (args[1]) | |
style += "opacity: 0.5;"; | |
if (args[2]) | |
style += "text-decoration: line-through;"; | |
if (args[3] && n == 4) | |
style += "padding-left: 20px;"+ | |
"background: url(chrome://mozapps/skin/extensions/alerticon-info-positive.png) no-repeat;"; | |
if (args[0]) | |
style += "font-weight: bold;"; | |
return style; | |
}, | |
actions : [ | |
[function (aIndex) { | |
if (aIndex >= 0) { | |
let isInlineOption = addons[aIndex].isInlineOption; | |
let optionsURL = addons[aIndex].optionsURL; | |
if (optionsURL) { | |
if (isInlineOption) { | |
BrowserOpenAddonsMgr("addons://detail/" + encodeURIComponent(addons[aIndex].id)); | |
} else { | |
let features = "chrome,titlebar,toolbar,centerscreen"; | |
try { | |
let instantApply = util.getBoolPref("browser.preferences.instantApply"); | |
features += instantApply ? ",dialog=no" : ",modal"; | |
} catch (e) { | |
features += ",modal"; | |
} | |
window.openDialog(optionsURL, "", features); | |
} | |
} | |
} | |
}, | |
'Show option dialog', | |
'option,c'], | |
[function (aIndex, rows) { | |
if (aIndex >= 0) { | |
rows[aIndex][1] = addons[aIndex].disabled = !addons[aIndex].disabled; | |
rows[aIndex][0] = addons[aIndex].isPendingOperation; | |
prompt.refresh(); | |
} | |
}, | |
'Enable / Disable', | |
'toggle-state,c'], | |
[function (aIndex, rows) { | |
if (aIndex >= 0) { | |
(addons[aIndex].uninstalled) ? | |
addons[aIndex].cancelUninstall() : addons[aIndex].uninstall(); | |
rows[aIndex][2] = addons[aIndex].uninstalled; | |
rows[aIndex][0] = addons[aIndex].isPendingOperation; | |
prompt.refresh(); | |
} | |
}, | |
'Uninstall / Cancel uninstall', | |
'toggle-uninstall,c'], | |
[function (aIndex) { | |
if (aIndex >= 0) | |
(addons[aIndex].updated) ? | |
addons[aIndex].cancelUpdates() : addons[aIndex].findUpdates(); | |
}, | |
'Find update / Cancel update', | |
'toggle-update'], | |
[function () BrowserOpenAddonsMgr("addons://list/extension"), | |
'Open addon manager', | |
'open-addon-manager'], | |
] | |
}); | |
}); | |
} | |
function toggleState(name) { | |
if (!name) return; | |
let re = new RegExp(name, "i"); | |
getaddons(function(addons) { | |
addons.filter(function(p) re.test(p.name)).forEach(function(p) p.disabled = !p.disabled); | |
}); | |
} | |
function enableState(name) { | |
if (!name) return; | |
let re = new RegExp(name, "i"); | |
getaddons(function(addons) { | |
addons.filter(function(p) re.test(p.name)).forEach(function(p) p.disabled = false); | |
}); | |
} | |
function disableState(name) { | |
if (!name) return; | |
let re = new RegExp(name, "i"); | |
getaddons(function(addons) { | |
addons.filter(function(p) re.test(p.name)).forEach(function(p) p.disabled = true); | |
}); | |
} | |
return { | |
copy: copyList, | |
show: showList, | |
toggle: toggleState, | |
enable: enableState, | |
disable: disableState, | |
}; | |
})(); | |
if ("@mozilla.org/addons/integration;1" in Cc) | |
// Over Gecko 2.0 | |
plugins.withProvides(function (provide) { | |
provide("firefox-addon-manager-copyto-clipboard", | |
function (ev, arg) pm.copy(), | |
M({ja: "Firefox addon manager - アドオンのリストをクリップボードにコピー", | |
en: "Firefox addon manager - Copy to clipboard list of addons"}) | |
); | |
provide("firefox-addon-manager-show", | |
function (ev, arg) pm.show(arg), | |
M({ja: "Firefox addon manager - リストを表示", | |
en: "Firefox addon manager - Show list"}) | |
); | |
provide("firefox-addon-manager-toggle", | |
function (ev, arg) pm.toggle(arg), | |
M({ja: "Firefox addon manager - 指定アドオンの有効・無効をトグル", | |
en: "Firefox addon manager - Toggle addon state"}) | |
); | |
provide("firefox-addon-manager-enable", | |
function (ev, arg) pm.enable(arg), | |
M({ja: "Firefox addon manager - 指定アドオンを有効に", | |
en: "Firefox addon manager - Enable addon state"}) | |
); | |
provide("firefox-addon-manager-disable", | |
function (ev, arg) pm.disable(arg), | |
M({ja: "Firefox addon manager - 指定アドオンを無効に", | |
en: "Firefox addon manager - Disable addon state"}) | |
); | |
}, PLUGIN_INFO); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment