shenmo
小狐狸
小狐狸
  • UID33580
  • 注册日期2010-07-30
  • 最后登录2022-12-29
  • 发帖数77
  • 经验68枚
  • 威望0点
  • 贡献值28点
  • 好评度1点
阅读:2407回复:1

求修改uc脚本externalApplications.uc.js

楼主#
更多 发布于:2012-07-08 09:37
这个脚本的作用是加载外部应用程序快捷方式(在菜单栏和状态栏),代码如下:
// ==UserScript==
// @name           externalApplications.uc.js
// @namespace      ithinc#mozine.cn
// @description    External Applications
// @include        main
// @compatibility  Firefox 3.5.x 3.6.x
// @author         ithinc
// @version        20091216.1.0.0 Final release
// @version        20091215.0.0.2 Handle toolbar apps and menu apps separately
// @version        20091212.0.0.1 Initial release
// ==/UserScript==

/* :::: External Applications :::: */

var gExternalApplications = {
  toolbar: {
    apps: [
      //{name: 'Notepad', path: '/WINDOWS/system32/notepad.exe'},
      {name: 'Calculator', path: 'C:\\WINDOWS\\system32\\calc.exe'},
	  {name: 'freegate', path: 'F:\\360download\\fg709a.exe'},
	  //{name: 'separator'},
	  {name: 'Internet Explorer', path: 'C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE', args: ['%u']},
      //{name: 'Command Prompt', path: 'C:\\WINDOWS\\system32\\cmd.exe'},
    ],
    insertafter: 'status-bar'  //'menubar-items' or 'home-button'
  },

  menu: {
    apps: [
      //{name: 'Notepad', path: '/WINDOWS/system32/notepad.exe'},
      {name: 'Calculator', path: 'C:\\WINDOWS\\system32\\calc.exe'},
      //{name: 'Command Prompt', path: 'C:\\WINDOWS\\system32\\cmd.exe'},
      //{name: 'separator'},
      //{name: 'UltraEdit', path: 'C:\\Program Files\\IDM Computer Solutions\\UltraEdit-32\\uedit32.exe'},
      //{name: 'Total Commander', path: 'U:\\Programs\\Total Commander\\TOTALCMD.EXE'},
      //{name: 'separator'},
	  //{name: 'My Computer', path: 'c:\\windows\\explorer.exe'},/*x为系统盘符*/
      {name: 'Internet Explorer', path: 'C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE', args: ['%u']},//外部浏览器打开当前页,使用参数%u
     // {name: 'Maxthon', path: 'C:\\Program Files\\Maxthon\\Maxthon.exe', args: ['%u']},
     // {name: 'Namoroka', path: 'D:\\Program Files\\Namoroka3.6b5pre\\firefox.exe', args: ['-no-remote', '-P blank']},
     // {name: 'separator'},
      //{name: 'Profile', path: 'C:\\Documents and Settings\\linus\\Application Data\\Mozilla\\Firefox\\Profiles\\c4r67s72.default'},
    ],
    insertafter: 'tools-menu', //'helpMenu', 'tools-menu' or 'browserToolsSeparator'
    label: 'ExtApps',
    accesskey: 'A'
  },

  init: function() {
    this.handleRelativePath(this.toolbar.apps);
    this.handleRelativePath(this.menu.apps);

    if (this.toolbar.apps.length > 0) {
      var refNode = document.getElementById(this.toolbar.insertafter);
      if (refNode) {
        refNode.parentNode.insertBefore(this.createToolbaritem(this.toolbar.apps), refNode.nextSibling);
      }
    }

    if (this.menu.apps.length > 0) {
      var refNode = document.getElementById(this.menu.insertafter);
      if (refNode) {
        var menu = refNode.parentNode.insertBefore(document.createElement('menu'), refNode.nextSibling);
        menu.setAttribute('label', this.menu.label);
        menu.setAttribute('accesskey', this.menu.accesskey);
        menu.appendChild(this.createMenupopup(this.menu.apps));
      }
    }
  },

  handleRelativePath: function(apps) {
    for (var i=0; i<apps.length; i++) {
      if (apps[i].path) {
        apps[i].path = apps[i].path.replace(/\//g, '\\');

        var ffdir = Cc['@mozilla.org/file/directory_service;1'].getService(Ci.nsIProperties).get('CurProcD', Ci.nsIFile).path;
        if (/^(\.)/.test(apps[i].path)) {
          apps[i].path = ffdir + '\\' + apps[i].path;
        }
        else if (/^(\\)/.test(apps[i].path)) {
          apps[i].path = ffdir.substr(0,2) + apps[i].path;
        }
      }
    }
  },

  exec: function(path, args) {
    args = args || [];
    for (var i=0; i<args.length; i++) {
      args[i] = args[i].replace(/%u/g, gBrowser.currentURI.spec);
    }

    var file = Cc['@mozilla.org/file/local;1'].createInstance(Ci.nsILocalFile);
    file.initWithPath(path);
    if (!file.exists()) {
      Cu.reportError('File Not Found: ' + path);
      return;
    }

    if (!file.isExecutable()) {
      file.launch();
    }
    else {
      var process = Cc['@mozilla.org/process/util;1'].createInstance(Ci.nsIProcess);
      process.init(file);
      process.run(false, args, args.length);
    }
  },

  createToolbaritem: function(apps) {
    var toolbaritem = document.createElement('toolbaritem');
    toolbaritem.setAttribute('class', 'chromeclass-toolbar-additional');
    toolbaritem.setAttribute('orient', 'horizontal');

    for (var i=0; i<apps.length; i++) {
      if (apps[i].name == 'separator') {
        toolbaritem.appendChild(document.createElement('toolbarseparator'));
      }
      else {
        var item = toolbaritem.appendChild(document.createElement('toolbarbutton'));
        item.setAttribute('class', 'toolbarbutton-1 chromeclass-toolbar-additional');
        item.setAttribute('label', apps[i].name);
        item.setAttribute('image', 'moz-icon:file://' + apps[i].path + '?size=16;');
        item.setAttribute('oncommand', 'gExternalApplications.exec(this.path, this.args);');
        item.setAttribute('tooltiptext', apps[i].name);
		item.setAttribute('style','margin: 0px -4px;background: none;box-shadow: none;border-color: transparent;'); //dawlen add
        item.path = apps[i].path;
        item.args = apps[i].args;
      }
    }
    return toolbaritem;
  },

  createMenupopup: function(apps) {
    var menupopup = document.createElement('menupopup');
    for (var i=0; i<apps.length; i++) {
      if (apps[i].name == 'separator') {
        menupopup.appendChild(document.createElement('menuseparator'));
      }
      else {
        var item = menupopup.appendChild(document.createElement('menuitem'));
        item.setAttribute('class', 'menuitem-iconic');
        item.setAttribute('label', apps[i].name);
        item.setAttribute('image', 'moz-icon:file://' + apps[i].path + '?size=16');
        item.setAttribute('oncommand', 'gExternalApplications.exec(this.path, this.args);');
        item.path = apps[i].path;
        item.args = apps[i].args;
      }
    }
    return menupopup;
  }
};
gExternalApplications.init();

现在用这个脚本有个问题,就是每次点击状态栏的ie图标时打开的网址都是第一次点击ie图标图标时的那个网页的网址,比如说:我现在的标签页是新浪,然后我点击状态栏的ie图标,就在ie里打开了新浪;然后我在火狐里打开了另外一个标签页腾讯,再次点击状态栏的ie图标,结果ie打开的是新浪而不是腾讯
这个问题只出现在点击状态栏的图标时,而点击菜单栏的ExtApps菜单就不会有这个问题
本人是代码小白,曾尝试将菜单栏的ExtApps菜单改为显示到状态栏,书签栏,但是间距太大了,不好看,求路过的高手修改这个脚本!(firefox 14 b11,windows 7)
紫焰蔷薇
火狐狸
火狐狸
  • UID38153
  • 注册日期2012-01-24
  • 最后登录2021-09-04
  • 发帖数221
  • 经验102枚
  • 威望0点
  • 贡献值36点
  • 好评度7点
  • 社区居民
  • 忠实会员
1楼#
发布于:2012-07-08 09:37
LZ想要的效果就是用IE打开当前的网页?这个鼠标手势也可以。
const IE_PATH = "C:\\Program Files\\Internet Explorer\\iexplore.exe";var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);file.initWithPath(IE_PATH);if (!file.exists()) {  alert("File does not exist: " + IE_PATH);  return;}var process  = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);try {  var args = [window.content.location.href];  process.init(file);  process.run(false, args, args.length);}catch (ex) {  alert("Failed to execute: " + IE_PATH);}
游客

返回顶部