google搜索v2

google搜索页面修改,增加便条

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         google搜索v2
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  google搜索页面修改,增加便条
// @grant        GM_addStyle
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_xmlhttpRequest
// @icon         https://www.google.com/s2/favicons?sz=64&domain=google.com
// @match        https://www.google.com/search?q=*
// @match        https://www.google.com.hk/search?q=*
// @require      https://code.jquery.com/jquery-3.6.0.min.js
// ==/UserScript==


const dom = {};
dom.query = jQuery.noConflict(true);
dom.query(document).ready(function ($) {
    'use strict';

    const detection_cycle = 500;
    const cycle_callbacks = [];
    const {hostname, pathname} = location;

    function no_display(item) {
        const no_display_css = item + " {display: none;}";
        GM_addStyle(no_display_css);
    }

    function add_search_note(){
        var key=$("[name=q]").val();
        var div = document.getElementById('happy');
        if (div) div.remove();

        GM_xmlhttpRequest({
            method: "GET",
            url: "http://www.funnyai.com/note/mini_fulltext.php?key="+encodeURIComponent(key),
            data: "",
            headers: {
                "Content-Typev": "application/x-www-form-urlencoded"
            },
            onload: function(response) {
                var body=response.responseText;
                var strSplit=body.split("count_record=");
                var count=parseInt(strSplit[1]);
                if (count>0){
                    var height=count*200;
                    if (height>320) height=320;
                    if ($("#happy").length==0){
                        var src="<div id='happy' style='margin:10px;width:95%;height:"+height+"px;border:1px dotted blue;overflow:auto;background-color:black'></div>" ;
                        $( src).insertBefore( $( "#appbar" ) );
                        $("#happy").append("<button id='sidebar-btn'>隐藏</button>");
                        $("#happy").append("<div id='content'></div>");

                        GM_setValue("show_google_note", true);
                        document.querySelector("#sidebar-btn").addEventListener("click", function () {
                            change_sidebar_status("show_google_note");
                        }, true);
                        $("#content").html(body);
                    }
                }
            }
        });
    }

    function change_sidebar_status(key_value) {
        var show_sidebar = GM_getValue(key_value, false);
        if (show_sidebar) {
            GM_setValue(key_value, false);
            $("#sidebar-btn").html("显示");

            $("#content").css("display", "none");
            $("#happy").height(30);
        } else {
            GM_setValue(key_value, true);
            $("#sidebar-btn").html("隐藏");

            $("#content").css("display", "block");
            $("#happy").height(320);
        }
    }

    switch (hostname.split(".")[0]) {  // 搜索
        case "www":
            setTimeout(()=>{
                add_search_note();
            },500);
            break;
    }

    if (!cycle_callbacks.length) {
        return;
    }

    cycle_callbacks.forEach(f => f());
    setInterval(() => cycle_callbacks.forEach(f => f()), detection_cycle);
});