PasteAndGo.uc.js を Firefox 3.5 対応 + α
xuldev.org :: userChrome.js scripts の PasteAndGo.uc.js は動作しなかったので修正してみた。
(JavaScript や Firefox の API に関して浅識なため) 乱暴な修正かと思います。間違いやスマートな方法など、ご指摘いただければ幸いです。
動作環境
- Windows XP Home Edition SP3 (x86)
- Firefox 3.5.2
Firefox 3.5 対応版
PasteAndGo.uc.js v1.0.20090810074113 を保存してください。
ソースコード
// ==UserScript== // @name Paste And Go // @namespace http://www.xuldev.org/ // @description Adds 'Paste and Go' menu to the context menu in Location bar. // @include main // @author Gomita // @version 1.0.20090810074113 // @homepage http://www.xuldev.org/misc/ucjs.php // ==/UserScript== // // v1.0.20090810074113 : Firefox 3.5 対応 // document.getElementById("urlbar").addEventListener("popupshowing", function(event) { const eltID = "pasteandgo-menuitem"; var menupopup = event.originalTarget; var refChild = menupopup.getElementsByAttribute("cmd", "cmd_paste")[0]; var canPaste = refChild.getAttribute("disabled") == "true"; var menuitem = document.getElementById(eltID); if (!menuitem) { var pasteAndGo = function(event) { goDoCommand("cmd_paste"); //handleURLBarCommand(event); gURLBar.handleCommand(event); menupopup.hidePopup(); }; menuitem = document.createElement("menuitem"); menuitem.id = eltID; menuitem.setAttribute("label", "Paste and Go"); menuitem.setAttribute("accesskey", "G"); menuitem.addEventListener("command", pasteAndGo, false); menupopup.insertBefore(menuitem, refChild.nextSibling); } menuitem.setAttribute("disabled", canPaste.toString()); }, false);
サーチバーで「貼り付けて移動」するように変更した
そもそも、ロケーションバーで「貼り付けて移動」することが少ないので対象をサーチバーへ変更。
PasteAndGo.uc.js 1.0.20090810074157.ino46 を保存してください。
ソースコード
// ==UserScript== // @name Paste And Go // @namespace http://www.xuldev.org/ // @description Adds 'Paste and Go' menu to the context menu in Search bar. // @include main // @author Gomita // @version 1.0.20090810074157.ino46 // @homepage http://www.xuldev.org/misc/ucjs.php // ==/UserScript== // // v1.0.20090810074157.ino46 : サーチバーで「貼り付けて移動」するように変更 // v1.0.20090810074113 : Firefox 3.5 対応 // document.getElementById("searchbar").addEventListener("popupshowing", function(event) { const eltID = "pasteandgo-menuitem"; var menupopup = event.originalTarget; var refChild = menupopup.getElementsByAttribute("cmd", "cmd_paste")[0]; var canPaste = refChild.getAttribute("disabled") == "true"; var menuitem = document.getElementById(eltID); if (!menuitem) { var pasteAndGo = function(event) { goDoCommand("cmd_paste"); var searchbar = document.getElementById("searchbar"); searchbar.handleSearchCommand(event); menupopup.hidePopup(); }; menuitem = document.createElement("menuitem"); menuitem.id = eltID; menuitem.setAttribute("label", "Paste and Go"); menuitem.setAttribute("accesskey", "G"); menuitem.addEventListener("command", pasteAndGo, false); menupopup.insertBefore(menuitem, refChild.nextSibling); } menuitem.setAttribute("disabled", canPaste.toString()); }, false);
変更点
document.getElementById("urlbar").addEventListener("popupshowing", function(event) {
gURLBar.handleCommand(event);
から
document.getElementById("searchbar").addEventListener("popupshowing", function(event) {
var searchbar = document.getElementById("searchbar"); searchbar.handleSearchCommand(event);
へ変更。