Greasy Fork

匿名版一键搜图

一键搜图(让盗图狗不再得意,让你不再为祭品信息而烦恼)

目前为 2016-08-28 提交的版本。查看 最新版本

// ==UserScript==
// @name         匿名版一键搜图
// @namespace    http://zhihaofans.com
// @version      0.3.1
// @description  一键搜图(让盗图狗不再得意,让你不再为祭品信息而烦恼)
// @author       zhihaofans
// @match        https://h.nimingban.com/f/*
// @match        https://h.nimingban.com/t/*
// @grant        none
// @note         V0.1:初始版本,只有百度,不带设置功能
// @note         V0.2:加入谷歌、搜狗,在网页顶端有设置可以切换(设置保存在本地浏览器)
// @note         V0.2.1:修复了编辑时编码格式错误导致乱码
// @note         V0.2.2:修复了保存设置失败的BUG
// @note         V0.2.3:修复了BUG
// @note         V0.2.4:修改了谷歌地址
// @note         V0.2.5:加入saucenao搜索引擎
// @note         V0.2.6:加入iqdb搜索引擎
// @note         V0.2.7:加入tineye搜索引擎
// @note         V0.2.8:加入360搜索引擎
// @note         V0.3:优化了代码
// @note         V0.3.1:优化了代码
// ==/UserScript==
var setting_show=0;
$(document).ready(function () {
    setting();
    $("#html_search").hide();
    start();
    $("#html_button_setting").click(function () {
        if(setting_show===0)
        {
            $("#html_search").show();
            setting_show=1;
        }
        else
        {
            $("#html_search").hide();
            setting_show=0;
        }
    });
    $("#html_search").change(function () {
        search_change($("#html_search").val());
    });

});
function setting()
{
    if (localStorage.getItem("setting_search") === undefined)
    {
        localStorage.setItem("setting_search","baidu");
    }
    var nmb_select="<select id=\"html_search\" name=\"html_search\" onchange=\"search_change(this.value)\"><option value=\"baidu\">baidu</option><option value=\"google\">google</option><option value=\"sogou\">sogou</option><option value=\"saucenao\">saucenao</option><option value=\"iqdb\">iqdb</option><option value=\"tineye\">tineye</option><option value=\"360\">360</option></select>";
    var li = "<li><a href=\"javascript:void(0)\" id=\"html_button_setting\">一键搜图</a></li> " + nmb_select;
    $("ul.uk-breadcrumb").append(li);
	$("#html_search option[value='"+localStorage.setting_search+"']").prop("selected",true);
}
function search_change(_search)
{
    localStorage.setItem("setting_search", _search);
    alert("设置完毕("+_search+")\n即将刷新");
    location.reload();
}
function start()
{
    var imgs_num=$("a.h-threads-img-a").length;
    var a_1=1;
	var nmb_search={"sogou":"http://pic.sogou.com/ris?query=","baidu":"http://image.baidu.com/n/pc_search?queryImageUrl=","google":"https://www.google.com/searchbyimage?image_url=","saucenao":"http://saucenao.com/search.php?db=999&url=","iqdb":"http://www.iqdb.org/?url=","tineye":"http://tineye.com/search/?url="};
    for(var a=0;a<imgs_num;a++)
    {
        var nmb_img=$("a.h-threads-img-a:eq("+a+")");
        a_1=a+1;
		if(localStorage.getItem("setting_search","baidu")=="360")
		{
			var nmb_link="<form id=\"_form"+a_1+"\" method=\"post\" action=\"http://st.so.com/stu\" target=\"_blank\" ><input type=\"hidden\" name=\"imgurl\" value=\""+nmb_img.attr("href")+"\" /> <a onclick=\"document.getElementById('_form"+a_1+"').submit();\">(←一键搜图)</a></form>";
		}
		else
		{
			var nmb_link="<a  target=\"_blank\" id=\"one_key_search_image_"+a_1+"\" href=\""+nmb_search[localStorage.setting_search]+nmb_img.attr("href")+"\">(←一键搜图)</a>";
		}
        nmb_img.prop("outerHTML",nmb_img.prop("outerHTML")+nmb_link);
    }
}