V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
no13bus
V2EX  ›  分享创造

最近因为谷歌的原因造成了 V2EX 搜索框内搜索内容不成功,自己写了个 chrome 的小插件。目前默认将原来的谷歌搜索换成了 bing 搜索。

  •  1
     
  •   no13bus ·
    no13bus · 2014-06-17 16:21:10 +08:00 · 4272 次点击
    这是一个创建于 3607 天前的主题,其中的信息可能已经有所发展或是发生改变。
    这是插件的下载地址http://pan.baidu.com/s/1jGJZ06U

    当每次打开v2ex的时候 搜索框内搜索文字就变成了使用bing搜索了。之前实验了baidu 360 ,发现bing的效果最好。

    其实原理很简单,就是用jquery把之前的搜索框里面的form的填写的内容提交给bing搜索。
    21 条回复    2014-06-21 09:23:36 +08:00
    Tonni
        1
    Tonni  
       2014-06-17 16:26:08 +08:00
    Chrome新版不是明令禁止安装非Chrome Store里面的扩展了么?前段时间我有个现在U2B的视频脚本被强行禁用了。
    Tonni
        2
    Tonni  
       2014-06-17 16:26:46 +08:00
    “下载”打成“现在”了。。。
    can
        3
    can  
       2014-06-17 16:28:02 +08:00
    打开bing输入site:v2ex.com keyword比插件要合适吧?chrome下一个扩展或者插件一个进程,况且现在正在封杀第三方,这个。。
    no13bus
        4
    no13bus  
    OP
       2014-06-17 16:35:33 +08:00
    @Tonni 是吗?不知道。我是刚开始写chrome插件。以前没写过。
    no13bus
        5
    no13bus  
    OP
       2014-06-17 16:38:54 +08:00
    https://github.com/no13bus/v2exchrome 自己写着玩的。
    确实是你那种方法很快。之前我也这么干的。后来人就懒了。不想重开一个tab打开。以前不知道封杀第三方。这个是我第一次写插件。
    @can
    aa65535
        6
    aa65535  
       2014-06-17 16:50:06 +08:00
    重定义 dispatch 函数就行了。
    ```
    function dispatch() {
    var q = document.getElementById("q");
    if (q.value != "") {
    var url = 'http://cn.bing.com/search?q=site%3Av2ex.com%2Ft%20' + q.value;
    if (navigator.userAgent.indexOf('iPad') > -1 || navigator.userAgent.indexOf('iPhone') > -1 || navigator.userAgent.indexOf('iPhone') > -1) {
    location.href = url;
    } else {
    window.open(url, "_blank");
    }
    return false;
    } else {
    return false;
    }
    }
    ```
    no13bus
        7
    no13bus  
    OP
       2014-06-17 18:20:47 +08:00
    @aa65535 刚开始我也是这么想的,后来觉得还是做到插件里面方便。你的意思是直接在我的那个v2ex.js里面写:
    dispatch();
    function dispatch() {
    var q = document.getElementById("q");
    if (q.value != "") {
    var url = 'http://cn.bing.com/search?q=site%3Av2ex.com%2Ft%20' + q.value;
    if (navigator.userAgent.indexOf('iPad') > -1 || navigator.userAgent.indexOf('iPhone') > -1 || navigator.userAgent.indexOf('iPhone') > -1) {
    location.href = url;
    } else {
    window.open(url, "_blank");
    }
    return false;
    } else {
    return false;
    }
    }
    no13bus
        8
    no13bus  
    OP
       2014-06-17 18:30:54 +08:00
    我的那个现在是能打开bing的搜索结果 但是同时google的界面还是能出来。但是
    $("#Search form").click(function() {
    $("#Search form").removeAttr("onsubmit");
    });
    我在这里是明明把form里面的onsubmit给去掉了。
    pandada8
        9
    pandada8  
       2014-06-17 18:31:59 +08:00
    为什么不做成Userscript.......
    no13bus
        10
    no13bus  
    OP
       2014-06-17 18:32:34 +08:00
    @pandada8 那是什么?
    aa65535
        11
    aa65535  
       2014-06-17 18:40:47 +08:00
    @no13bus 不是,chrome插件是不能访问和修改Web函数的,当然可以修改DOM,曲线解决很简单。
    另外:你这插件用了之后搜索会同时打开google和bing。
    pandada8
        12
    pandada8  
       2014-06-17 18:41:41 +08:00
    Userscripts跨浏览器而且比较轻量不用Chrome多开一个进程也可以规避Google的第三方不允许安装的策略
    虽然本质上和插件差不多
    aa65535
        13
    aa65535  
       2014-06-17 18:46:19 +08:00
    只需要一个js文件 v2ex.js
    ```
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.innerText='if(typeof dispatch==="function"){function dispatch(){var q=document.getElementById("q");if(q.value!=""){var url="http://cn.bing.com/search?q=site%3Av2ex.com%2Ft%20"+q.value;if(navigator.userAgent.indexOf("iPad")>-1||navigator.userAgent.indexOf("iPhone")>-1||navigator.userAgent.indexOf("iPhone")>-1){location.href=url;}else{window.open(url,"_blank");}return false;}else{return false;}}}';
    document.getElementsByTagName('body')[0].appendChild(script);
    ```

    manifest.json
    ```
    "content_scripts": [
    {
    "matches": [
    "*://*.v2ex.com/*",
    "*://v2ex.com/*"
    ],
    "run_at": "document_end",
    "js": ["js/v2ex.js"]
    }
    ]
    ```
    spartak
        14
    spartak  
       2014-06-17 18:47:27 +08:00
    v2ex 官方改一下多好,要不投个票:)
    aa65535
        15
    aa65535  
       2014-06-17 18:52:10 +08:00
    其实做成 Userscripts 是更好的选择。

    // ==UserScript==
    // @name V2ex search
    // @version 1.00
    // @run-at document-end
    // @include *://*.v2ex.com/*
    // @include *://v2ex.com/*
    // ==/UserScript==
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.innerText='if(typeof dispatch==="function"){function dispatch(){var q=document.getElementById("q");if(q.value!=""){var url="http://cn.bing.com/search?q=site%3Av2ex.com%2Ft%20"+q.value;if(navigator.userAgent.indexOf("iPad")>-1||navigator.userAgent.indexOf("iPhone")>-1||navigator.userAgent.indexOf("iPhone")>-1){location.href=url;}else{window.open(url,"_blank");}return false;}else{return false;}}}';
    document.getElementsByTagName('body')[0].appendChild(script);
    yangg
        16
    yangg  
       2014-06-17 20:14:05 +08:00 via Android
    我很好奇ls的插件什么的iPad能安装么?要不那些if是干嘛的
    ChiChou
        17
    ChiChou  
       2014-06-17 21:15:45 +08:00
    现在Chrome不能安装非市场扩展了,只能用开发者模式导入源码,非常蛋疼。
    no13bus
        18
    no13bus  
    OP
       2014-06-17 21:47:14 +08:00
    @ChiChou 趋势。为了安全,咱们看的代码还行,看不懂的给你代码里面放点东西,谁也不知道呀。
    ChiChou
        19
    ChiChou  
       2014-06-18 10:04:17 +08:00
    @no13bus 大陆开发者表示不知道怎么注册 Google 钱包(很多帖子说填账单地址随便找个 HK 的),有应用也没法发布。现在 Google 被艹,更是发布了也没人装了。
    han365
        20
    han365  
       2014-06-21 09:14:52 +08:00 via Android
    不会用啊
    no13bus
        21
    no13bus  
    OP
       2014-06-21 09:23:36 +08:00 via Android
    @han365 下载下来,然后在浏览器里面的插件页面导入文件夹即可
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2191 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 05:36 · PVG 13:36 · LAX 22:36 · JFK 01:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.