Last active
September 27, 2015 14:48
-
-
Save 958/1286784 to your computer and use it in GitHub Desktop.
[keysnail]User script 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>User script manager</name> | |
<description>User script manager</description> | |
<description lang="ja">User スクリプト 管理</description> | |
<author>958</author> | |
<iconURL>https://sites.google.com/site/958site/Home/files/user-script-manager.ks.png</iconURL> | |
<updateURL>https://gist.github.com/958/1286784/raw/user-script-manager-ks.js</updateURL> | |
<version>0.0.4</version> | |
<license>MIT</license> | |
<minVersion>1.8.0</minVersion> | |
<include>main</include> | |
<detail lang="ja"><![CDATA[ | |
=== 使い方 === | |
Greasemonkey, Scriptish の スクリプト を管理します | |
以下のバージョンで動作確認を行っています | |
- Greasemonkey 1.9 | |
- Scriptish 0.1.11 | |
* Greasemonkey と Scriptish の同時使用には対応していません | |
==== User script を管理する ==== | |
エクステ 'user-script-manager-show' を実行すると、インストールされている User スクリプトが一覧表示されます | |
ここで指定したスクリプトの有効・無効切り替え、アンインストールなどを行うことができます | |
==== User script の有効・無効を簡単に切り替える ==== | |
エクステ 'user-script-manager-toggle', 'user-script-manager-enable', 'user-script-manager-disable' は、パラメータで指定したスクリプトの有効・無効を瞬時に切り替えます | |
有効・無効を頻繁に変更するようなスクリプトがある場合に便利でしょう | |
パラメータにはスクリプト名の正規表現を指定してください | |
以下のように使用します | |
>|javascript| | |
ext.exec('user-script-manager-toggle', 'autopagerize'); | |
ext.exec('user-script-manager-enable', 'minibuffer|ldrize'); | |
ext.exec('user-script-manager-disable', 'minibuffer|ldrize'); | |
||< | |
エクステ 'user-script-manager-toggle-all', 'user-script-manager-enable-all', 'user-script-manager-disable-all' は、User スクリプトの実行そのものを制御します | |
一時的にすべての User スクリプトを止めたい場合などに使用してください | |
==== User スクリプトコマンドを実行する ==== | |
エクステ 'user-script-manager-show-menu-command' は、Greasemonkey 等のメニューに登録されている User スクリプトコマンド(Auto Pagerize - clear cache 等)を一覧表示し、実行することができます | |
==== 設定 ==== | |
エクステ 'user-script-manager-show' のキーマップを変更したい人は、次のような設定を .keysnail.js の PRESERVE エリアへ | |
>|javascript| | |
plugins.options["user_script_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", | |
// User script manager specific actions | |
"T" : "toggle", | |
"E" : "edit", | |
"U" : "uninstall", | |
"S" : "sooner", // (Greasemonkey only) | |
"L" : "later", // (Greasemonkey only) | |
'O' : 'option', | |
"M" : "open-sciprt-manager", | |
}; | |
||< | |
]]></detail> | |
</KeySnailPlugin>; | |
// Option | |
let pOptions = plugins.setupOptions("user_script_manager", { | |
"keymap": { | |
preset: { | |
'T': 'toggle', | |
'E': 'edit', | |
'U': 'uninstall', | |
'S': 'sooner', | |
'L': 'later', | |
'O': 'option', | |
'M': 'open-script-manager', | |
}, | |
description: M({ | |
ja: "メイン画面の操作用キーマップ", | |
en: "Local keymap for manipulation" | |
}) | |
}, | |
}, PLUGIN_INFO); | |
// Add ext | |
let usm = (function() { | |
let isScriptish = (window.Scriptish_openInEditor) ? true : false; | |
const SCRIPT_ICON = (isScriptish) ? | |
"chrome://scriptish/skin/userscript.png" : "chrome://greasemonkey/skin/userscript.png"; | |
let getConfig = function(callback) | |
(!isScriptish) ? callback(window.GM_util.getService()._config) : callback({}) | |
let openInEditor = function(script) | |
(!isScriptish) ? window.GM_util.openInEditor(script) : window.Scriptish_openInEditor(script, window); | |
function getScripts(callback) | |
(isScriptish) ? callback(window.Scriptish_config.scripts) : getConfig(function(config) callback(config.scripts)); | |
function scriptsToCollections(scripts) | |
scripts.map(function(s) [ | |
s.enabled, s.needsUninstall, s.icon.fileURL, s.name, s.version, | |
formatDate(s.modifiedDate || s.updateDate), s.description]); | |
function formatDate(date) | |
[date.getYear() + 1900, date.getMonth() + 1, date.getDate()].join('/'); | |
function showList() { | |
let GM_uninstallQueue = {}; | |
getScripts(function(scripts) { | |
let baseActions = [ | |
[function (aIndex, rows) { | |
if (aIndex >= 0) { | |
openInEditor(scripts[aIndex]); | |
} | |
}, | |
'Edit script', | |
'edit'], | |
[function (aIndex, rows) { | |
if (aIndex >= 0) { | |
rows[aIndex][0] = scripts[aIndex].enabled = !scripts[aIndex].enabled; | |
prompt.refresh(); | |
} | |
}, | |
'Toggle status', | |
'toggle,c'], | |
[function (aIndex, rows) { | |
if (aIndex >= 0) { | |
if (isScriptish) { | |
if (rows[aIndex][1] == true) | |
scripts[aIndex].cancelUninstall(); | |
else | |
scripts[aIndex].uninstall(); | |
} else { | |
if (rows[aIndex][1] == true) { | |
delete(GM_uninstallQueue[scripts[aIndex].id]); | |
scripts[aIndex].needsUninstall = false; | |
} else { | |
GM_uninstallQueue[scripts[aIndex].id] = scripts[aIndex]; | |
scripts[aIndex].needsUninstall = true; | |
} | |
} | |
rows[aIndex][1] = scripts[aIndex].needsUninstall; | |
prompt.refresh(); | |
} | |
}, | |
'Uninstall / Cancel uninstall', | |
'uninstall,c'], | |
[function (aIndex, rows) { | |
if (aIndex >= 0) { | |
let features = "chrome,titlebar,toolbar,centerscreen"; | |
try { | |
let instantApply = util.getBoolPref("browser.preferences.instantApply"); | |
features += instantApply ? ",dialog=no" : ",modal"; | |
} catch (e) { | |
features += ",modal"; | |
} | |
let optionsURL = (isScriptish) ? | |
scripts[aIndex].optionsURL : | |
'chrome://greasemonkey/content/scriptprefs.xul#' + scripts[aIndex].id; | |
window.openDialog(optionsURL, "", features); | |
} | |
}, | |
'Option', | |
'option,c'], | |
[function () BrowserOpenAddonsMgr(isScriptish ? "addons://list/userscript" : "addons://list/greasemonkey-user-script"), | |
'Open script manager', | |
'open-script-manager'], | |
]; | |
let actions = isScriptish ? baseActions : baseActions.concat([ | |
[function (aIndex, rows) { | |
if (aIndex > 0) { | |
getConfig(function(config){ | |
config.move(scripts[aIndex], -1); | |
{ | |
let temp = scripts[aIndex - 1]; | |
scripts[aIndex - 1] = scripts[aIndex]; | |
scripts[aIndex] = temp; | |
} | |
{ | |
let temp = rows[aIndex - 1]; | |
rows[aIndex - 1] = rows[aIndex]; | |
rows[aIndex] = temp; | |
} | |
prompt.refresh(aIndex - 1); | |
}); | |
} | |
}, | |
'Sooner', | |
'sooner,c'], | |
[function (aIndex, rows) { | |
if (aIndex >= 0 && (rows.length - 1) > aIndex) { | |
getConfig(function(config) { | |
config.move(scripts[aIndex], 1); | |
{ | |
let temp = scripts[aIndex + 1]; | |
scripts[aIndex + 1] = scripts[aIndex]; | |
scripts[aIndex] = temp; | |
} | |
{ | |
let temp = rows[aIndex + 1]; | |
rows[aIndex + 1] = rows[aIndex]; | |
rows[aIndex] = temp; | |
} | |
prompt.refresh(aIndex + 1); | |
}); | |
} | |
}, | |
'Later', | |
'later,c'], | |
]); | |
prompt.selector({ | |
message : "pattern:", | |
collection : scriptsToCollections(scripts), | |
flags : [HIDDEN | IGNORE, HIDDEN | IGNORE, ICON | IGNORE, 0, 0, 0, 0], | |
style : [0, 0, 0, style.prompt.description], | |
header : ["Name", "Version", "Modified date", "Description"], | |
width : [30, 10, 10, 50], | |
keymap : pOptions["keymap"], | |
stylist : function(args) { | |
let style = ""; | |
if (!args[0]) | |
style += "opacity: 0.5;"; | |
if (args[1]) | |
style += "text-decoration: line-through"; | |
return style; | |
}, | |
actions : actions, | |
onFinish : function() { | |
if (!isScriptish) { | |
getConfig(function(config) { | |
for (let id in GM_uninstallQueue) | |
config.uninstall(GM_uninstallQueue[id]); | |
config._save(true); | |
}); | |
} else { | |
window.Scriptish_config.uninstallScripts(); | |
} | |
}, | |
}); | |
}); | |
} | |
function toggleState(name) { | |
if (!name) return; | |
let re = new RegExp(name, "i"); | |
getScripts(function(scripts) | |
scripts.filter(function(s) re.test(s.name)).forEach(function(s) s.enabled = !s.enabled)); | |
} | |
function enableState(name) { | |
if (!name) return; | |
let re = new RegExp(name, "i"); | |
getScripts(function(scripts) | |
scripts.filter(function(s) re.test(s.name)).forEach(function(s) s.enabled = true)); | |
} | |
function disableState(name) { | |
if (!name) return; | |
let re = new RegExp(name, "i"); | |
getScripts(function(scripts) | |
scripts.filter(function(s) re.test(s.name)).forEach(function(s) s.enabled = false)); | |
} | |
function enableAll() | |
(isScriptish) ? Scriptish.enabled = true : GM_util.setEnabled(true); | |
function disableAll() | |
(isScriptish) ? Scriptish.enabled = false : GM_util.setEnabled(false); | |
function toggleAll() | |
(isScriptish) ? Scriptish.enabled = !Scriptish.enabled : GM_util.setEnabled(!GM_util.getEnabled()); | |
function showMenuCommands() { | |
let menus = []; | |
let commands = []; | |
if (isScriptish) { | |
menus = window.Scriptish_BrowserUI.currentMenuCommander.toolsMenuItems; | |
commands = [menus[i].getAttribute('label') for (i in menus)]; | |
} else { | |
GM_BrowserUI.gmSvc.withAllMenuCommandsForWindowId( | |
GM_util.windowId(gBrowser.contentWindow), | |
function(index, command) { | |
if (command.frozen) return; | |
menus.push(command); | |
}); | |
commands = [menus[i].name for (i in menus)]; | |
} | |
if (menus.length == 0) { | |
display.echoStatusBar("No Menu Command"); | |
return false; | |
} | |
prompt.selector({ | |
message: "Menu Command :", | |
callback: function (index) { | |
let item = menus[index]; | |
return (item._commandFunc || item.commandFunc)(); | |
}, | |
header: ["Command"], | |
collection: commands, | |
}); | |
} | |
return { | |
show: showList, | |
toggle: toggleState, | |
enable: enableState, | |
disable: disableState, | |
toggleAll: toggleAll, | |
enableAll: enableAll, | |
disableAll: disableAll, | |
showMenuCommands: showMenuCommands, | |
}; | |
})(); | |
plugins.withProvides(function (provide) { | |
provide("user-script-manager-show", | |
function (ev, arg) usm.show(arg), | |
M({ja: "User script manager - リストを表示", | |
en: "User script manager - Show list"}) | |
); | |
provide("user-script-manager-toggle", | |
function (ev, arg) usm.toggle(arg), | |
M({ja: "User script manager - 指定スクリプトの有効・無効をトグル", | |
en: "User script manager - Toggle script state"}) | |
); | |
provide("user-script-manager-enable", | |
function (ev, arg) usm.enable(arg), | |
M({ja: "User script manager - 指定スクリプトを有効に", | |
en: "User script manager - Enable script state"}) | |
); | |
provide("user-script-manager-disable", | |
function (ev, arg) usm.disable(arg), | |
M({ja: "User script manager - 指定スクリプトを無効に", | |
en: "User script manager - Disable script state"}) | |
); | |
provide("user-script-manager-toggle-all", | |
function (ev, arg) usm.toggleAll(), | |
M({ja: "User script manager - ユーザスクリプトの有効・無効をトグル", | |
en: "User script manager - Toggle all script state"}) | |
); | |
provide("user-script-manager-enable-all", | |
function (ev, arg) usm.enableAll(), | |
M({ja: "User script manager - ユーザスクリプトを有効に", | |
en: "User script manager - Enable all script state"}) | |
); | |
provide("user-script-manager-disable-all", | |
function (ev, arg) usm.disableAll(), | |
M({ja: "User script manager - ユーザスクリプトを無効に", | |
en: "User script manager - Disable all script state"}) | |
); | |
provide("user-script-manager-show-menu-command", | |
function (ev, arg) usm.showMenuCommands(), | |
M({ja: "User script manager - Userスクリプトのメニューコマンドを実行", | |
en: "User script manager - Execute user script command"}) | |
); | |
}, PLUGIN_INFO); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment