TutorDBOps Helper

try to improve TutorDBOps

目前为 2021-09-24 提交的版本。查看 最新版本

// ==UserScript==
// @name         TutorDBOps Helper
// @namespace    http://tpdbops.tutorabc.com/
// @version      0.1
// @description  try to improve TutorDBOps
// @author       Tex
// @match        http://tpdbops.tutorabc.com/mysqlmanage/*
// @icon         https://www.google.com/s2/favicons?domain=tutorabc.com
// @grant        none
// ==/UserScript==

(function() {
    function GM_addStyle(css) {
        const style = document.getElementById("GM_addStyleBy8626") || (function() {
            const style = document.createElement('style');
            style.type = 'text/css';
            style.id = "GM_addStyleBy8626";
            document.head.appendChild(style);
            return style;
        })();
        const sheet = style.sheet;
        sheet.insertRule(css, (sheet.rules || sheet.cssRules || []).length);
    }

    GM_addStyle(`
      * {
        font-family: Consolas;
        font-weight: bold;
        font-size: 14px;
       }
    `);

    let showLeftArea = true;
    function toggleRightArea () {
        // toggle state
        showLeftArea = !showLeftArea;

        // hide sidebar
        const sidebar = document.querySelector("#container > aside");
        sidebar.style.width = showLeftArea? '230px' : '0px';
        sidebar.style.opacity = showLeftArea? '1' : '0';
        sidebar.style['z-index'] = showLeftArea? 'unset' : '-1';

        //  remove right area margin left
        const rightblock = document.querySelector("#container > section");
        rightblock.style['margin-left'] = showLeftArea ? '230px':'0px';


    }

    function submitSql() {
        const searchBtn = document.getElementById("search");
        searchBtn.click();
    }

    // autofocus sql textarea
    const sqlTextArea = document.querySelector("form > table > tbody > tr > td:nth-child(1) > div > div > textarea");
    sqlTextArea.focus();

    // enroll events
    document.onkeydown = function(e) {
        if(e.code === 'Enter' && e.ctrlKey) {
            submitSql();
        }
        if(e.code === 'KeyB' && e.ctrlKey) {
            toggleRightArea();
        }
    }
})();