Skip to content

Instantly share code, notes, and snippets.

@iMyon
Created August 2, 2014 07:34
Show Gist options
  • Save iMyon/f34e98c4302e336ca999 to your computer and use it in GitHub Desktop.
Save iMyon/f34e98c4302e336ca999 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<!--
// ==UserScript==
// @name rebuild_userChrome_Alice0775_UC脚本管理器_火狐橙菜单+可拖动按钮版20130126.uc.xul
// @namespace http://space.geocities.yahoo.co.jp/gl/alice0775
// @description Clear the cache of scripts for userChrome.js, Open a new window
// @note userChrome.js用のスクリプトのキャッシュをクリアーし,新しいウインドウを開く
// @include main
// @charset UTF-8
// @compatibility Firefox 3.5b4pre 3.6a1pre 4.0b7pre
// @author Alice0775
// @note ==UC管理器简体中文图形界面 forked by iwo & dannylee - Mozest.com==
// @note 转载请注明以下出处!
// @note 脚本主页@Mozest论坛 http://g.mozest.com/thread-41859-1-1
// @version 2013/01/26 19:00 图形界面升级为可拖动至Fx各工具栏的按钮
// @note ================================================================
// ==/UserScript==
// @note 2013/01/20 12:00 Fx21a+适用,更正菜单项译名
// @note 2013/01/12 22:00 基于20121130原版更新,Fx20a适用(已经不使用不再支持的E4X-xml语法)
// @note 2012/10/10 20:00 随原作更新,修正Ubuntu(Windows也可能)不能正常“打开Chrome文件夹”的错误
// @note 2012/09/18 22:00 菜单优化,内部syntax整理
// @note 2012/09/16 10:00 AppMenu按钮使用内部新20*20图标,可配合rebuild_userChrome_xul_Menu Icons.css使菜单图标化
// @note 2012/07/14 14:00 使用16*16图标
// @note 2012/07/13 18:00 支持右键编辑含中文名脚本文件
// @note ================================================================
// @version 2012/11/30 22:00 ubuntu12.04.1 "chromeフォルダを開く" に失敗することがあるのを修正
// @version 2012/09/30 09:00 ubuntu12.04.1 "chromeフォルダを開く" に失敗することがあるのを修正
// @version 2012/02/25 23:00 restart
// @version 2010/10/25 22:00 Bug 574688 adon bar
// @version 2010/07/04 00:00 nsDragAndDrop
// @version 2009/11/14 00:00 Seamonkeyに対応
// @version 2009/08/24 00:00 Namoroka3.6a2pre で右クリックでのスクリプト編集時にコンテキストメニューが表示されるのを修正
// @version 2009/04/10 00:00 Minefield3.6a1pre での動作改善
// @version 2009/03/27 00:00 nsIProcess変更
// @version 2008/02/25 00:00 reuseのデフォルト値trueに変更
// @version 2008/01/09 02:00 スクリプト保存ファイルピッカーをキャンセル時のエラー処理追加
// @version 2008/01/04 16:00 スクリプトのドロップをstatusbar-display上に変更
// @version 2007/12/15 18:00 base64データスキームの保存に対応
// @version 2007/12/15 02:00 ttp://の保存に対応
// @version 2007/12/15 01:00 メニューが表示されない場合があるのを修正
// @version 2007/12/14 23:00 saveFolderModokiがある時スクリプトのリンクをステータスバーの左1/3にドロップすることで, chrmeホルダに保存するようにした
// @version 2007/12/14 19:00 日本語のファイル名のスクリプトの有効/無効が機能していなかったのを修正
// @version 2007/12/14 17:00 スクリプトの有効/無効/編集を設定できるようにした
// @Note 使用するエディタを編集しておくこと
-->
<script type="application/javascript" xmlns="http://www.w3.org/1999/xhtml"><![CDATA[
var userChromejs = {
// --- config ---
editor: "C:\\WINDOWS\\system32\\notepad.exe",
//editor: "C:\\Program Files\\hidemaru\\hidemaru.exe",
//editor: "/usr/bin/gedit",
// --- config ---
_statusDisplay: null,
get statusDisplay() {
if (!this._statusDisplay)
this._statusDisplay = document.getElementById('status-bar') ||
document.getElementById('statusbar-display');
return this._statusDisplay;
},
_addonbar: null,
get addonbar() {
if (!this._addonbar)
this._addonbar = document.getElementById('addon-bar');
return this._addonbar;
},
_dragService: null,
get dragService() {
if (!this._dragService)
this._dragService = Cc["@mozilla.org/widget/dragservice;1"]
.getService(Ci.nsIDragService);
return this._dragService;
},
handleEvent: function(event) {
switch(event.type) {
case 'dragover':
this.dragover(event);
break;
case 'drop':
this.drop(event);
break;
case 'unload':
this.uninit();
break;
}
},
init: function(){
window.addEventListener("unload",this , false);
if ("nsDragAndDrop" in window && this.statusDisplay) {
this.statusDisplay.addEventListener('dragover',function(event){nsDragAndDrop.dragOver(event,userChromejs.dndObserver);},true);
this.statusDisplay.addEventListener('dragdrop',function(event){nsDragAndDrop.drop(event,userChromejs.dndObserver);},true);
} else if(this.addonbar) {
this.addonbar.addEventListener('dragover', this ,true);
this.addonbar.addEventListener('drop', this ,true);
}
this.addPrefListener(userChromejs.readLaterPrefListener); // 登録処理
//update menubutton stuff start
var navBar = document.getElementById("nav-bar");
if (!navBar) return;
this.menuBtn = document.createElement("toolbarbutton");
this.menuBtn.setAttribute("id", "userChromeJsManagerMenuBtn");
this.menuBtn.setAttribute("class", "toolbarbutton-1 chromeclass-toolbar-additional");//
this.menuBtn.setAttribute("label", "userChromeJs管理器");
this.menuBtn.setAttribute("tooltiptext", "userChromeJS管理器");
this.menuBtn.setAttribute("type", "menu" /*下拉菜单,右键菜单请替换为*//*"context", "_child"*/);
this.menuBtn.setAttribute("removable", "true");
this.menuBtn.style.listStyleImage = "url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAArUlEQVQ4je3QMQoCMRCF4ddPlRvkBGmEhVRb2W5lueAltvMWlmmFNENO4AkCe4MUHsLS4tmsjWQLF5UVHPiZ7mMY4GfGGENrLZ1zTCl1McY+hDA452itpTGGtwtmWwdYShmf+4N1sGkaeu/Zti0/Am4AbgHuAO4BHgAeRXgS4VmEo8gXwMfpqppV9TrtrKr5HWCeA1NKXa3FYIyxr7UYDCEMtRaDL/+w1jrA1c4do7gmzOLZkZYAAAAASUVORK5CYII=)";
navBar.appendChild(this.menuBtn);
//never ever touch code below Pls!
var xml_menuBtn = '\
<menupopup id="userChromejs_options"\
onpopupshowing="userChromejs.onpopup();"\
context="">\
<menuitem label="打开Chrome文件夹"\
id="userChromejs_openChromeFolder"\
tooltiptext="即用户脚本文件夹"\
accesskey="h"\
class="menuitem-iconic"\
oncommand=\'new Components.Constructor("@mozilla.org/file/local;1","nsILocalFile", "initWithPath")(Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("UChrm", Components.interfaces.nsIFile).path).reveal();\'/>\
<menuitem label="打开新窗口并重置脚本"\
id="userChromejs_rebuild"\
tooltiptext="仅重新载入选中的脚本"\
accesskey="x"\
class="menuitem-iconic"\
oncommand="userChromejs.rebuild();"/>\
<menuitem label="在每个新窗口都重置脚本"\
id="userChrome_setting"\
tooltiptext="仅重新载入选中的脚本"\
accesskey="u"\
oncommand="userChromejs.setting();"\
type="checkbox"/>\
<menuitem label="重新启动浏览器"\
id="userChromejs_restartApp"\
accesskey="r"\
class="menuitem-iconic"\
oncommand="userChromejs.restartApp();"/>\
<menuseparator />\
<menu label="userChromeJS用户脚本命令..."\
id="userChromejs_script_options_Menu"\
accesskey="s"\
class="menu-iconic">\
<menupopup id="userChromejs_script_options_MenuPopup" />\
</menu>\
</menupopup>\
';
//
var range_menuBtn = document.createRange();
var referenceNode = document.getElementById("userChromeJsManagerMenuBtn");
range_menuBtn.selectNodeContents(referenceNode);
range_menuBtn.collapse(false);
range_menuBtn.insertNode(range_menuBtn.createContextualFragment(xml_menuBtn.replace(/\n|\t/g, '')));
range_menuBtn.detach();
//update menubutton stuff end
},
uninit: function(){
if ("nsDragAndDrop" in window && this.statusDisplay) {
this.statusDisplay.removeEventListener('dragover',function(event){nsDragAndDrop.dragOver(event,userChromejs.dndObserver);},true);
this.statusDisplay.removeEventListener('dragdrop',function(event){nsDragAndDrop.drop(event,userChromejs.dndObserver);},true);
} else if(this.addonbar) {
this.addonbar.removeEventListener('dragover', this ,true);
this.addonbar.removeEventListener('drop', this ,true);
}
this.removePrefListener(userChromejs.readLaterPrefListener); // 登録解除
},
dragover: function(event) {
var dragService = Cc["@mozilla.org/widget/dragservice;1"]
.getService(Ci.nsIDragService);
var dragSession = dragService.getCurrentSession();
var supportedTypes = ["text/x-moz-url", "text/unicode", "application/x-moz-file"];
for each (var type in supportedTypes) {
if (event.dataTransfer.types.contains(type)) {
var data = event.dataTransfer.getData(type);
var url = (/^\s*(.*?)\s*$/m.test(data))
? RegExp.$1 : null;
if (/(\.uc\.js|\.uc\.xul|\.uc\.xul\.txt)$/.test(url)) {
dragSession.canDrop = true;
event.preventDefault();
return;
}
}
}
},
drop: function(event) {
var dragService = Cc["@mozilla.org/widget/dragservice;1"]
.getService(Ci.nsIDragService);
var dragSession = dragService.getCurrentSession();
var supportedTypes = ["text/x-moz-url", "text/unicode", "application/x-moz-file"];
for each (var type in supportedTypes) {
if (event.dataTransfer.types.contains(type)) {
var data = event.dataTransfer.getData(type);
this.dndObserver.onDrop(event, {data: data}, dragSession);
return;
}
}
},
dragDropSecurityCheck: function dragDropSecurityCheck(event, dragSession, url) {
if (!url)
return false;
// need to do a security check to make
// sure the source document can load the dropped URI.
url = url.replace(/^\s*|\s*$/g, '');
if (url.indexOf('chrome://') == 0 || url.indexOf('file://') == 0)
return url;
// urlSecurityCheck
try {
urlSecurityCheck(url, gBrowser.contentPrincipal, Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
}
catch(e) {
event.stopPropagation();
//throw 'Drop of ' + url + ' denied.';
return false;
}
return url;
},
dndObserver: {
getSupportedFlavours : function () {
var flavours = new FlavourSet();
flavours.appendFlavour("text/x-moz-url");
flavours.appendFlavour("text/unicode");
flavours.appendFlavour("application/x-moz-file");
return flavours;
},
onDragOver: function (evt,flavour,session){},
onDrop: function (evt,dropdata,session){
var fname;
evt.stopPropagation();
evt.preventDefault();
if (dropdata.data!=""){
//ステータスバーの左1/3にドロップしたか
var target = evt.target;
while(target){
if(target == userChromejs.statusDisplay ||
target == userChromejs.addonbar)
break;
target = target.parentNode;
}
if(!target) return;
if(evt.screenX < target.boxObject.screenX + target.boxObject.width/3)
//saveFolderModokiが必要
if(!saveFolderModoki) return;
//ドロップしたurl
var url = (/^\s*(.*?)\s*$/m.test(dropdata.data))?RegExp.$1:null;
//保存ホルダ nsIFile
var folder = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("UChrm", Components.interfaces.nsIFile);
//デフォルトのファイル名
if(/(.*)\n?(.*)?/m.test(dropdata.data) )
fname = RegExp.$2?RegExp.$2:"";
//データスキームか
if(/(^data:text\/javascript(;.*)?,?)|(^data:application\/x-javascript(;.*)?,?)/.test(url)){
// urlSecurityCheck は saveFolderModoki.directSaveLinkで実施している
saveScript(url, fname, folder);
}else{
//リンクか
if(!/(^h?ttps?:\/\/)|(^ftp:\/\/)/.test(url)) return;
if (/^h?.?.p(s?):(.+)$/i.test(url)){
url = "http" + RegExp.$1 + ':' + RegExp.$2;
if(!RegExp.$2) return null;
fname = url.match(/.+\/(.+)$/)[1];
}
fname = fname.replace(/\.uc\.xul\.txt$/,'.uc.xul');
//スクリプトファイルか?
if(/(\.uc\.js|\.uc\.xul|\.uc\.xul\.txt)$/.test(url)){
if (typeof gBrowser.dragDropSecurityCheck == 'function')
gBrowser.dragDropSecurityCheck(evt, session, url);
else {
userChromejs.dragDropSecurityCheck(evt, session, url)
}
saveScript(url, fname, folder);
}
}
}
function saveScript(url, fname, folder){
//ファイルピッカによりnsIFile決定
var aFile = getFolderPath(fname, folder)
if(!aFile) return;
//フォルダパス
folder = aFile.path.replace(aFile.leafName,'');
//nsILocalFileのフォルダ
var aFolder = saveFolderModoki.initFileWithPath(folder);
if(!aFolder) return;
//リンクを保存
saveFolderModoki.directSaveLink(null, url, aFile.leafName, gBrowser.currentURI, aFolder);
}
function getFolderPath(fname, folder){
//ファイルピッカにより保存先決定
var fp = Components.classes['@mozilla.org/filepicker;1']
.createInstance(Components.interfaces.nsIFilePicker);
fp.init(window, "Save script As", fp.modeSave);
fp.appendFilter("Script Files","*.uc.js; *.uc.xul");
if(/\.uc\.js$/.test(fname)){
fp.defaultExtension = "uc.js";
fp.defaultString = fname;
}else if(/\.uc\.xul$/.test(fname)){
fp.defaultExtension = "uc.xul";
fp.defaultString = fname;
}else{
fp.defaultExtension = "uc.js";
fp.defaultString = fname + ".uc.js";
}
fp.displayDirectory = folder;
if ( fp.show() == fp.returnCancel || !fp.file ) return;
//nsIFile
return fp.file;
}
}
},
rebuild: function(){
var flag = this.getPref("userChrome.enable.reuse",'bool',true);
this.setPref("userChrome.enable.reuse",'bool',false);
setTimeout(function(){OpenBrowserWindow();}, 0);
setTimeout(function(self,flag){self.setPref("userChrome.enable.reuse",'bool',flag);},2000,this,flag);
},
setting: function(){
var flag = this.getPref("userChrome.enable.reuse",'bool',true);
this.setPref("userChrome.enable.reuse",'bool',!flag);
},
//Redo start
onpopup: function(){
var menu;
var menuApp;
var flag = this.getPref("userChrome.enable.reuse",'bool',true);
var menuitem = document.getElementById('userChrome_setting');
menuitem.setAttribute('checked', !flag);
var menuitemApp = document.getElementById('userChrome_setting_appMenu');
menuitemApp.setAttribute('checked', !flag);
//modified to add or remove extra menu items
var uc_menupopup = document.getElementById("userChromejs_options");
for(var i = 6, len = uc_menupopup.childNodes.length; i < len; i++){//4
uc_menupopup.removeChild(uc_menupopup.lastChild);
}
var uc_menupopupApp = document.getElementById("userChromejs_options_appMenu");
for(var k = 4, len = uc_menupopupApp.childNodes.length; k < len; k++){//4
uc_menupopupApp.removeChild(uc_menupopupApp.lastChild);
}
var menuseparator = document.createElement('menuseparator');
uc_menupopup.appendChild(menuseparator);
var menuseparatorApp = document.createElement('menuseparator');
uc_menupopupApp.appendChild(menuseparatorApp);
menuitem = document.createElement('menuitem');
menuitem.setAttribute('label','\u542f\u7528/\u7981\u7528 userChromeJS');//启用禁用
menuitem.setAttribute('tooltiptext','\u56E7rz\n\u5371\u9669\u52A8\u4F5C\uFF01');
menuitem.setAttribute('oncommand','userChromejs.chgDirStat("*");');
menuitem.setAttribute('onclick','userChromejs.clickDirMenuitem(event,true)');
menuitem.setAttribute('type','checkbox');
menuitem.setAttribute('checked', !userChrome_js.dirDisable['*']);
menuitem.dirName = '*';
uc_menupopup.appendChild(menuitem);
menuitemApp = document.createElement('menuitem');
menuitemApp.setAttribute('label','\u542f\u7528/\u7981\u7528 userChromeJS');//启用禁用(火狐橙)
menuitemApp.setAttribute('tooltiptext','\u56E7rz\n\u5371\u9669\u52A8\u4F5C\uFF01');
menuitemApp.setAttribute('oncommand','userChromejs.chgDirStat("*");');
menuitemApp.setAttribute('onclick','userChromejs.clickDirMenuitem(event,true)');
menuitemApp.setAttribute('type','checkbox');
menuitemApp.setAttribute('checked', !userChrome_js.dirDisable['*']);
menuitemApp.dirName = '*';
uc_menupopupApp.appendChild(menuitemApp);
for(var j = 0, lenj = userChrome_js.arrSubdir.length; j < lenj; j++){
var dirName = userChrome_js.arrSubdir[j] == "" ? "root" : userChrome_js.arrSubdir[j];
var flg = false;
for(var i = 0, len = userChrome_js.scripts.length; i < len; i++){
var script = userChrome_js.scripts[i];
if(script.dir != dirName) continue;
flg = true;
break;
}
if(!flg){
for(var i = 0, len = userChrome_js.overlays.length; i < len; i++){
var script = userChrome_js.overlays[i];
if(script.dir != dirName) continue;
flg = true;
break;
}
}
if(!flg) continue;
var menu = document.createElement('menu');
menu.setAttribute('label','chrome/' + (dirName=="root"?"":dirName) );
menu.setAttribute('onclick','userChromejs.clickDirMenu(event)');
if(userChrome_js.dirDisable[dirName])
menu.setAttribute('style', 'font-style:italic;');
menu.dirName = dirName;
menupopup = document.createElement('menupopup');
menupopup.setAttribute('onpopupshowing','event.stopPropagation();');
menuitem = document.createElement('menuitem');
menuitem.setAttribute('label','chrome/' + (dirName=="root"?"":dirName) + ' \uFEFF\u811A\u672C\u5168\u90E8\u542F\u7528/\u505C\u7528');
menuitem.setAttribute('oncommand', 'userChromejs.chgDirStat(this.dirName);');
menuitem.setAttribute('onclick','userChromejs.clickDirMenuitem(event)');
menuitem.setAttribute('type', 'checkbox');
menuitem.setAttribute('checked', !userChrome_js.dirDisable[dirName]);
menuitem.dirName = dirName;
menupopup.appendChild(menuitem);
menuseparator = document.createElement('menuseparator');//子文件夹名分割线
menupopup.appendChild(menuseparator);
var flg = false;
for(var i = 0, len = userChrome_js.scripts.length; i < len; i++){
var script = userChrome_js.scripts[i];
if(script.dir != dirName) continue;
flg = true;
menuitem = document.createElement('menuitem');
menuitem.setAttribute('label',script.filename);
menuitem.setAttribute('oncommand','userChromejs.chgScriptStat(this.script.filename);');
menuitem.setAttribute('onclick','userChromejs.clickScriptMenu(event)');
menuitem.setAttribute('type','checkbox');
menuitem.setAttribute('checked',!userChrome_js.scriptDisable[script.filename] );
if(script.description)
menuitem.setAttribute('tooltiptext',script.description);
menuitem.script = script;
menupopup.appendChild(menuitem);
}
for(var i = 0, len = userChrome_js.overlays.length; i < len; i++){
var script = userChrome_js.overlays[i];
if(script.dir != dirName) continue;
if(flg){
menuseparator = document.createElement('menuseparator');
menupopup.appendChild(menuseparator);
}
flg = false;
menuitem = document.createElement('menuitem');
menuitem.setAttribute('label',script.filename);
menuitem.setAttribute('oncommand','userChromejs.chgScriptStat(this.script.filename);');
menuitem.setAttribute('onclick','userChromejs.clickScriptMenu(event)');
menuitem.setAttribute('type','checkbox');
menuitem.setAttribute('checked',!userChrome_js.scriptDisable[script.filename] );
if(script.description)
menuitem.setAttribute('tooltiptext',script.description);
menuitem.script = script;
menupopup.appendChild(menuitem);
}
menu.appendChild(menupopup);
uc_menupopup = document.getElementById("userChromejs_options");
uc_menupopup.appendChild(menu);
//redo start
var menuApp = document.createElement('menu');
menuApp.setAttribute('label','chrome/' + (dirName=="root"?"":dirName) );
menuApp.setAttribute('onclick','userChromejs.clickDirMenu(event)');
if(userChrome_js.dirDisable[dirName])
menuApp.setAttribute('style', 'font-style:italic;');
menuApp.dirName = dirName;
menupopupApp = document.createElement('menupopup');
menupopupApp.setAttribute('onpopupshowing','event.stopPropagation();');
menuitemApp = document.createElement('menuitem');
menuitemApp.setAttribute('label','chrome/' + (dirName=="root"?"":dirName) + ' \uFEFF\u811A\u672C\u5168\u90E8\u542F\u7528/\u505C\u7528');
menuitemApp.setAttribute('oncommand', 'userChromejs.chgDirStat(this.dirName);');
menuitemApp.setAttribute('onclick','userChromejs.clickDirMenuitem(event)');
menuitemApp.setAttribute('type', 'checkbox');
menuitemApp.setAttribute('checked', !userChrome_js.dirDisable[dirName]);
menuitemApp.dirName = dirName;
menupopupApp.appendChild(menuitemApp);
menuseparatorApp = document.createElement("menuseparator");//子文件夹名分割线
menupopupApp.appendChild(menuseparatorApp);
var flg = false;
for(var i = 0, len = userChrome_js.scripts.length; i < len; i++){
var script = userChrome_js.scripts[i];
if(script.dir != dirName) continue;
flg = true;
menuitemApp = document.createElement('menuitem');
menuitemApp.setAttribute('label',script.filename);
menuitemApp.setAttribute('oncommand','userChromejs.chgScriptStat(this.script.filename);');
menuitemApp.setAttribute('onclick','userChromejs.clickScriptMenu(event)');
menuitemApp.setAttribute('type','checkbox');
menuitemApp.setAttribute('checked',!userChrome_js.scriptDisable[script.filename] );
if(script.description)
menuitemApp.setAttribute('tooltiptext',script.description);
menuitemApp.script = script;
menupopupApp.appendChild(menuitemApp);
}
for(var i = 0, len = userChrome_js.overlays.length; i < len; i++){
var script = userChrome_js.overlays[i];
if(script.dir != dirName) continue;
if(flg){
menuseparatorApp = document.createElement('menuseparator');
menupopupApp.appendChild(menuseparatorApp);
}
flg = false;
menuitemApp = document.createElement('menuitem');
menuitemApp.setAttribute('label',script.filename);
menuitemApp.setAttribute('oncommand','userChromejs.chgScriptStat(this.script.filename);');
menuitemApp.setAttribute('onclick','userChromejs.clickScriptMenu(event)');
menuitemApp.setAttribute('type','checkbox');
menuitemApp.setAttribute('checked',!userChrome_js.scriptDisable[script.filename] );
if(script.description)
menuitemApp.setAttribute('tooltiptext',script.description);
menuitemApp.script = script;
menupopupApp.appendChild(menuitemApp);
}
menuApp.appendChild(menupopupApp);
uc_menupopupApp = document.getElementById("userChromejs_options_appMenu");
uc_menupopupApp.appendChild(menuApp);
//redo over
}
},
//Redo over
clickDirMenu: function(event){
if(event.button == 1 || event.button == 2){
event.stopPropagation();
event.preventDefault();
userChromejs.chgDirStat(event.target.dirName);
if(event.target.firstChild && event.target.firstChild.firstChild)
event.target.firstChild.firstChild.setAttribute('checked',!userChrome_js.dirDisable[event.target.dirName] );
if(!!userChrome_js.dirDisable[event.target.dirName])
event.target.setAttribute('style', 'font-style:italic;');
else
event.target.removeAttribute('style');
}
},
clickDirMenuitem: function(event,stop){
if(event.button == 1 || event.button == 2){
event.stopPropagation();
event.preventDefault();
userChromejs.chgDirStat(event.target.dirName);
event.target.setAttribute('checked',!userChrome_js.dirDisable[event.target.dirName] );
if(!stop && !!userChrome_js.dirDisable[event.target.dirName])
event.target.parentNode.parentNode.setAttribute('style', 'font-style:italic;');
else
event.target.parentNode.parentNode.removeAttribute('style');
}
},
clickScriptMenu: function(event){
if(event.button==1){
event.stopPropagation();
event.preventDefault();
userChromejs.chgScriptStat(event.target.script.filename);
event.target.setAttribute('checked',!userChrome_js.scriptDisable[event.target.script.filename] );
}else if(event.button==2){
event.stopPropagation();
this.launchEditor(event.target.script);
}
},
launchEditor: function(aScript){
var editor = this.editor;
var UI = Components.classes['@mozilla.org/intl/scriptableunicodeconverter'].createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
var platform = window.navigator.platform.toLowerCase();
if(platform.indexOf('win') > -1){
UI.charset = 'GB2312';//Shift_JIS
}else{
UI.charset = 'UTF-8';
}
var path = Components.classes['@mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService).getProtocolHandler('file').QueryInterface(Components.interfaces.nsIFileProtocolHandler).getFileFromURLSpec(aScript.url).path
path = UI.ConvertFromUnicode(path);
var appfile = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
appfile.initWithPath(editor);
var process = Components.classes['@mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess);
process.init(appfile);
process.run(false, [path], 1, {});
},
chgDirStat: function(adirName){
var s = userChromejs.getPref("userChrome.disable.directory", "str", "");
if(!userChrome_js.dirDisable[adirName]){
s = (s+',').replace(adirName+',','') + adirName+',';
}else{
s = (s+',').replace(adirName+',','');
}
s = s.replace(/,,/g,',').replace(/^,/,'');
userChromejs.setPref("userChrome.disable.directory", "str", s);
userChrome_js.dirDisable = this.restoreState(s.split(','));
return userChrome_js.dirDisable;
},
chgScriptStat: function(afilename){
var s = userChromejs.getPref("userChrome.disable.script", "str", "");
if(!userChrome_js.scriptDisable[afilename]){
s = (s+',').replace(afilename+',','') + afilename+',';
}else{
s = (s+',').replace(afilename+',','');
}
s = s.replace(/,,/g,',').replace(/^,/,'');
userChromejs.setPref("userChrome.disable.script", "str", s);
userChrome_js.scriptDisable = this.restoreState(s.split(','));
return userChrome_js.scriptDisable;
},
restoreState: function (arr){
var disable = [];
for(var i = 0,len = arr.length; i < len; i++)
disable[arr[i]] = true;
return disable;
},
//prefを読み込み
getPref: function(aPrefString, aPrefType, aDefault){
var xpPref = Components.classes['@mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefBranch2);
try{
switch (aPrefType){
case 'complex':
return xpPref.getComplexValue(aPrefString, Components.interfaces.nsILocalFile); break;
case 'str':
return unescape(xpPref.getCharPref(aPrefString).toString()); break;
case 'int':
return xpPref.getIntPref(aPrefString); break;
case 'bool':
default:
return xpPref.getBoolPref(aPrefString); break;
}
}catch(e){
}
return aDefault;
},
//prefを書き込み
setPref: function(aPrefString, aPrefType, aValue){
var xpPref = Components.classes['@mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefBranch2);
try{
switch (aPrefType){
case 'complex':
return xpPref.setComplexValue(aPrefString, Components.interfaces.nsILocalFile, aValue); break;
case 'str':
return xpPref.setCharPref(aPrefString, escape(aValue)); break;
case 'int':
aValue = parseInt(aValue);
return xpPref.setIntPref(aPrefString, aValue); break;
case 'bool':
default:
return xpPref.setBoolPref(aPrefString, aValue); break;
}
}catch(e){
}
return null;
},
// 監視を開始する
addPrefListener: function(aObserver) {
try {
var pbi = Components.classes['@mozilla.org/preferences;1']
.getService(Components.interfaces.nsIPrefBranch2);
pbi.addObserver(aObserver.domain, aObserver, false);
} catch(e) {}
},
// 監視を終了する
removePrefListener: function(aObserver) {
try {
var pbi = Components.classes['@mozilla.org/preferences;1']
.getService(Components.interfaces.nsIPrefBranch2);
pbi.removeObserver(aObserver.domain, aObserver);
} catch(e) {}
},
readLaterPrefListener:{
domain : 'userChrome.disable',
//"userChrome.disable"という名前の設定が変更された場合全てで処理を行う
observe : function(aSubject, aTopic, aPrefstring) {
if (aTopic == 'nsPref:changed') {
// 設定が変更された時の処理
setTimeout(function(){
var s = userChromejs.getPref("userChrome.disable.directory", "str", "");
userChrome_js.dirDisable = userChromejs.restoreState(s.split(','));
s = userChromejs.getPref("userChrome.disable.script", "str", "");
userChrome_js.scriptDisable = userChromejs.restoreState(s.split(','));
}, 0);
}
}
},
restartApp: function() {
const appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"]
.getService(Components.interfaces.nsIAppStartup);
// Notify all windows that an application quit has been requested.
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
.createInstance(Components.interfaces.nsISupportsPRBool);
os.notifyObservers(cancelQuit, "quit-application-requested", null);
// Something aborted the quit process.
if (cancelQuit.data)
return;
// Notify all windows that an application quit has been granted.
os.notifyObservers(null, "quit-application-granted", null);
// Enumerate all windows and call shutdown handlers
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var windows = wm.getEnumerator(null);
var win;
while (windows.hasMoreElements()) {
win = windows.getNext();
if (("tryToClose" in win) && !win.tryToClose())
return;
}
let XRE = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime);
if (typeof XRE.invalidateCachesOnRestart == "function")
XRE.invalidateCachesOnRestart();
appStartup.quit(appStartup.eRestart | appStartup.eAttemptQuit);
},
}
userChromejs.init();
//メニューが長くなりすぎるので, あまり使わないメニューを"userChrome.jsの各スクリプトの設定"の下に移動させる
var userChromejsScriptOptionsMenu = {
//あまり使わないメニューのリスト
menues: [
"AutoCopy_settings",//
"GrabScroll_optionsMenu",
"localMark_settings",//
"menutabTooltip",
"Patch_XULrubySupportMenu",
"PipeliningToggle",
"linkInNewTabForSpecifiedPageToolMenu",
"ieviewModokiTool",
"linkloadInBackgroundToolMenu",
"rebuild_userChrome_settings",//
"reload_userchrome_css",//
"reload_usercontent_css",//
"SaveFolderToolsMenu",
"SmartScrollbar_OnOff_switch",//
"UserCSSLoader_settings",//
"WebScreenShotMenu",//
"translation_optionsMenu",//
],
interval: 500, //0.5秒間隔
maxcount: 50, //最大50回までトライ
count: 0,
timer: null,
run: function() {
//DOMの構築が完了するのを待ってからメニューを移動させる(5秒間隔で最大50回までトライ)
this.timer = setInterval(function(self){
if (++self.count > self.maxcount || self.moveMenu())
clearInterval(self.timer);
}, this.interval, this);
},
//用户脚本命令菜单(下拉子菜单)
moveMenu: function(){
var menupopup = document.getElementById('userChromejs_script_options_MenuPopup');//userChromejs_script_options
if (!menupopup)
return false;
var i = 0;
while (i < this.menues.length) {
var menu = document.getElementById(this.menues[i]);
if (menu) {
setTimeout(function(menupopup, menu){menupopup.appendChild(menu);}, 100, menupopup, menu);
this.menues.splice(i, 1);
continue;
}
i++;
}
return this.menues.length == 0 ? true : false
},
}
userChromejsScriptOptionsMenu.run();
// 通过手动更新 toolbar 的 currentSet 特性来添加按钮到 toolbar 里,使得按钮可拖动
var updateToolbar = {
runOnce: function() {
var toolbars = document.querySelectorAll("toolbar");
Array.slice(toolbars).forEach(function (toolbar) {
var currentset = toolbar.getAttribute("currentset");
if (currentset.split(",").indexOf("userChromeJsManagerMenuBtn"/* 按钮 ID */) < 0) return;
toolbar.currentSet = currentset;
try {
BrowserToolboxCustomizeDone(true);
} catch (ex) {
}
});
},
}
updateToolbar.runOnce();
]]></script>
<menupopup id="appmenuPrimaryPane"><!--taskPopup -->
<!--在火狐橙AppMenu上添加UserChromeJs管理菜单-->
<menu label="userChromeJS管理"
id="userChromeJs_Manager_appMenu"
tooltiptext="userChromeJS管理器"
accesskey="u"
class="menu-iconic"
image="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAArUlEQVQ4je3QMQoCMRCF4ddPlRvkBGmEhVRb2W5lueAltvMWlmmFNENO4AkCe4MUHsLS4tmsjWQLF5UVHPiZ7mMY4GfGGENrLZ1zTCl1McY+hDA452itpTGGtwtmWwdYShmf+4N1sGkaeu/Zti0/Am4AbgHuAO4BHgAeRXgS4VmEo8gXwMfpqppV9TrtrKr5HWCeA1NKXa3FYIyxr7UYDCEMtRaDL/+w1jrA1c4do7gmzOLZkZYAAAAASUVORK5CYII="
insertbefore="appmenu_webDeveloper">
<menupopup id="userChromejs_options_appMenu"
onpopupshowing="userChromejs.onpopup();"
context=""><!--用户脚本列表弹出菜单-->
<menuitem label="打开Chrome文件夹"
id="userChromejs_openChromeFolder_appMenu"
tooltiptext="即用户脚本文件夹"
accesskey="h"
class="menuitem-iconic"
oncommand='new Components.Constructor("@mozilla.org/file/local;1","nsILocalFile", "initWithPath")(Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("UChrm", Components.interfaces.nsIFile).path).reveal();'/>
<menuitem label="打开新窗口并重置脚本"
id="userChromejs_rebuild_appMenu"
tooltiptext="仅重新载入选中的脚本"
accesskey="x"
class="menuitem-iconic"
oncommand="userChromejs.rebuild();"/>
<menuitem label="在每个新窗口都重置脚本"
id="userChrome_setting_appMenu"
tooltiptext="仅重新载入选中的脚本"
accesskey="u"
oncommand="userChromejs.setting();"
type="checkbox"/>
<menuitem label="重新启动浏览器"
id="userChromejs_restartApp_appMenu"
accesskey="r"
class="menuitem-iconic"
oncommand="userChromejs.restartApp();"/>
<menuseparator />
</menupopup>
</menu>
</menupopup>
</overlay>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment