tab tools

some tools

Från och med 2024-08-02. Se den senaste versionen.

// ==UserScript==
// @name         tab tools
// @name:zh-CN   标签页小工具
// @namespace    http://tampermonkey.net/
// @version      0.4
// @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("adjust", adjust);

    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 adjust() {
        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 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='知识库';
        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);
                });
            }
        }

})();