-
-
Save mooz/250007 to your computer and use it in GitHub Desktop.
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); | |
} |
// 拡張機能のアクセスキーも殺す設定 | |
// 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); | |
}); | |
})(); |
// 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); | |
} | |
} | |
}); |
Try new script (kill-access-keys.ks.js) and tell me whether it works correctly or not.
This script kill all access keys on all sites by default and allows you to specify prefer certain site's access keys.
nice, thank you :-)
been testing it a bit, it works great with wikipedia to specify exceptions :-)
非常に便利に使わせていただいております。ありがとうございます。
ところで、この機能をXULで書かれているadd onの画面のaccesskeyにも適応する方法はございますでしょうか?
たとえばエラーコンソール画面やExecute JSというアドオン(http://www.mouseless.de/index.php?/content/view/18/31/)においてもaccesskeyを無効にしたいと考えています。
ウィンドウが開いたときのイベントをリッスンできれば、toolbarbuttonタグのDOMオブジェクトをすべて取得し、accesskey要素をもっていたら消す、とすればいいように思うのですが、どうしたら開いたときのイベントが取得できるかわからず、行き詰っております。
もし解決策がおありでしたらご教示ください。
kill-extension-access-key.ks.js と言うものを作成してみましたので, ご確認下さい.
非常に快適に動作しております。
新規ウィンドウが開かれるたびに設定ファイルがロードされることを利用して、直接実行すればよかったのですね。
迅速な対応まことにありがとうございました。
Sometimes this doesn't work, probably the access keys are added after the function is called, or something.
Is there a way to, by default, just kill all access keys on all sites, and instead have site-specific exceptions for certain keys?
(Actually, seeing as emacs bindings and access keys are so often in conflict, it seems to me like the ideal feature for keysnail would be a more general UI for maintaining site-specific exceptions. Eg. a menu with all the access keys by this site listed, and a simple way of ticking them off for all pages in http://.example.org/)