-
-
Save danny0838/eb39618471ab82f9b22f27b46b5ac39d to your computer and use it in GitHub Desktop.
Firefox minimal userChromeJS to modify native keyboard shortcuts
This file contains 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
// config-prefs.js - a minimal bootstrap | |
// create in Firefox defaults pref directory - for windows = C:\Program Files\Mozilla Firefox\defaults\pref\ | |
// must also create C:\Program Files\Mozilla Firefox\config.js | |
pref("general.config.filename", "config.js"); | |
pref("general.config.obscure_value", 0); | |
pref("general.config.sandbox_enabled", false); |
This file contains 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
// config.js - a minimal bootstrap | |
// create in Firefox install directory - for windows = C:\Program Files\Mozilla Firefox\ | |
// must also create C:\Program Files\Mozilla Firefox\defaults\pref\config-prefs.js | |
try { | |
let { classes: Cc, interfaces: Ci, manager: Cm } = Components; | |
const {Services} = Components.utils.import('resource://gre/modules/Services.jsm'); | |
function ConfigJS() { Services.obs.addObserver(this, 'chrome-document-global-created', false); } | |
ConfigJS.prototype = { | |
observe: function (aSubject) { aSubject.addEventListener('DOMContentLoaded', this, {once: true}); }, | |
handleEvent: function (aEvent) { | |
let document = aEvent.originalTarget; let window = document.defaultView; let location = window.location; | |
if (/^(chrome:(?!\/\/(global\/content\/commonDialog|browser\/content\/webext-panels)\.x?html)|about:(?!blank))/i.test(location.href)) { | |
if (window._gBrowser) { | |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
const NS_XUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; | |
const mainKeysetElem = document.getElementById("mainKeyset"); | |
// 交換 Ctrl+Shift+O (管理書籤) 和 Ctrl+Shift+B (顯示書籤工具列) | |
let keyManageBookmarks = document.getElementById("manBookmarkKb"); | |
keyManageBookmarks.setAttribute( "key", "B" ); | |
let keyToolbarBookmarks = document.getElementById("viewBookmarksToolbarKb"); | |
keyToolbarBookmarks.setAttribute( "key", "O" ); | |
// 移除 Ctrl+B (開啟書籤側欄) | |
let keySidebarBookmarks = document.getElementById("viewBookmarksSidebarKb"); | |
keySidebarBookmarks.removeAttribute( "key" ); | |
keySidebarBookmarks.removeAttribute( "modifiers" ); | |
// 加入 Ctrl+ALT+S (將側邊欄移至右方) | |
let keySidebarReverse = mainKeysetElem.appendChild(document.createElementNS(NS_XUL, "key")); | |
keySidebarReverse.setAttribute("id", "key_sidebarReverse"); | |
keySidebarReverse.setAttribute("modifiers", "accel,alt"); | |
keySidebarReverse.setAttribute("key", "S"); | |
keySidebarReverse.setAttribute("oncommand", "SidebarUI.reversePosition();"); | |
let menuSidebarReverseElem = document.getElementById('sidebar-reverse-position'); | |
menuSidebarReverseElem.setAttribute("key", "key_sidebarReverse"); | |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
} | |
} | |
} | |
}; | |
if (!Services.appinfo.inSafeMode) { new ConfigJS(); } | |
} catch(ex) {}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment