本帖最后由 Cye3s 于 2009-8-4 05:49 编辑

使用方法(新,扩展版本号>=1.0)
原作者已不再更新,最后一个版本是0.8,其它人接手后更新1.0版本
http://userchromejs.mozdev.org/
使用方法很简单:
找到配置文件夹下的chrome文件夹,找到userChrome.js,结尾写入一行
  1. userChrome.import("*", "UChrm");
复制代码
之后把各独立脚本(*.uc.js,*.uc.xul)放在 "配置文件夹/chrome"下,也就是和userChrome.js放在一起

脚本收集网站
http://zoolcar9.lhukie.net/mozilla/userChromeJS/  (推荐)
http://extensions.geckozone.org/userChrome_js_scripts
http://www.xuldev.org/misc/ucjs.php(作者写了很多好脚本,可惜很多是日语说明,这是英文说明的几个脚本)
http://space.geocities.jp/alice0775/index2.html(脚本非常丰富,不过还是日语说明...)
http://forum.moztw.org/viewtopic.php?p=99969 Moztw上的主题

本论坛一位好心人收集整理的独立脚本,很全,我就省事了,本帖就不再经常更新了,哈
http://board.mozest.com/viewthread.php?tid=26773

mozillazine上的主题
http://forums.mozillazine.org/viewtopic.ph...=15&start=0

JS中如果想增加中文菜单,请先转换成JavaScript escapes格式,再设置到label中.在线转换:
http://people.w3.org/rishida/scripts/uniview/conversion.php

-------------------------------下面内容可以不用看了,过时了------------------------------------------------
使用方法(旧,扩展版本号<=0.8):
1.先安装扩展(只有3K)
http://forums.mozillazine.org/viewtopic.php?t=556229
http://mozilla.zeniko.ch/userchrome.js.xpi
作者主页:http://mozilla.zeniko.ch/userchrome.js.html

2.编辑%配置文件夹\%chrome\userChrome.js,加入网上找到的userChrome.js代码,保存,重启Firefox,生效

或使用下面的方法,方便维护:
用下面的userChrome.js文件替换原  %配置文件夹%\chrome  下同名文件

用于加载   %配置文件夹%\chrome  目录下的所有*.uc.js与*.uc.xul
实现不同功能的代码分别保存成独立uc.js脚本,名字任意,但扩展名必需是uc.js.
要禁用某个脚本只要改扩展名或移动到子目录中,如:%配置文件夹%\chrome\Disabled

例如我机子上的结构为:
  1. %Profiles%CHROME
  2.   │  TheWorld.uc.js
  3.   │  toggleFindbar.uc.js
  4.   │  stayopenmenu.uc.xul
  5.   │  userChrome.css
  6.   │  userChrome.js
  7.   └─Disable
  8.           00hideTitleBar.uc.js
  9.           CopyTitle.uc.js
  10.           hidemenubar.uc.js
复制代码
已知Bug:如果有使用.uc.xul,会造成.uc.js中修改界面的代码失效(如调整工具栏图标大小,隐藏菜单),功能代码正常.


2008-03-02更新:
另外一个*.uc.js|*.uc.xul加载脚本:
http://pirlouy42.free.fr/Firefox/userChrome.js/userChrome.js
效率似乎没有上一个高
但它能很好地支持*.uc.xul脚本,不会造成*.uc.js中修改界面代码失效
并且支持以下注释(@include部分指定在哪个窗口生效,这个例子是主窗口,这只是说明文字,不是代码)
  1. <!--
  2.     // ==UserScript==
  3.     // @name           User Agent Switcher Lite
  4.     // @namespace      https://addons.mozilla.org
  5.     // @description    Remove Cookie(s) for Site
  6.     // @include        chrome://browser/content/browser.xul
  7.     // @author         Dwipal
  8.     // @compatibility  Firefox 2.0 3.0
  9.     // @modified       by Alice0775
  10.     // @version        0.3 mod 2007/08/13 10:00
  11.     // ==/UserScript==
  12.     -->
复制代码
[ 本帖最后由 Cye3s 于 2008-11-19 10:02 编辑 ]
附件: 您所在的用户组无法下载或查看附件
我很懒...
2008-12-01:新的通用加强版本,http://mozilla.sociz.com/viewthr ... &extra=page%3D1

一个例子,在右键菜单中加入LaunchIE(可替代IE View),用IE查看当前页面或链接
  1. var LaunchIE = {
  2.     mSchemes: ["file", "ftp", "http", "https"],

  3.     init: function()
  4.     {
  5.         this.mItem = document.createElement("menuitem");
  6.         this.mItem.setAttribute("label", "LaunchIE");
  7.         this.mItem.setAttribute("accesskey", "u");
  8.       
  9.         document.getElementById("contentAreaContextMenu").addEventListener("popupshowing", function() { LaunchIE.onPopupShowing(this); }, false);
  10.     },

  11.     onPopupShowing: function(aPopup)
  12.     {
  13.         aPopup.insertBefore(this.mItem, document.getElementById("context-sep-" + ((gContextMenu.onLink)?"open":"stop")));
  14.         this.mItem.setAttribute("oncommand", "LaunchIE.launch(" + ((gContextMenu.onLink)?"gContextMenu.linkURI":"gBrowser.currentURI") + ");");
  15.         this.mItem.hidden = !gContextMenu.onLink && (gContextMenu.isTextSelected || gContextMenu.onImage || gContextMenu.onTextInput);
  16.         this.mItem.setAttribute("disabled", this.mItem.hidden || !this.isSupported((gContextMenu.onLink)?gContextMenu.linkURI:gBrowser.currentURI));
  17.     },

  18.     launch: function(aURI, aApp)
  19.     {
  20.         if (!this.isSupported(aURI))
  21.         {
  22.             throw new Error("LaunchIE: unsupported URI scheme '" + aURI.scheme + "'!");
  23.         }
  24.       
  25.         var iexplore = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  26.         try
  27.         {
  28.             var regkey = Components.classes["@mozilla.org/windows-registry-key;1"].createInstance(Components.interfaces.nsIWindowsRegKey);
  29.             regkey.open(Components.interfaces.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" + (aApp || "IEXPLORE.EXE"), Components.interfaces.nsIWindowsRegKey.ACCESS_READ);
  30.             iexplore.initWithPath(regkey.readStringValue(""));
  31.             regkey.close();
  32.         }
  33.         catch (ex)
  34.         {
  35.             iexplore.initWithPath((Components.classes["@mozilla.org/process/environment;1"].getService(Components.interfaces.nsIEnvironment).get("PROGRAMFILES") || "C:\\Program Files") + "\\Internet Explorer\\iexplore.exe");
  36.         }
  37.       
  38.         var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
  39.         process.init(iexplore);
  40.         process.run(false, [aURI.spec], 1);
  41.     },

  42.     isSupported: function(aURI)
  43.     {
  44.         return this.mSchemes.indexOf(aURI.scheme) > -1;
  45.     }
  46. };

  47. LaunchIE.init();
复制代码
[ 本帖最后由 Cye3s 于 2008-12-1 10:23 编辑 ]
我很懒...
自己改写的:调用其它浏览器,如TheWorld,并使用中文菜单(中文转换为Unicode)
  1. var LaunchTW = {
  2.     mSchemes: ["file", "ftp", "http", "https"],

  3.     init: function()
  4.     {
  5.         this.mItem = document.createElement("menuitem");
  6.         this.mItem.setAttribute("label", "\u7528TheWorld\u67E5\u770B");
  7.         this.mItem.setAttribute("accesskey", "U");
  8.       
  9.         document.getElementById("contentAreaContextMenu").addEventListener("popupshowing", function() { LaunchTW.onPopupShowing(this); }, false);
  10.     },

  11.     onPopupShowing: function(aPopup)
  12.     {
  13.         aPopup.insertBefore(this.mItem, document.getElementById("context-sep-" + ((gContextMenu.onLink)?"open":"stop")));
  14.         this.mItem.setAttribute("oncommand", "LaunchTW.launch(" + ((gContextMenu.onLink)?"gContextMenu.linkURI":"gBrowser.currentURI") + ");");
  15.         this.mItem.hidden = !gContextMenu.onLink && (gContextMenu.isTextSelected || gContextMenu.onImage || gContextMenu.onTextInput);
  16.         this.mItem.setAttribute("disabled", this.mItem.hidden || !this.isSupported((gContextMenu.onLink)?gContextMenu.linkURI:gBrowser.currentURI));
  17.     },

  18.     launch: function(aURI, aApp)
  19.     {
  20.         if (!this.isSupported(aURI))
  21.         {
  22.             throw new Error("LaunchTW: unsupported URI scheme '" + aURI.scheme + "'!");
  23.         }
  24.       
  25.         var iexplore = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  26.       
  27.         iexplore.initWithPath("D:\\Program Files\\TheWorld\\TheWorld.exe");
  28.         var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
  29.         process.init(iexplore);
  30.         process.run(false, [aURI.spec], 1);
  31.     },

  32.     isSupported: function(aURI)
  33.     {
  34.         return this.mSchemes.indexOf(aURI.scheme) > -1;
  35.     }
  36. };

  37. LaunchTW.init();
复制代码
[ 本帖最后由 Cye3s 于 2008-9-4 08:54 编辑 ]
我很懒...
在标签菜单中增加"粘贴并转到",改自
http://zoolcar9.lhukie.net/mozilla/userChr...ab-and-go.uc.js
只换成中文菜单
如果想在后台加载,修改
var loadInBackground = nsPreferences.getBoolPref(prefString, false);

var loadInBackground = nsPreferences.getBoolPref(prefString, true);
  1. (function() {
  2.   if (typeof pg2_PasteAndGo == "function") return;

  3.   // create menuitem
  4.   var newItem = document.createElement("menuitem");
  5.   newItem.id = "paste-and-go-in-tab";
  6.   newItem.setAttribute("label", "\u7C98\u8D34\u5E76\u8F6C\u5230");
  7.   newItem.setAttribute("oncommand", "this.pasteAndGo();");
  8.   newItem.setAttribute("accesskey", "G");
  9.   newItem.pasteAndGo = function() {
  10.     var prefString = "userChromeJS.PasteAndGoInTab.loadInBackground";
  11.     var loadInBackground = nsPreferences.getBoolPref(prefString, false);
  12.     var tabbrowser = getBrowser();
  13.     var paste = readFromClipboard();
  14.     if (!paste) return;
  15.     if (tabbrowser.mContextTab.localName == 'tabs') {
  16.       tabbrowser.loadOneTab(paste, null, null, null, loadInBackground, true);
  17.     } else {
  18.       tabbrowser.mContextTab.linkedBrowser.loadURI(paste, null, null, true);
  19.       if (!loadInBackground) tabbrowser.selectedTab = tabbrowser.mContextTab;
  20.     }
  21.   }

  22.   // add menuitem to tab context menu
  23.   var tabContext = document.getAnonymousElementByAttribute(
  24.                     gBrowser, "anonid", "tabContextMenu");
  25.   tabContext.insertBefore(newItem, tabContext.firstChild);

  26.   // disable menuitem if there's no text in clipboard
  27.   tabContext.addEventListener("popupshowing", function(aEvent) {
复制代码
改进版本:判断剪贴板中的内容是不是URL,不是则隐藏菜单(感谢drag&go脚本中的正则式)
  1. /*-----------------------------------------------------
  2.       Paste to Tab and Go

  3.       Add Paste and Go menuitem to tab context menu
  4.       to paste URL from clipboard
  5.       and load it in current tab or a new tab
  6.   -----------------------------------------------------*/

  7. /* ***** BEGIN LICENSE BLOCK *****
  8. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  9. *
  10. * The contents of this file are subject to the Mozilla Public License Version
  11. * 1.1 (the "License"); you may not use this file except in compliance with
  12. * the License. You may obtain a copy of the License at
  13. * http://www.mozilla.org/MPL/
  14. *
  15. * Software distributed under the License is distributed on an "AS IS" basis,
  16. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  17. * for the specific language governing rights and limitations under the
  18. * License.
  19. *
  20. * The Original Code is Paste to Tab and Go script for userChrome.js
  21. *
  22. * The Initial Developer of the Original Code is LouCypher.
  23. * Portions created by the Initial Developer are Copyright (C) 2006
  24. * the Initial Developer. All Rights Reserved.
  25. *
  26. * Contributor(s) (alphabetical order):
  27. *  LouCypher <loucypher.moz@gmail.com>
  28. *
  29. * Alternatively, the contents of this file may be used under the terms of
  30. * either the GNU General Public License Version 2 or later (the "GPL"), or
  31. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  32. * in which case the provisions of the GPL or the LGPL are applicable instead
  33. * of those above. If you wish to allow use of your version of this file only
  34. * under the terms of either the GPL or the LGPL, and not to allow others to
  35. * use your version of this file under the terms of the MPL, indicate your
  36. * decision by deleting the provisions above and replace them with the notice
  37. * and other provisions required by the GPL or the LGPL. If you do not delete
  38. * the provisions above, a recipient may use your version of this file under
  39. * the terms of any one of the MPL, the GPL or the LGPL.
  40. *
  41. * ***** END LICENSE BLOCK ***** */


  42. (function() {
  43.   if (typeof pg2_PasteAndGo == "function") return;

  44.   // create menuitem
  45.   var newItem = document.createElement("menuitem");
  46.   newItem.id = "paste-and-go-in-tab";
  47.   newItem.setAttribute("label", "\u7C98\u8D34\u5E76\u8F6C\u5230");
  48.   newItem.setAttribute("oncommand", "this.pasteAndGo();");
  49.   newItem.setAttribute("accesskey", "G");
  50.   newItem.pasteAndGo = function() {
  51.     var prefString = "userChromeJS.PasteAndGoInTab.loadInBackground";
  52.     var loadInBackground = nsPreferences.getBoolPref(prefString, false);
  53.     var tabbrowser = getBrowser();
  54.     var paste = readFromClipboard();
  55.     if (!paste) return;
  56.     if (tabbrowser.mContextTab.localName == 'tabs') {
  57.       tabbrowser.loadOneTab(paste, null, null, null, loadInBackground, true);
  58.     } else {
  59.       tabbrowser.mContextTab.linkedBrowser.loadURI(paste, null, null, true);
  60.       if (!loadInBackground) tabbrowser.selectedTab = tabbrowser.mContextTab;
  61.     }
  62.   }

  63.   // add menuitem to tab context menu
  64.   var tabContext = document.getAnonymousElementByAttribute(
  65.                     gBrowser, "anonid", "tabContextMenu");
  66.   tabContext.insertBefore(newItem, tabContext.firstChild);

  67.   // disable menuitem if there's no text in clipboard
  68.   tabContext.addEventListener("popupshowing", function(aEvent) {
  69.     /*var ioService = Components.classes["@mozilla.org/network/io-service;1"]
  70.                       .getService(Components.interfaces.nsIIOService);
  71.     try {
  72.       var pasteURL = ioService.newURI(readFromClipboard(), null, null);
  73.     } catch(ex) {
  74.     }*/
  75.     var pasteURL = readFromClipboard();
  76.     var menuItem = document.getElementById("paste-and-go-in-tab");
  77.     if (pasteURL) menuItem.tooltipText = readFromClipboard();
  78.     //menuItem.setAttribute("disabled", !pasteURL ? true : false);
  79.     menuItem.setAttribute("disabled", !pasteURL ? true : (/^file:\/{3}|^data:.+|^(?!java script:)\S*?(([\w-]\.)+\w{2,7}|localhost([:\/]|$))\S*$/.test(pasteURL) ? false : true));
  80.   }, false);

  81.   var copyTabUrlTMP = document.getElementById("tm-copyTabUrl");
  82.   if (copyTabUrlTMP)
  83.     tabContext.insertBefore(copyTabUrlTMP, newItem.nextSibling);

  84. })();
复制代码
[ 本帖最后由 Cye3s 于 2008-9-4 08:55 编辑 ]
我很懒...
在未载入的图像右键菜单加入"显示图片",强制重新载入图片,从Show Image扩展修改而来,又少装一个扩展,哦耶
3.0已自带这个功能
  1. var showImage = {

  2. showImageInit:function()
  3. {
  4.     this.mItem = document.createElement("menuitem");
  5.     this.mItem.setAttribute("label", "\u91CD\u65B0\u8F7D\u5165\u56FE\u7247");
  6.     this.mItem.setAttribute("accesskey", "L");
  7.   
  8.     document.getElementById( "contentAreaContextMenu" ).addEventListener( "popupshowing", function() { showImage.onPopupShowing(this); }, false );

  9. },

  10. onPopupShowing: function(aPopup)
  11. {
  12.     aPopup.insertBefore(this.mItem, document.getElementById("context-viewimage"));
  13.     this.mItem.setAttribute("oncommand", "showImage.performShowImage(true);");
  14.     this.mItem.hidden = !(gContextMenu.onImage && (!gContextMenu.target.naturalWidth || !gContextMenu.target.complete));
  15.     this.mItem.setAttribute("disabled", this.mItem.hidden);
  16. },

  17. performShowImage:function(reload)
  18. {
  19.     var imgNode = gContextMenu.target;
  20.     var prefService = Components.classes[ "@mozilla.org/preferences-service;1" ]
  21.                                .getService( Components.interfaces.nsIPrefBranch );
  22.     var oriImageBehavior = 0;
  23.     if( prefService.getIntPref( "permissions.default.image") != 0 )
  24.     {
  25.         oriImageBehavior = prefService.getIntPref( "permissions.default.image" );
  26.         prefService.setIntPref( "permissions.default.image", 0 );
  27.     }
  28.     var imgSrc = imgNode.getAttribute( "src" );
  29.     imgNode.setAttribute( "src","" );
  30.     if( reload == true )
  31.     {
  32.         var imgURI = imgNode.currentURI;
  33.         var imageCacheService = Components.classes[ '@mozilla.org/image/cache;1' ]
  34.                                          .getService( Components.interfaces.imgICache );
  35.         imageCacheService.removeEntry( imgURI );
  36.     }
  37.     imgNode.setAttribute( "src", imgSrc );
  38.     if( oriImageBehavior != 0 )
  39.     {
  40.         prefService.setIntPref( "permissions.default.image", oriImageBehavior );
  41.     }
  42.     return;
  43. }

  44. };

  45. showImage.showImageInit();
复制代码
[ 本帖最后由 Cye3s 于 2008-9-4 08:56 编辑 ]
我很懒...
【转换搜索引擎后马上搜索】这段代码的作用于搜索框,如果你搜索框已经有了关键字,此时想切换到另一个搜索引擎搜索的时候。只要转换引擎,转换后马上用你转换后的搜索引擎发起搜索。
  1. (function() {
  2.     var searchbar = document.getElementById("searchbar");
  3.     eval("searchbar.onEnginePopupCommand = "
  4.          + searchbar.onEnginePopupCommand.toString().replace(/}$/,
  5.            "if(this.getAttribute('empty') != 'true' &&\
  6.            this.textbox.value.length)\
  7.            this.textbox.onTextEntered();\
  8.            }")
  9.         );
  10. })();
复制代码
[ 本帖最后由 nettrottist 于 2008-9-21 16:07 编辑 ]
代替Compact Menu
  1. (function() {
  2.   var compact = document.createElement("menu");
  3.   compact.setAttribute("label", "Menu");

  4.   var mPopup = document.createElement("menupopup");

  5.   var menubar = document.getElementById("main-menubar");
  6.   var menus = menubar.childNodes.length;
  7.   for (var i = 0; i < menus; ++i) {
  8.     mPopup.appendChild(menubar.firstChild);
  9.   }

  10.   compact.appendChild(mPopup);
  11.   menubar.appendChild(compact);

  12. })();
复制代码
[ 本帖最后由 Cye3s 于 2008-9-2 16:21 编辑 ]
我很懒...
很好很强大 biggrin.gif

楼主能不能帮我修改下,拖放中右击中断,我知道能拖放到工具栏和esc取消,但是我很不喜欢 sad.gif

就是这个原因我不用dragandgo,谢谢楼主


drag&go


contentAreaDNDObserver.onDragOver = function(aEvent, aFlavour, aDragSession) {

// left click position
if(!this.OverAlready) {
this.StartDragX = aEvent.screenX;
this.StartDragY = aEvent.screenY;
this.OverAlready = true;
}

aEvent.target.setAttribute("dragover", "true");
return (aDragSession.canDrop = true);
};

contentAreaDNDObserver.__preUC_onDrop = contentAreaDNDObserver.onDrop;
contentAreaDNDObserver.onDrop = function(aEvent, aXferData, aDragSession) {


var EndDragX = aEvent.screenX;
var EndDragY = aEvent.screenY;

var direction;
var xStart = contentAreaDNDObserver.StartDragX;
var yStart = contentAreaDNDObserver.StartDragY;
var DistanceX = Math.abs(EndDragX - xStart);
var DistanceY = Math.abs(EndDragY - yStart);
var Geste = false ;
// Chose a tolerance for gesture
var Tolerance = 10;

if( DistanceX > Tolerance || DistanceY > Tolerance)
{
Geste = true;
if (DistanceX > DistanceY)
direction = xStart < EndDragX ? "R" : "L";
else direction = yStart < EndDragY ? "D" : "U";
}

var xferData = aXferData.data.split("\n");
// window.confirm(xferData);

if (Geste == true)
{
var url = (/^\s*(.*?)\s*$/m.test(aXferData.data))?RegExp.$1:null;
if (!url)
{
this.__preUC_onDrop(aEvent, aXferData, aDragSession);
return;
}
// if (/^file:\/{3}(?:.*\/)?(.+\.xpi)$/.test(url)) // local XPI -> install
if (/.*\.xpi$/.test(url)) // local XPI -> install
{
var xpinstallObj = {};
xpinstallObj[RegExp.$1] = url;

for (var i = 1; i < aDragSession.numDropItems; i++)
{ // allow to install several extensions at once
url = this.__UC_getDroppedURL(aDragSession, i);
if (/.*\.xpi$/.test(url))
xpinstallObj[RegExp.$1] = url;
}
InstallTrigger.install(xpinstallObj);
}
// if it's an image
else if(/^\[Image\] /.test(xferData[1]) && !(/^(file\:\/\/\/)/.test(url)) )
{
// window.confirm("image");
if(!aEvent.ctrlKey)
saveURL(url, null, null, false, true);
}
// if it's a link
else if (/^file:\/{3}|^data:.+|^(?!java script:)\S*?(([\w-]\.)+\w{2,7}|localhost([:\/]|$))\S*$/.test(url))
{
// window.confirm("link");
gBrowser.dragDropSecurityCheck(aEvent, aDragSession, url);
var referrer = gBrowser.currentURI;
if (referrer.spec == "about:blank")
loadURI(url, null, null);
else this.__UC_loadInTab(url, aEvent);

for (i = 1; i < aDragSession.numDropItems; i++)
{
url = this.__UC_getDroppedURL(aDragSession, i);
gBrowser.dragDropSecurityCheck(aEvent, aDragSession, url);
gBrowser.addTab(url, referrer);
}
}
else // text string -> web search
{
// window.confirm("text");
// here you can choose URL for each gesture
if (direction=="R" && (aDragSession.sourceDocument) )
openURL = "http://www.google.fr/search?q=";
if (direction=="L" && (aDragSession.sourceDocument) )
openURL = "http://fr.wikipedia.org/wiki/Special:Search?search=";
if (direction=="D" && (aDragSession.sourceDocument) )
openURL = "http://www.wordreference.com/fren/";
if (direction=="U" && (aDragSession.sourceDocument) )
openURL = "http://www.wordreference.com/enfr/";

this.__UC_loadInTab(openURL + encodeURIComponent(url), aEvent);
}
}
aEvent.preventDefault();
contentAreaDNDObserver.OverAlready = false;
};

contentAreaDNDObserver.__preUC_onDragStart = contentAreaDNDObserver.onDragStart;
contentAreaDNDObserver.onDragStart = function(aEvent, aXferData, aDragAction) {

// prevent images of being dragged themselves (drag a link to them instead)

// make sure we're dragging an image
var target = aEvent.originalTarget;
if (!/^img$/i.test(target.localName)) throw new Error(); // fall back to default drag handler

// make sure we've actually got a link to drag
for (var obj = target.parentNode; obj && !/^a$/i.test(obj.localName); obj = obj.parentNode);
var url = ((obj)?obj.href:null) || target.src;
if (!url) throw new Error();

var caption = ((obj)?obj.title:null) || target.title || target.alt || url.replace(/^.*\//, "") || url;
aXferData.data = new TransferData();
// aXferData.data.addDataForFlavour("text/x-moz-url", url + "\n" + caption);
// mark unlinked images as downloadable by onDrop ("[Image] ")
aXferData.data.addDataForFlavour("text/x-moz-url", url + "\n" + ((obj)?"":"[Image] ") + caption);
aXferData.data.addDataForFlavour("text/unicode", url);
aXferData.data.addDataForFlavour("text/html", '<a href="' + url + '">' + caption + '</a>');

var nsIDragService = Components.interfaces.nsIDragService;
aDragAction.action = nsIDragService.DRAGDROP_ACTION_COPY | nsIDragService.DRAGDROP_ACTION_MOVE | nsIDragService.DRAGDROP_ACTION_LINK;


};


contentAreaDNDObserver.__UC_loadInTab = function(aURL, aEvent) {
var newTab = gBrowser.addTab(aURL, gBrowser.currentURI);
// if (gPrefService.getBoolPref("browser.tabs.loadInBackground") != !(aEvent && aEvent.shiftKey))
// {
gBrowser.selectedTab = newTab;
// }
};

contentAreaDNDObserver.__UC_getDroppedURL = function(aDragSession, aIndex) {
try
{
var xfer = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
xfer.addDataFlavor("application/x-moz-file", "nsIFile");
xfer.addDataFlavor("text/x-moz-url");
xfer.addDataFlavor("text/unicode");
aDragSession.getData(xfer, aIndex);

var flavour = {}, data = {}, length = {};
xfer.getAnyTransferData(flavour, data, length);
var xferData = new FlavourData(data.value, length.value, this.getSupportedFlavours().flavourTable[flavour.value]);

return transferUtils.retrieveURLFromData(xferData.data, xferData.flavour.contentType);
}
catch (ex)
{
return null;
}
};

getBrowser().addEventListener("dragover", function(aEvent) { nsDragAndDrop.dragOver(aEvent, contentAreaDNDObserver); }, false);
gBrowser.addEventListener("drop", function(aEvent) { nsDragAndDrop.dragOver(aEvent, contentAreaDNDObserver); }, false);
gBrowser.addEventListener("draggesture", function(aEvent) { nsDragAndDrop.startDrag(aEvent, contentAreaDNDObserver); }, true);
试了下,拖动事件触发函数后,函数内不能接受新的右键点击事件...不知道怎么改...等高手:-(
我很懒...
引用 (Cye3s @ 2007年12月28日 12:06 PM) <{POST_SNAPBACK}>
试了下,拖动事件触发函数后,函数内不能接受新的右键点击事件...不知道怎么改...等高手:-(



可否模拟esc按键,我看了javascript教程,只有使用wsh的 " border="0" alt="sweatingbullets.gif" />
ESC也一样,我不知道怎么在函数里监听新事件:-(正在学习别人的代码

代替鼠标手势All-in-One Gestures的脚本:
http://www.xuldev.org/blog/?p=73
我很懒...
配合DownThemAll!(1.0b3上测试通过)

比如我的下载目录默认为E:\Downloads\ ,本次下载临时改变保存路径为E:\temp,下次下载要手工改回E:\Downloads\ ,命名规则也类似,我经常是忘了改 ,结果下载的东西全乱了.这个脚本在每次调用下载前重置下载目录和命名规则.
  1. var dtaDefault = {
  2.     reset:function(){
  3.         var ps = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
  4.         ps.setCharPref("extensions.dta.directory",'["E:\\\\Downloads\\\\", "E:\\\\Downloads\\\\tmpath\\\\", "E:\\\\"]');
  5.         ps.setCharPref("extensions.dta.renaming",'["*name*.*ext*", "*text*", "*num*_*name*.*ext*", "*url*-*name*.*ext*", "*name* (*text*).*ext*", "*name* (*hh*-*mm*).*ext*"]');
  6.         ps.setBoolPref("extensions.dta.lastqueued",false);
  7.     },
  8.     setMenu:function(menuID){
  9.         document.getElementById(menuID).setAttribute("oncommand", "dtaDefault.reset();"+document.getElementById(menuID).getAttribute("oncommand"));
  10.     },   
  11.     init:function() {
  12.         dtaDefault.setMenu("dta-manager-button");
  13.         dtaDefault.setMenu("dtaToolsManager");
  14.         dtaDefault.setMenu("dtaCtxDTA");
  15.         dtaDefault.setMenu("dtaCtxTDTA");
  16.         dtaDefault.setMenu("dtaCtxSave");
  17.         dtaDefault.setMenu("dtaCtxSaveT");
  18.         dtaDefault.setMenu("dtaToolsDTA");
  19.         dtaDefault.setMenu("dtaToolsTDTA");
  20.         dtaDefault.setMenu("dtaCtxSave-direct");
  21.         dtaDefault.setMenu("dtaCtxSaveT-direct");
  22.         dtaDefault.setMenu("dtaCtxDTA-direct");
  23.         dtaDefault.setMenu("dtaCtxTDTA-direct");
  24.     }
  25. }

  26. dtaDefault.reset();
  27. window.setTimeout(function() {
  28.     dtaDefault.init();
  29. });
复制代码
[ 本帖最后由 Cye3s 于 2008-9-4 08:57 编辑 ]
我很懒...
代替TabMixPlus部分功能,地址栏和书签在新标签(在当前标签右边)中打开
新标签打开(目前只在Firefox 3 Beta3上测试通过,历史栏还不能在新标签中打开):
  1. eval("BrowserLoadURL = " + BrowserLoadURL.toString().replace("e;", "[        DISCUZ_CODE_0        ] if ((gBrowser.currentURI.spec != 'about:blank' || gBrowser.webProgress.isLoadingDocument) && (!aTriggeringEvent.altKey)) { var tab = gBrowser.addTab(); gBrowser.selectedTab = tab; }"));
  2. eval("PlacesController.prototype.openSelectedNodeIn = " + PlacesController.prototype.openSelectedNodeIn.toString().replace('openUILinkIn(node.uri, aWhere);','var tabBrowser = null, browserWindow = getTopWin(); if (browserWindow) tabBrowser = browserWindow.getBrowser(); if (tabBrowser && (tabBrowser.currentURI.spec != "about:blank" || tabBrowser.webProgress.isLoadingDocument) && (!/^j/.test(node.uri) && aWhere == "current")) aWhere = "tab"; [        DISCUZ_CODE_0        ]'));
复制代码
在当前标签右边打开:
  1. /* Open tab right to the current one  */
  2. eval("gBrowser.addTab ="+gBrowser.addTab.toString().replace(
  3. 'if (!blank)',
  4. 'this.moveTabTo(t,this.mCurrentTab._tPos+1);'+
  5. 'if (!blank)'));

  6. eval("gBrowser.moveTabTo = " + gBrowser.moveTabTo.toString().replace("this.mTabContainer.childNodes[i].selected = false;"));
复制代码
[ 本帖最后由 Cye3s 于 2008-9-4 08:58 编辑 ]
我很懒...
有right encoding, autocopy, open text link的代码么?
引用 (我行我速 @ 2008年2月17日 10:36 AM) <{POST_SNAPBACK}>
有right encoding, autocopy, open text link的代码么?

2008-02-28修改:
right encoding原来的xul实现方法太笨,去掉了,见39楼有新代码 " border="0" alt="thumbsup.gif" />
我很懒...