百度AiStudio输出结果隐藏

try to take over the world!

当前为 2020-09-21 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);
    }
})();