百度AiStudio输出结果隐藏

try to take over the world!

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         百度AiStudio输出结果隐藏
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       Birkhoff
// @match        https://aistudio.baidu.com/*.ipynb
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 以下为代码
    window.onload = function() {
        // 脚本变量
        window.birkhoff = {};
        // 循环检测
    	const outputUpdateInterval = setInterval(() => {
    		const outputs = document.getElementsByClassName('cc-output');
            window.birkhoff.outputs = outputs;
    		for (var i in outputs) {
    			const output = outputs[i];
    			if (output.birkhoff_marked) {
    				continue;
    			}
    			// 获取到目标的按钮
    			if (output && output.firstElementChild && output.firstElementChild.firstElementChild) {
	    			const button = output.firstElementChild.firstElementChild;
	    			button.onclick = () => {
	    				if (output.status === 'show' || !output.status) {
	    					output.lastElementChild.style = "display: none";
	    					output.status = 'hidden';
	    				} else {
	    					output.lastElementChild.style = "";
	    					output.status = 'show';
	    				}
	    			};
                    output.style = "border-top: 5px dashed black;";
	    			output.birkhoff_marked = 'marked';
    			}
    		}
    	}, 1000);

        const tags = document.getElementById('tab-notebook').parentElement;
        tags.onclick = () => {
            setTimeout(() => {
                const notebookTag = document.getElementById('tab-notebook');
                if (notebookTag.ariaSelected === 'true') {
                    window.birkhoff.floatButton.style['display'] = '';
                } else {
                    window.birkhoff.floatButton.style['display'] = 'none';
                }
            }, 50);
        };

        const floatButton = document.createElement('button');
        window.birkhoff.floatButton = floatButton;
        floatButton.innerText = '隐藏';
        floatButton.style = 'font-size: 20px; color: black; background-color: deepskyblue; position: absolute; right: 100px; bottom: 100px; height: 60px; width: 60px; border: 1px solid lightgray; border-radius: 50%;';
        floatButton.onclick = () => {
            for (var i in window.birkhoff.outputs) {
                const output = window.birkhoff.outputs[i];
                if (output && output.firstElementChild && output.firstElementChild.firstElementChild) {
                    const button = output.firstElementChild.firstElementChild;
                    if (floatButton.innerText === '隐藏' && (output.status === 'show' || !output.status)) {
                        button.click();
                    } else if (floatButton.innerText === '显示' && output.status === 'hidden') {
                        button.click();
                    }
                }
            }
            floatButton.innerText = floatButton.innerText === '隐藏' ? '显示' : '隐藏';
        };
        document.body.append(floatButton);
    }
})();