MozTW 討論區 https://forum.moztw.org/ |
|
給 userChrome.js 套件用的實用 script https://forum.moztw.org/viewtopic.php?f=11&t=17813 |
第 1 頁 (共 3 頁) |
發表人: | yuoo2k [ 2007-03-01, 23:06 ] |
文章主題 : | 給 userChrome.js 套件用的實用 script |
userChrome.js - allows to easily customize Firefox through JavaScript. 有些小功能可以用 userChrome.js 這個小套件簡單達成,就不用多花時間特別弄一個套件出來。 |
發表人: | yuoo2k [ 2007-03-01, 23:10 ] |
文章主題 : | 當新增分頁時能自動利用尾端空白分頁 |
代碼: (function() {
//公用函式 function hookCode(orgFunc, orgCode, myCode) { eval(orgFunc + "=" + eval(orgFunc).toString().replace(orgCode, myCode)); } //當新增分頁時能自動利用尾端空白分頁 hookCode("getBrowser().addTab", "return t;", ( function() { if ((aURI != "about:blank") &&(["removeTab","sss_restoreWindow","sss_undoCloseTab"].indexOf(this.addTab.caller.name) == -1) &&(!t.previousSibling.linkedBrowser.webProgress.isLoadingDocument) &&(t.previousSibling.linkedBrowser.currentURI.spec == "about:blank")) { this.removeTab(t.previousSibling); } } ).toString().replace(/^.*{/,"").replace(/.*}$/,"")+"$&"); })(); |
發表人: | yuoo2k [ 2007-03-01, 23:12 ] |
文章主題 : | 巴哈姆特討論區外部鏈結用中鍵點擊可直接開啟 |
代碼: (function() {
//公用函式 function hookCode(orgFunc, orgCode, myCode) { eval(orgFunc + "=" + eval(orgFunc).toString().replace(orgCode, myCode)); } //巴哈姆特外部鏈結用中鍵點擊可直接開啟 hookCode("openNewTabWith", /{/, "{" + ( function() { if (arguments[3] && arguments[3].button == 1) { var m = arguments[0].match(/^javascript:(top\.)?confirmLink\(\s*(\x22|\x27)(.*)(\x22|\x27)\s*\)$/); if (m) arguments[0] = unescape(m[3]); } } ).toString().replace(/^.*{/,"").replace(/.*}$/,"")); })(); |
發表人: | yuoo2k [ 2007-03-01, 23:18 ] |
文章主題 : | 幾個可增強搜尋列操作便利性的功能 |
代碼: var gSearchBox = {
get ref() { return document.getElementById("searchbar"); }, get textbox() { return document.getAnonymousElementByAttribute(this.ref, "class", "searchbar-textbox"); }, get goButton() { return document.getAnonymousElementByAttribute(this.ref, "class", "search-go-button"); }, get engineButton() { return document.getAnonymousElementByAttribute(this.ref, "class", "searchbar-engine-button"); }, get value() { if (this.textbox) return this.textbox.inputField.value; }, set value(v) { if (this.textbox) { this.textbox.focus(); this.textbox.inputField.value = v; var e = document.createEvent("HTMLEvents"); e.initEvent("oninput", true, false); this.textbox.dispatchEvent(e); } } } //使用 滑鼠中鍵 點擊 搜尋欄位 時,可直接 清除目前搜尋欄 的內容。 gSearchBox.textbox.addEventListener("click", function(event) { if (event.button == 1) { gSearchBox.value = ""; } }, false); //使用 滑鼠右鍵 點擊 搜尋按鈕 時,可直接 貼上目前剪貼簿 的內容。 gSearchBox.goButton.addEventListener("click", function(event) { if (event.button == 2) { var data = readFromClipboard(); if (!data) data = ""; data = data.replace(/(^\s*|\s*$)/g, ""); gSearchBox.value = data; event.preventDefault(); } }, false); //使用 滑鼠中鍵 點擊 引擎切換選單 時,可使用該引擎 搜尋目前搜尋欄 的內容。 //使用 滑鼠右鍵 點擊 引擎切換選單 時,可使用該引擎 搜尋目前剪貼簿 的內容。 gSearchBox.engineButton.addEventListener("click", function(event) { if ((event.button == 1)||(event.button == 2)) { var data = gSearchBox.value; if (gSearchBox.ref.getAttribute("empty") == "true") data = ""; if (event.button == 2) { data = readFromClipboard(); if (!data) return; } data = data.replace(/(^\s*|\s*$)/g, ""); var engine = event.originalTarget.engine; var anonid = event.originalTarget.getAttribute("anonid"); if (!engine && anonid != "searchbar-engine-button") return; if (engine) gSearchBox.ref.currentEngine = engine; gSearchBox.value = data; gSearchBox.ref.doSearch(data, true); gSearchBox.ref._popup.hidePopup(); } }, false); |
發表人: | kfly [ 2007-03-02, 11:13 ] |
文章主題 : | |
真的是好东西!收了. |
發表人: | 過路的 [ 2007-03-02, 18:17 ] |
文章主題 : | |
感謝yuoo2k大整理這些好用的功能,真是一大福音,小弟要趕緊來試試。 |
發表人: | yuoo2k [ 2007-03-02, 21:10 ] |
文章主題 : | 用滑鼠中鍵點擊開啟新分頁,短按=背景開啟,長按=前景開啟 |
代碼: (function() {
function hookCode(orgFunc, orgCode, myCode) { try { eval(orgFunc + "=" + eval(orgFunc).toString().replace(orgCode, myCode)); }catch(e){ Components.utils.reportError("Failed to hook function: "+orgFunc); } } function hookProp(parentNode, propName, myGetter, mySetter) { var oGetter = parentNode.__lookupGetter__(propName); var oSetter = parentNode.__lookupSetter__(propName); if (oGetter && myGetter) myGetter = oGetter.toString().replace(/{/, "{"+myGetter.toString().replace(/^.*{/,"").replace(/.*}$/,"")); if (oSetter && mySetter) mySetter = oSetter.toString().replace(/{/, "{"+mySetter.toString().replace(/^.*{/,"").replace(/.*}$/,"")); if (!myGetter) myGetter = oGetter; if (!mySetter) mySetter = oSetter; if (myGetter) try { eval('parentNode.__defineGetter__(propName, '+ myGetter.toString() +');'); }catch(e){ Components.utils.reportError("Failed to hook property Getter: "+propName); } if (mySetter) try { eval('parentNode.__defineSetter__(propName, '+ mySetter.toString() +');'); }catch(e){ Components.utils.reportError("Failed to hook property Setter: "+propName); } } window.addEventListener("mousedown", function(event){ if (event && event.button == 1) { window.clickState = 1; var ms = nsPreferences.getIntPref("mclickfocustab.timeout", 300); setTimeout(function(){ window.clickState = 2; }, ms); } }, true); window.addEventListener("mousemove", function(event){ window.clickState = 0; }, true); hookCode("getBrowser().addTab", /return (\S+);/, "if (window.clickState == 2) { this.selectedTab = $1; } if (window.clickState > 0) { window.clickState = -1; } $&"); hookProp(getBrowser(), "selectedTab", null, function(){ if ((window.clickState < 0) && this.selectedTab) return val; }); })(); |
發表人: | 過路的 [ 2007-03-03, 11:17 ] |
文章主題 : | |
終於連上http://forums.mozillazine.org/viewtopic.php?t=397735 不過安裝了userChrome.js套件,卻不知到要把Script貼在何處 PS:相關的使用資料小弟沒找到,倒是Script看到很多。 |
發表人: | Velociraptor [ 2007-03-03, 12:46 ] |
文章主題 : | |
過路的 寫: 終於連上http://forums.mozillazine.org/viewtopic.php?t=397735
不過安裝了userChrome.js套件,卻不知到要把Script貼在何處 PS:相關的使用資料小弟沒找到,倒是Script看到很多。 放到 userChrome.js 裡面 檔案位置在 profile 底下的 chrome 資料夾 |
發表人: | 過路的 [ 2007-03-03, 14:37 ] |
文章主題 : | |
Velociraptor 寫: 放到 userChrome.js 裡面
檔案位置在 profile 底下的 chrome 資料夾 謝謝Velociraptor大的幫忙,原來是要放在這邊,感謝。 ![]() |
發表人: | yuoo2k [ 2007-03-09, 17:44 ] |
文章主題 : | 鏈結有用target屬性指定目標分頁名稱時,總是在新分頁開啟該鏈結 |
代碼: (function() {
//公用函式 function hookCode(orgFunc, orgCode, myCode) { eval(orgFunc + "=" + eval(orgFunc).toString().replace(orgCode, myCode)); } //鏈結有用target屬性指定目標分頁名稱時,總是在新分頁開啟該鏈結。 hookCode("contentAreaClick", "if (linkNode) {", "$&" + ( function() { if (event.button == 0 && !event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) { var target = linkNode.getAttribute("target"); if (target && !/^(_self|_parent|_top|_content|_main|_blank)$/.test(target.toLowerCase())) { function _existsFrameName(containerFrames, frameName) { for (var i = 0; i < containerFrames.length; i++) { if (containerFrames[i].name == frameName) return true; if (_existsFrameName(containerFrames[i].frames, frameName)) return true; } return false; } if (!_existsFrameName(document.commandDispatcher.focusedWindow.top.frames, target)) { openNewTabWith(linkNode.href, linkNode.ownerDocument.location.href, null, null, false); return false; } } } } ).toString().replace(/^.*{/,"").replace(/.*}$/,"")); })(); |
發表人: | Merci chao [ 2007-03-17, 16:37 ] |
文章主題 : | 使用 Alt 顯示/隱藏選單工具列 |
修正問題: 1. 全螢幕時無效 2. 已隱藏選單會被強制顯示 部份含有 "ori-" 字眼的程式碼只適用於 HideMenubar userChrome.css 代碼: #toolbar-menubar:hover{visibility:visible!important} (解決無法按下選單工具列中其他項目的問題) userChrome.js 代碼: var toolbar = document.getElementById("toolbar-menubar");
toolbar.collapsed = true; toolbar.addEventListener("DOMMenuItemInactive", function(event) { //改為 toolbar-menubar, 遲開自訂工具列問題 var menubar = event.target.parentNode; if (menubar.parentNode.parentNode != this) return; setTimeout( function() { var toolbar = menubar.parentNode.parentNode; if (toolbar.collapsed || toolbar.altKey) return; for (var item=menubar.firstChild; item; item=item.nextSibling) if (item.getAttribute("_moz-menuactive")) return; var attr = ["collapsed", "moz-collapsed"]; for (var i=0; i<2; i++) { if (toolbar.getAttribute("ori-"+attr[i])) { toolbar.setAttribute(attr[i], true); toolbar.removeAttribute("ori-"+attr[i]); } } }, 0, menubar); }, false); window.addEventListener("keydown", function(event){ if ((event.keyCode == 18) && !event.ctrlKey && !event.shiftKey && !event.metaKey) document.getElementById("toolbar-menubar").altKey = true; }, true); window.addEventListener("keyup", function(event) { if ((event.keyCode == 18) && !event.ctrlKey && !event.shiftKey && !event.metaKey) { var toolbar = document.getElementById("toolbar-menubar"); toolbar.altKey = false; var attr = ["collapsed", "moz-collapsed"]; for (var i=0; i<2; i++) { if (toolbar.getAttribute("ori-"+attr[i])) { toolbar.setAttribute(attr[i], true); toolbar.removeAttribute("ori-"+attr[i]); } else { if (toolbar.getAttribute(attr[i]) == "true") toolbar.setAttribute("ori-"+attr[i], true); toolbar.removeAttribute(attr[i]); } } } }, true); window.addEventListener("keypress", function(event) { var menubar = document.getElementById("main-menubar"); var toolbar = menubar.parentNode.parentNode; if (event.altKey && (toolbar.collapsed || toolbar.getAttribute("moz-collapsed")) ) { for (var item=menubar.firstChild; item; item=item.nextSibling) { if ((item.localName == "menu") && (item.getAttribute("accesskey").toLowerCase() == String.fromCharCode(event.charCode)) && !item.getAttribute("hidden")) // 修正能顯示已隱藏選單 { toolbar.altKey = false; var attr = ["collapsed", "moz-collapsed"]; for (var i=0; i<2; i++) { if (toolbar.getAttribute(attr[i]) == "true") toolbar.setAttribute("ori-"+attr[i], true); toolbar.removeAttribute(attr[i]); } item.lastChild.showPopup(); break; } } } }, true); |
發表人: | 1abcd [ 2007-03-17, 17:22 ] |
文章主題 : | |
yuoo2k 寫: userChrome.js - allows to easily customize Firefox through JavaScript. 有些小功能可以用 userChrome.js 這個小套件簡單達成,就不用多花時間特別弄一個套件出來。 Velociraptor 寫: 放到 userChrome.js 裡面 檔案位置在 profile 底下的 chrome 資料夾 Merci chao 寫: 修正問題: 1. 全螢幕時無效
全螢幕可以顯示隱藏的選單了,謝謝各位大大。 |
發表人: | yuoo2k [ 2007-04-02, 11:08 ] |
文章主題 : | 自訂主選單"歷史"下拉清單中顯示的記錄數目 |
代碼: (function() {
//公用函式 function hookCode(orgFunc, orgCode, myCode) { eval(orgFunc + "=" + eval(orgFunc).toString().replace(orgCode, myCode)); } //自訂主選單列"歷史"下拉清單中顯示的記錄數目 (可將下兩行中的 25 改為您欲自訂的顯示數目) hookCode("updateGoMenu", "if (count > 10", "if (count > 25"); hookCode("updateGoMenu", "count = 10;", "count = 25;"); })(); |
發表人: | goldie [ 2007-12-20, 20:00 ] |
文章主題 : | 取代 Tiny Menu (Compact Menu) |
在這裡找到的 from the excellent LouCypher (aka Zoolcar9): http://zoolcar9.lhukie.net/mozilla/userChromeJS/ 該空間裡頭的「compact_menu.uc.js 」 代碼: (function() {
var compact = document.createElement("menu"); compact.setAttribute("label", "Menu"); var mPopup = document.createElement("menupopup"); var menubar = document.getElementById("main-menubar"); var menus = menubar.childNodes.length; for (var i = 0; i < menus; ++i) { mPopup.appendChild(menubar.firstChild); } compact.appendChild(mPopup); menubar.appendChild(compact); })(); |
第 1 頁 (共 3 頁) | 所有顯示的時間為 UTC + 8 小時 |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |