Created
December 6, 2009 02:36
-
-
Save mooz/250007 to your computer and use it in GitHub Desktop.
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
| if (KeySnail.windowType === "navigator:browser") | |
| { | |
| const whiteList = [ | |
| // ["URL (RegExp)", ["k", "e", "y"]] | |
| ["http://twitter\.com/", ["f"]], | |
| ["http://wikipedia\.com/", ["j", "o"]] | |
| ]; | |
| window.addEventListener( | |
| "DOMContentLoaded", | |
| function (ev) { | |
| let doc = ev.target; | |
| if (!doc) return; | |
| let inWhiteList = {}; | |
| let siteInfo = whiteList.reduce(function (a, r) (a || (RegExp(r[0]).test(doc.location) ? r : null)), null); | |
| if (siteInfo) | |
| for (let [, c] in Iterator(siteInfo[1])) | |
| inWhiteList[c] = true; | |
| let nodes = doc.evaluate('//*[@accesskey]', doc, null, 7, null); | |
| for (let i = 0; i < nodes.snapshotLength; i++) | |
| { | |
| let node = nodes.snapshotItem(i); | |
| if (inWhiteList[node.getAttribute("accesskey")]) | |
| continue; | |
| let clone = node.cloneNode(true); | |
| clone.removeAttribute('accesskey'); | |
| node.parentNode.replaceChild(clone, node); | |
| } | |
| }, false); | |
| } |
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
| // 拡張機能のアクセスキーも殺す設定 | |
| // URI が分からない場合は, 対象ウィンドウにフォーカスを当ててコマンドを実行し確認. | |
| key.setGlobalKey("C-0", function () { | |
| alert(document.documentURI); | |
| }, "Check document URI"); | |
| (function () { | |
| // 対象とする URI | |
| let URLs = [ | |
| "chrome://global/content/console.xul", | |
| "chrome://executejs/content/executejs/executeJS.xul" | |
| ]; | |
| function killer() { | |
| let nodes = document.evaluate('//*[@accesskey]', document, null, 7, null); | |
| for (let i = 0; i < nodes.snapshotLength; ++i) { | |
| let node = nodes.snapshotItem(i); | |
| let clone = node.cloneNode(true); | |
| clone.removeAttribute('accesskey'); | |
| node.parentNode.replaceChild(clone, node); | |
| } | |
| } | |
| URLs.some(function (uri) { | |
| if (document.documentURI !== uri) | |
| return false; | |
| // naive な方法. addEventListener("load") などが効かないので…… | |
| setTimeout(function () { killer(); }, 300); | |
| }); | |
| })(); |
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
| // original code from Firemacs | |
| hook.setHook( | |
| 'LocationChange', | |
| function (aNsURI) { | |
| if (!aNsURI || !aNsURI.spec) | |
| return; | |
| const wikipediaRegexp = "^http://[a-zA-Z]+\\.wikipedia\\.org/"; | |
| if (aNsURI.spec.match(wikipediaRegexp)) | |
| { | |
| var doc = content.document; | |
| if (doc && !doc.__ksAccesskeyKilled__) | |
| { | |
| doc.addEventListener( | |
| "DOMContentLoaded", | |
| function () { | |
| doc.removeEventListener("DOMContentLoaded", arguments.callee, true); | |
| var nodes = doc.evaluate('//*[@accesskey]', doc, | |
| null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | |
| for (let i = 0; i < nodes.snapshotLength; i++) | |
| { | |
| let node = nodes.snapshotItem(i); | |
| let clone = node.cloneNode(true); | |
| clone.removeAttribute('accesskey'); | |
| node.parentNode.replaceChild(clone, node); | |
| } | |
| doc.__ksAccesskeyKilled__ = true; | |
| }, true); | |
| } | |
| } | |
| }); |
非常に便利に使わせていただいております。ありがとうございます。
ところで、この機能をXULで書かれているadd onの画面のaccesskeyにも適応する方法はございますでしょうか?
たとえばエラーコンソール画面やExecute JSというアドオン(http://www.mouseless.de/index.php?/content/view/18/31/)においてもaccesskeyを無効にしたいと考えています。
ウィンドウが開いたときのイベントをリッスンできれば、toolbarbuttonタグのDOMオブジェクトをすべて取得し、accesskey要素をもっていたら消す、とすればいいように思うのですが、どうしたら開いたときのイベントが取得できるかわからず、行き詰っております。
もし解決策がおありでしたらご教示ください。
Author
kill-extension-access-key.ks.js と言うものを作成してみましたので, ご確認下さい.
非常に快適に動作しております。
新規ウィンドウが開かれるたびに設定ファイルがロードされることを利用して、直接実行すればよかったのですね。
迅速な対応まことにありがとうございました。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
been testing it a bit, it works great with wikipedia to specify exceptions :-)