网易漫画“猜你喜欢”侧边栏自动隐藏

按钮颜色变暗

目前為 2017-04-14 提交的版本,檢視 最新版本

// ==UserScript==
// @name         网易漫画“猜你喜欢”侧边栏自动隐藏
// @namespace    http://github.com/maijz128
// @version      0.2
// @description  按钮颜色变暗
// @author       MaiJZ
// @match        https://manhua.163.com/reader/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    var recommand = document.getElementById('J_BookRecommand');
    var panel_btns = document.getElementsByClassName('panel-btn');
    var btn = document.getElementById('J_RecommandTrigger');

    function show() {
        recommand.style.left = '0px';
    }
    function hide() {
        recommand.style.left = '-132px';
        btn.style.padding = '0px';
        btn.style.color = '#333';
    }
    function isShow() {
        if (recommand) {
            if (recommand.style.left > 0) {
                return true;
            }
        }
        return false;
    }
    function autoHide() {
        setInterval(function () {
            if (isShow) {
                setTimeout(hide, 2000);
            }
        }, 1000);

    }

    var count = 0;
    var inter = setInterval(function () {
        recommand = document.getElementById('J_BookRecommand');
        panel_btns = document.getElementsByClassName('panel-btn');
        btn = document.getElementById('J_RecommandTrigger');



        if (panel_btns) {
            for (var i = 0; i < panel_btns.length; i++) {
                panel_btns[i].style.color = "#333";
                panel_btns[i].style.background = "transparent";
            }
        }


        if (btn) {
            btn.addEventListener('click', function () {
                console.log('click J_RecommandTrigger');
            });
            hide();
            autoHide();

            clearInterval(inter);
        }

        if (count > 100) {
            clearInterval(inter);
        } else {
            count++;
        }
    }, 50);

})();