前往
大廳
主題

火狐Firefox UC腳本:ButtonEventListener為工具列圖示增加點擊功能

—— | 2016-12-19 15:28:57 | 巴幣 0 | 人氣 487

除了為重新整理、油猴和Stylish圖示按鈕增加功能,還有為網址列和書籤,詳細功能請看程式碼。
這個腳本讓Stylish火狐版變得跟Chrome版一樣,直接在按鈕的選單裡的樣式列按右鍵彈出編輯視窗(分頁),不用跑到附加管理員裡再選擇要編輯樣式。

// ==UserScript==
// @name           ButtonEventListener.uc.js
// @namespace      runningcheese@qq.com
// @description    為工具列圖示增加點擊功能
// @author         runningcheese
// @version        0.0.1-2016.11.29
// @license        MIT License
// @compatibility  Firefox 29+
// @charset        UTF-8
// @reviewURL      http://www.runningcheese.com/firefox-v6

// ==/UserScript==

if (location == "chrome://browser/content/browser.xul") {


//右鍵  網址列重整圖示 強制重整頁面(跳過快取)
(function () {
var ReloadButton = document.getElementById('urlbar-reload-button');
if (!ReloadButton) return;
ReloadButton.addEventListener("click", function (event) {
if (event.button == 2) {
event.preventDefault();
BrowserReloadSkipCache();
}
}, false);
})();
}

//點擊頁面恢復原來的網址
gBrowser.addEventListener("DOMWindowCreated", function () {
window.content.document.addEventListener("click", function (e) {
document.getElementById("urlbar").handleRevert();
}, false);
}, false);

//當網址列失去焦點後恢復原來的網址
if (location == "chrome://browser/content/browser.xul") {
var ub = document.getElementById("urlbar");
ub.addEventListener("blur", function () {
this.handleRevert();
}, false);
};

/*書籤下拉選單中键不關閉*/(一般在資料夾下選擇一個書籤後就關閉,這個按中鍵即可複選,括弧裡這句不用複製)
eval('BookmarksEventHandler.onClick = ' + BookmarksEventHandler.onClick.toString()
.replace(/if \(node\.localName \=\= \"menupopup"\)\n\s+node\.hidePopup\(\)\;\n\s+else/,''));
eval('checkForMiddleClick = ' + checkForMiddleClick.toString()
.replace('closeMenus(event.target);',''));

//中鍵點擊網址列自動複製網址
document.getElementById('urlbar').addEventListener('click', function(e){
    if(e.button == 1) goDoCommand('cmd_copy');
}, false);

/*GM中鍵切換開關不關閉下拉選單*/
eval('GM_popupClicked = ' + GM_popupClicked.toString()
.replace(/\'command\' \=\= aEvent\.type/,"$& \|\| aEvent\.button \=\= 1")
.replace(/\=\! script\.enabled\;\n/,"$&aEvent.target.setAttribute('checked',script.enabled);\n")
.replace(/closeMenus/,"if(aEvent\.button \!\= 1) $&"));

/*stylish中鍵切換開關不關閉下拉選單和右鍵直接打開編輯*/
eval("stylishOverlay.popupShowing = "+ stylishOverlay.popupShowing.toString()
.replace(/menuitem\.addEventListener.*/,'\
menuitem.addEventListener("click", function(event) {\
if(event.button != 2) {\
stylishOverlay.toggleStyle(this.stylishStyle);\
event.target.setAttribute("checked",this.stylishStyle.enabled);\
event.stopPropagation();\
}else{\
stylishCommon.openEditForStyle(this.stylishStyle);\
closeMenus(this);\
event.preventDefault();\
}\
}, false);'

)
);

創作回應

更多創作