[kesai]google搜索选项扩展

增加了快捷设置文件类型过滤搜索和网站过滤搜索

目前为 2019-08-05 提交的版本。查看 最新版本

// ==UserScript==
// @name         [kesai]google搜索选项扩展
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  增加了快捷设置文件类型过滤搜索和网站过滤搜索
// @author       kesai
// @match        https://www.google.com/*
// @match        https://www.google.co.jp/*
// @match        https://www.google.com.hk/*
// @require      https://code.jquery.com/jquery-3.3.1.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    let fileExtArray = ['doc', 'pdf', 'xls', 'ppt', 'rtf', 'kml'];

    function initMenus() {
        initfileType();
        initSiteFilter();
    }


    function initfileType() {
        $(".hdtb-mn-cont").append($('<span class="hQKUmb"></span>'));
        var div = $('<div class="hdtb-mn-hd" aria-haspopup="true" role="button" tabindex="0" aria-label="所有网页和文件"><div class="mn-hd-txt">所有网页和文件</div><span class="mn-dwn-arw"></span></div>');
        $(".hdtb-mn-cont").append(div);
        let ul = $('<ul class="hdtbU hdtb-mn-o" aria-expanded="false" style="display:none;left: 410.977px; top: 25px; min-width: 148px;"><li class="hdtbItm hdtbSel" id="li_" tabindex="0">所有网页和文件(不限格式)</li></ul>');

        var i = 1;
        fileExtArray.forEach(function(fileExt) {
            var id = "li_" + i;
            //debugger;
            var li = $('<li class="hdtbItm" id="' + id + '"><a class="q qs">' + fileExt + '</a></li>');
            ul.append(li)
            i++;
        })

        $(".hdtb-mn-cont").append(ul);
        div.bind("click", function() {
            if (ul.css("display") === "block") ul.css("display", "none");
            else
                ul.css("display", "block")
        });
        var regex = /filetype:[a-zA-Z]{3}/i;
        var isExistFileTypeReg = /filetype:*/i;
        ul.find("li").bind("click", function() {
            var str = $(".gLFyf.gsfi").val();
            var filetype = "filetype:" + $(this).text();
            if (isExistFileTypeReg.test(str)) {
                var regex = /filetype:[a-zA-Z]{1,4}/i;
                if (regex.test(str)) $(".gLFyf.gsfi").val(str.replace(regex, filetype));
            } else {
                $(".gLFyf.gsfi").val($(".gLFyf.gsfi").val() + " " + filetype);
            }
            ul.css("display", "none");
            $(".Tg7LZd").trigger("click");
        });
    }

    function initSiteFilter() {
        $(".hdtb-mn-cont").append($('<span class="hQKUmb"></span>'));
        var div = $('<div class="hdtb-mn-hd" aria-haspopup="true" role="button" tabindex="0" aria-label="站点内检索"><div class="mn-hd-txt">站点内检索</div><span class="mn-dwn-arw"></span></div>');
        $(".hdtb-mn-cont").append(div);

        let ul = $('<ul class="hdtbU hdtb-mn-o" aria-expanded="false" style="display:none;left: 410.977px; top: 25px; min-width: 148px;"><li><input id="input_site" type="txt" autocomplete="off" value="" placeholder="例如:baidu.com"><a id="btn_site_OK">确认</a></li></ul>');
        $(".hdtb-mn-cont").append(ul);

        div.bind("click", function() {
            if (ul.css("display") === "block") ul.css("display", "none");
            else
                ul.css("display", "block")
        });

        $("#btn_site_OK").bind("click", function() {
            var url = $("#input_site").val();
            //没有进行正则表达式的验证
            $(".gLFyf.gsfi").val($(".gLFyf.gsfi").val() + " " + "site:" + url);
            $(".Tg7LZd").trigger("click");
            ul.css("display", "none");
        });
    }



    $(function() {
        //initMenus();
        setTimeout(function() { initMenus(); }, 2000);

    })



})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址