Y.B.'s profilewavewaving's 爬痕PhotosBlogLists Tools Help

Blog


    9/7/2009

    用鼠标手势实现firefox的Paste and Search

    在小众软件上看到 Paste and Go 的FireGestures 脚本(http://www.appinn.com/gestures-firefox-paste-and-go/ ),看着ms挺简单,不过却是很有趣。文章末尾,作者说要是有个 搜索剪贴板内容的功能 就好了。想想ms这功能也蛮有意思。于是搜索了下,执行搜索框的firefox函数。虽然不懂,不过依样画葫芦,居然成功实现了功能。呵呵,脚本非常简单,如下图:
    文本如下:
    var str = readFromClipboard();
    if (!str)
    return;
    BrowserSearch.loadSearch(str, true);
     
    名称和动作全是山寨的。:).
     
    在firefox窗口里,按鼠标右键,向右,向上,再向左,即逆时针半圈 (R U L),就能打开一个页面并搜索剪切板里的内容了。
     
    下边是个高级的多功能版本,参考http://www.xuldev.org/firegestures//feedback.php上的一些例子:
     
    其功能是,如果当前点是链接,那么在新窗口页打开链接,如果是选择文本,(如果未选择,即文本为空,则取剪贴板内内容),若该文本是链接,则在新窗口页打开链接,如果是普通文本,则当作搜索内容进行搜索。不过这里,判断文本链接的正则非常初级,需要改进。
     
    //Open link & Go /Selected & Go or Search/Paste & Go or Search 
    // (1) If you started gesture from a link, do 'Open Link in New Tab'
    var srcNode = FireGestures.sourceNode;
    var linkURL = FireGestures.getLinkURL(srcNode);
    if (linkURL) {
      gBrowser.loadOneTab(linkURL, null, null, null, true, false);
      return;
    }
    // (2) Else if you select nothing, do 'Search for clipboard text'
    var sel = FireGestures.getSelectedText();
    if (sel == "") {
       sel = readFromClipboard();
       if (!sel) return;
    }
    // (3) Else if you select text, do 'Search for Selection'
    if (sel){
      if (sel.match(/^www.|^http:|html?$/)) // rough version, need further improvement
        {var taa = gBrowser.loadOneTab(sel, null, null, null, true, false);
        gBrowser.moveTabTo(taa, ++gBrowser.mCurrentTab._tPos);}
      else
      {BrowserSearch.loadSearch(sel, true);
      return;}
    }
     
     

    Comments (1)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    sun darwinwrote:
    ...上进了啊,现在
    Sept. 8

    Trackbacks

    The trackback URL for this entry is:
    http://wavewaving.spaces.live.com/blog/cns!DF35415F8ED2448D!946.trak
    Weblogs that reference this entry
    • None