tab tools

some tools

目前為 2024-08-07 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         tab tools
// @name:zh-CN   标签页小工具
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  some tools
// @description:zh-cn    会用到的
// @author       onionycs
// @run-at       document-start
// @match *://*/*
// @grant        GM_registerMenuCommand
// @require      http://code.jquery.com/jquery-3.x-git.min.js
// ==/UserScript==


(function() {
    'use strict';

    GM_registerMenuCommand("Remove - title", removeName);
    GM_registerMenuCommand("faker", faker);
    GM_registerMenuCommand("adjustSSPNOTE", adjustSSPNOTE);
    GM_registerMenuCommand("adjustSVISVI", adjustSVISVI);


    function removeName() {
        var head = document.getElementsByTagName('head')[0];

        // 获取所有<title>标签
        var titles = head.getElementsByTagName('title');

        // 遍历<title>标签并删除
        for (var i = 0; i < titles.length; i++) {
            head.removeChild(titles[i]);
        }
    }

    function adjustSSPNOTE() {
        var $ = unsafeWindow.jQuery;
        console.log("start");
        $('div[role="combobox"]')[0].click();
        var id=$('div[role="combobox"]')[0].id+'-option-2';
        setTimeout(function() {
            // 这里写你希望延迟执行的代码
            console.log('执行了延迟300ms的代码');
            $('#'+id)[0].click();
        }, 300);
        document.getElementsByClassName("left-content")[0].style.width = "40%";
        document.getElementsByClassName("right-content")[0].style.width = "60%";
        console.log("end");
    }

    function adjustSVISVI(){
        document.getElementsByClassName("editor")[0].style.marginLeft="200px"
        document.getElementsByClassName("editor")[0].style.width="1080px"
        document.getElementsByClassName("editor")[0].style.maxWidth="1080px"
    }

    function faker() {
        // 假设新的favicon图标URL是'new-favicon.ico'
        var newFaviconUrl = 'https://img-ys011.didistatic.com/static/cooper_cn/ico-dbook.png';
        //var newFaviconUrl = 'file:///users/didi/downloads/wiki.ico';


        // 创建一个新的<link>元素
        var link = document.createElement('link');
        link.type = 'image/x-icon';
        link.rel = 'icon';
        link.href = newFaviconUrl;

        // 查找旧的favicon链接(如果有的话),并移除它
        // 注意:这里我们假设只有一个favicon链接,或者我们只关心第一个
        // 查找并删除所有rel="shortcut icon"的link元素
        var links = document.querySelectorAll('link[rel="shortcut icon"]');
        links.forEach(function(link) {
            link.remove();
        });
        // 查找并删除所有rel="shortcut icon"的link元素
        links= document.querySelectorAll('link[rel="icon"]');
        links.forEach(function(link) {
            link.remove();
        });

        // 将新的<link>元素添加到<head>部分
        var head = document.head || document.getElementsByTagName('head')[0];
        head.appendChild(link);

        // 注意:在有些情况下,浏览器可能不会立即显示新的favicon
        // 这取决于浏览器的缓存策略和实现细节

        removeName();
        var myhead = document.head || document.getElementsByTagName('head')[0];
        var title = document.createElement('title');
        title.textContent='知识库 - Cooper';
        myhead.appendChild(title);
    }

    function replaceTextInNode(node, regex, replacement) {
            if (node.nodeType === 3) { // Node.TEXT_NODE
                node.textContent = node.textContent.replace(regex, replacement);
            } else if (node.nodeType === 1) { // Node.ELEMENT_NODE
                Array.from(node.childNodes).forEach(child => {
                    replaceTextInNode(child, regex, replacement);
                });
            }
        }

})();