界面优化

各种奇奇怪怪的界面优化

当前为 2020-04-06 提交的版本,查看 最新版本

// ==UserScript==
// @name                   界面优化
// @namespace              http://tampermonkey.net/
// @version                1.0.0.6
// @description            各种奇奇怪怪的界面优化
// @author                 YiJie
// @create                 2020-04-05
// @match                  https://www.baidu.com/
// @require                https://code.jquery.com/jquery-1.10.2.min.js
// @require                https://cdn.jsdelivr.net/npm/[email protected]/dist/AIO/notiflix-aio-2.1.2.min.js
// @grant                  GM_setValue
// @grant                  GM_getValue
// @grant                  GM_deleteValue
// ==/UserScript==
(function() {
    'use strict';
    var scriptInfo = {
        "name":"界面优化",
        "description":"各种奇奇怪怪的界面优化",
        "author":"YiJie",
        "create":"2020-04-05",
        "version":"1.0.0.6",
        "greasyforkURL":"https://greasyfork.org/zh-CN/scripts/399630-%E7%99%BE%E5%BA%A6%E7%95%8C%E9%9D%A2%E4%BC%98%E5%8C%96",
    };
    GM.setValue = GM_setValue;
    GM.getValue = GM_getValue;
    GM.deleteValue = GM_deleteValue;
    console.clear();
    console.log("百度界面优化");

     Notiflix.Notify.Init({ closeButton:true,position:"left-top", });
    document.head.appendChild($('<link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">')[0]);

    function cssToObj(css) {
        var regex = /([\w-]*)\s*:\s*([^;]*)/g;
        var match, properties={};
        while(match=regex.exec(css)) properties[match[1]] = match[2].trim();
        return properties;
    }
    function setBackgroundImg(sel){
        var imgSrcList = [
            "https://i.ibb.co/s3JKYMF/000.jpg",
            "https://i.ibb.co/tsb7Cfn/001.jpg",
            "https://i.ibb.co/6sBQw9q/002.jpg",
            "https://i.ibb.co/MP4G8j2/003.jpg",
            "https://i.ibb.co/FWwkmy2/004.jpg",
            "https://i.ibb.co/94SM1Sy/005.jpg",
            "https://i.ibb.co/nQddnNb/006.jpg",
            "https://i.ibb.co/TkF20QS/007.jpg",
            "https://i.ibb.co/hs9z9PJ/008.jpg",
            "https://i.ibb.co/p3tTNpQ/009.jpg",
            "https://i.ibb.co/GM5BvmT/010.jpg",
            "https://i.ibb.co/3mz84QJ/011.jpg",
            "https://i.ibb.co/gjhYqrL/012.jpg",
            "https://i.ibb.co/bvJLyY7/013.jpg",
            "https://i.ibb.co/z8nc4j7/014.jpg",
            "https://i.ibb.co/zJLbp2s/015.jpg",
            "https://i.ibb.co/9GwtCsp/016.jpg",
            "https://i.ibb.co/hs8Xthb/017.jpg",
            "https://i.ibb.co/pKycnJM/018.jpg",
            "https://i.ibb.co/BzbRLRy/4.jpg",
            "https://i.ibb.co/BrktnNc/20190804-163142529-i-OS.jpg",
            "https://i.ibb.co/4Fw8XRs/20190805-010826105-i-OS.jpg",
            "https://i.ibb.co/XDvW1Cd/20190805-010841479-i-OS.jpg",
            "https://i.ibb.co/kBySyBb/20190805-010852315-i-OS.jpg",
            "https://i.ibb.co/7Rw98XB/20190805-010909179-i-OS.jpg",
            "https://i.ibb.co/sP6QZ2t/20191001-075308938-i-OS.jpg",
            "https://i.ibb.co/Lx0BMCP/20191001-075336361-i-OS.jpg",
            "https://i.ibb.co/K6qkSsV/20191001-075342746-i-OS.jpg",
            "https://i.ibb.co/dK6Tmmc/20191001-075348921-i-OS.jpg",
            "https://i.ibb.co/KG9cNm3/20191001-075353062-i-OS.jpg",
            "https://i.ibb.co/TRL1ZHg/20191001-075416392-i-OS.jpg",
            "https://i.ibb.co/b1S1fks/20191001-075427752-i-OS.jpg",
            "https://i.ibb.co/3MnwMth/20191001-075432952-i-OS.jpg",
            "https://i.ibb.co/zJCsBHP/20191001-075438207-i-OS.jpg",
            "https://i.ibb.co/gDm6Fmg/20191001-075445325-i-OS.jpg",
            "https://i.ibb.co/4NL9hFM/20191001-075449837-i-OS.jpg",
            "https://i.ibb.co/dMRVSZd/20191001-075454275-i-OS.jpg",
            "https://i.ibb.co/gzWHrcN/20191001-075458168-i-OS.jpg",
            "https://i.ibb.co/QcmYM8w/20191001-075516346-i-OS.jpg",
            "https://i.ibb.co/bgjBcjJ/20191001-075519978-i-OS.jpg",
            "https://i.ibb.co/yPPtNjL/20191001-075526525-i-OS.jpg",
            "https://i.ibb.co/Rvw8nV4/20191001-075538057-i-OS.jpg",
            "https://i.ibb.co/9g2wKSc/20191001-075604237-i-OS.jpg",
            "https://i.ibb.co/qMhSDQS/20191007-031751146-i-OS.jpg",
            "https://i.ibb.co/wS5BVbM/20191007-032041427-i-OS.jpg",
            "https://i.ibb.co/Sr0fKnp/20191007-032113652-i-OS.jpg",
            "https://i.ibb.co/vL6K108/0.png",
            "https://i.ibb.co/Ht8zfxm/1.jpg",
            "https://i.ibb.co/LSKh5bR/2.png",
            "https://i.ibb.co/JHyVVdB/3.jpg",
            "https://i.ibb.co/Nr0KmNW/4.jpg",
            "https://i.ibb.co/WkCmDcg/5.png",
            "https://i.ibb.co/g63VKV7/6.png",
            "https://i.ibb.co/PMtQPxq/7.png",
            "https://i.ibb.co/PzsCpzs/8.jpg",
            "https://i.ibb.co/CVPTd9J/9.png",
            "https://i.ibb.co/bRvfsmk/10.png",
            "https://i.ibb.co/dGwmykP/11.png",
            "https://i.ibb.co/thrKwq5/12.png",
            "https://i.ibb.co/9GDJbkK/13.jpg",
            "https://i.ibb.co/M1NxHsP/14.jpg",
            "https://i.ibb.co/34n7VqV/15.jpg",
            "https://i.ibb.co/nLWpdrv/16.jpg",
            "https://i.ibb.co/qY6s8c5/17.png",
            "https://i.ibb.co/PFnLqHk/18.png",
            "https://i.ibb.co/rwTft2F/19.jpg",
            "https://i.ibb.co/Pwh0rKJ/20.jpg",
            "https://i.ibb.co/KWDFVDW/21.jpg",
            "https://i.ibb.co/3hBR9Sz/22.png",
            "https://i.ibb.co/fYR4sVb/23.jpg",
            "https://i.ibb.co/Nys5S5x/24.png",
            "https://i.ibb.co/NL7D7hK/25.png",
            "https://i.ibb.co/pR3sHst/26.png",
            "https://i.ibb.co/wS26Y1R/27.jpg",
            "https://i.ibb.co/FYhK1L2/28.png",
            "https://i.ibb.co/Wv39ZCq/29.png",
            "https://i.ibb.co/k1D1T06/30.jpg",
            "https://i.ibb.co/ZKnb0zF/31.png",
        ];
        if(sel==-1) sel = Math.round(Math.random()*imgSrcList.length);
        let img=new Image();
        img.src=imgSrcList[sel];
        img.onload=function(){
            $('#head').css({
                "background-position": "center",
                "background-color": "black",
                "background-size": "100%",
                "background-repeat": "repeat-y",
                "background-image":"url('"+imgSrcList[sel]+"')",
                "transition":"1s",
            });
            setTimeout(function(){
                $('#head').css({
                    "background-color": "white",
                });
            },1000);
        };
        GM.setValue("backImgSelect",sel);
    }
    function initView(){
    // 删除不必要的部分
        $('html').css(cssToObj("overflow:hidden;"));
        $('#su').css(cssToObj("display: none;"));
        $('div#u1').css(cssToObj("display: none;"));
        $('div#bottom_layer.s-bottom-layer').css(cssToObj("display: none;"));
        $('div#qrcodeCon').css(cssToObj("display: none;"));
        $('div#s_top_wrap').css(cssToObj("display: none;"));
        $('div#s_upfunc_menus').css(cssToObj("display: none;"));
        $('div#u_sp').css(cssToObj("display: none;"));
    // 设置自定义的logo
        $('#lg').css(cssToObj("display: none;"));
        $('body').append("\
        <div id='logoTitle' class='title'>\
            <span style='color: rgb(50, 100, 200);'>B</span>\
            <span style='color: rgb(70, 120, 220);'>a</span>\
            <span style='color: rgb(90, 140, 240);'>i</span>\
            <span style='color: rgb(50, 100, 200);'>d</span>\
            <span style='color: rgb(90, 140, 240);'>u</span>\
        </div>");
        $('#logoTitle').css(cssToObj("\
            position: fixed;\
            top: 230px;\
            width: 100%;height: 100%;\
            color:black;\
            font-size: 80px;\
            font-weight: 600;\
            user-select: none;\
            text-align: center;\
            line-height: 300px;\
        "));
    // 搜索框样式
        $('#form .s_ipt_wr').css(cssToObj("\
            position: fixed;\
            top: calc(50% - 21px);left: calc(50% - 300px);\
            width: 600px;\
            border: 2px solid white;\
            border-radius: 30px;\
            overflow: hidden;\
            transition: 1s;\
        ")).hover(function(){
            $(this).css(cssToObj("\
                border-radius: 4px;\
                box-shadow: 0 0 20px white;\
            "));
        },function(){
            $(this).css(cssToObj("\
                border-radius: 30px;\
                box-shadow: 0 0 0 white;\
            "));
        });
        $('#form .s_ipt_wr input')
            .css(cssToObj("padding-left: 20px;color: white;over: white;border: none;background-color: rgba(0,0,0,0);transition: .5s;border: none;"))
            [0].oninput = function(){
    // 搜索框下方提示
            setTimeout(function(){
                $('#fm .bdsug').css(cssToObj("left: 40px;top: 175px;width: 560px;"));
                $('#form .bdsug').css(cssToObj("left: 40px;top: 175px;width: 560px;"));
            },100);
        };

        var selectNode = $("\
            <div class='selectNode'>\
                <i class='fa fa-refresh fa-3x'></i>\
                <div class='selectNode-nav'></div>\
            </div>\
        ").css(cssToObj("\
            position: fixed;\
            bottom: 20px;left: -25px;\
            width: 50px;height: 50px;\
            border-radius: 50%;\
            background-image: linear-gradient( 135deg, #3C8CE7 30%, #00EAFF 100%);\
            box-shadow: 0 0 30px white;\
            transition: .5s;\
        ")).hover(function(){
            this.isMouseout = false;
            $(this).css(cssToObj("\
                bottom: 20px;left: 20px;\
                transform: rotateZ(180deg);\
            "));
        },function(){
            var content = this;
            content.isMouseout = true;
            setTimeout(function(){
                if(content.isMouseout) $(content).css(cssToObj("\
                    bottom: 20px;left: -25px;\
                    transform: rotateZ(0deg);\
                "));
            },1000);
        });
        selectNode.find('.fa-refresh').css(cssToObj("\
            width: 100%;\
            color: rgb(250,250,250);\
            font-size: 25px;\
            text-align: center;\
            line-height: 50px;\
        ")).click(function(){
            setBackgroundImg(-1);
        });
        selectNode.find('.selectNode-nav').css(cssToObj("\
            position: absolute;\
            padding-left: 6px;\
            padding-right: 6px;\
            padding-top: 6px;\
            top: 70px;left: calc(50% - 18px);\
            width: 24px;\
        ")).append($("\
            <i title='有关本插件' class='fa fa-info fa-2x'></i>\
            <i title='插件设置' class='fa fa-cog fa-2x'></i>\
            <i title='添加新背景图' class='fa fa-plus fa-2x'></i>\
            <i title='历史记录' class='fa fa-history fa-2x'></i>\
            <i title='分享给好友' class='fa fa-share-alt fa-2x'></i>\
        "));
        selectNode.find('.selectNode-nav').find('i').css(cssToObj("\
            margin-bottom: 16px;\
            width: 24px;\
            text-align: center;\
            color: gray;\
            transform: rotateZ(180deg);\
            transition: .5s;\
        ")).hover(function(){
            $(this).css(cssToObj("\
                color: white;\
            "));
        },function(){
            $(this).css("color","gray");
        });
        document.body.appendChild(selectNode[0]);
        selectNode.find(".fa-info").click(function(){
            Notiflix.Report.Init({ width:"420px",backgroundColor:"#ffffff",svgSize:"50px",titleFontSize:"20px",buttonFontSize:"16px", info: {svgColor:"#0fa1e5",buttonBackground:"#2aa5e8",}, });
            Notiflix.Report.Info( '关于本插件', '追求极简的快乐', '确认' );
            setTimeout(function(){
                $('.notiflix-report-message').html('\
                    <h3>追求极简的快乐</h3>\
                    <h4>插件名:'+scriptInfo.name+'&nbsp;&nbsp;'+scriptInfo.version+'</h4>\
                    <h4>作者:'+scriptInfo.author+'</h4>\
                    <h4>创建时间:'+scriptInfo.create+'</h4>\
                    <h4>greasyfork<a href="'+scriptInfo.greasyforkURL+'">发布地址</a></h4>\
                ');
            },100)
        });

        var thatWord = $("\
            <div class='thatWord'>\
                <div class='thatWord-content'></div>\
                <div class='thatWord-author'></div>\
            </div>\
        ").css(cssToObj("\
            position: fixed;\
            padding: 10px;\
            width: 300px;\
            bottom: 0;right: 0;\
            color: white;\
            user-select: none;\
            font-size: 18px;\
        "));
        thatWord
        .hover(function(){
            var content = this;
            this.copyX = $("<i title='复制文本内容' class='fa fa-copy fa-1x'></i>")
            .click(function(){
                const input = document.createElement('input');
                input.setAttribute('readonly', 'readonly');
                input.setAttribute('value', thatWord.find('.thatWord-content')[0].innerText);
                document.body.appendChild(input);
                input.setSelectionRange(0, 9999);
                input.select();
                if (document.execCommand('copy')) {
                    document.execCommand('copy');
                }
                document.body.removeChild(input);
                Notiflix.Notify.Success('复制成功');
            });
            thatWord.append(this.copyX);
        },function(){
            if(this.copyX){this.copyX.remove();}
        });
        thatWord.find('.thatWord-content').css(cssToObj("width: 100%;float: left;"))[0].innerText = "极致简约,极致设计";
        thatWord.find('.thatWord-author').css(cssToObj("float: right;")).html("—— 一介");
        thatWord.find('.fa-copy').css(cssToObj("position: absolute;top: 10px;right: 10px;"));
        document.body.appendChild(thatWord[0]);
    }

    initView();

//     GM.deleteValue("isFirst");
    if(typeof(GM.getValue("isFirst")) == "undefined"){
        var message = $("\
            <div class='message'>\
                <i class='fa fa-remove fa-1x'></i>\
                <div class='message-content'>点击可切换背景图</div>\
            </div>\
        ").css(cssToObj("\
            position: fixed;\
            top: 88%;left: 70px;\
            padding: 10px;\
            width: 150px;height: 24px;\
            border-radius: 20px 20px 20px 0px;\
            background-color: white;\
            transition: 1s;\
        "));
        message.find('i').css(cssToObj("\
            position: absolute;\
            top: 0px;right: 0px;\
            width: 24px;height: 24px;\
            color: rgb(250,50,50);\
            font-size: 16px;\
            text-align: center;\
            line-height: 24px;\
        ")).click(function(){
            GM.setValue("isFirst",true);
            message.css(cssToObj("opacity: 0;"));
            setTimeout(function(){
                message.remove();
            },1000);
        });
        message.find('.message-content').css(cssToObj("\
            position: absolute;\
            font-size: 16PX;\
        "));
        document.body.appendChild(message[0]);
    }

    if(typeof(GM.getValue("backImgSelect")) == "number"){
        setBackgroundImg(GM.getValue("backImgSelect"));
    }
    else{
        console.log(GM.getValue("backImgSelect"));
        setBackgroundImg(0);
    }
})();