百度文库-精简&优化

删除主页广告、邀请、垃圾内容

// ==UserScript==
// @icon         https://tva1.sinaimg.cn/large/008i3skNgy1gssioj9haig3040040glg.gif
// @name         百度文库-精简&优化
// @namespace    wenku.taozhiyu.gitee.io
// @version      0.3.19
// @description  删除主页广告、邀请、垃圾内容
// @author       涛之雨
// @home-url	 https://greasyfork.org/zh-CN/scripts/422847
// @match        *://wenku.baidu.com/*
// @grant	     GM_addStyle
// @grant	     unsafeWindow
// @license      GPL-3.0-only
// @run-at       document-start
// ==/UserScript==
/**********************************************\
 * V 0.3.19
 * 唔,鸽了好久,终于抽空修复了文本复制的问题
 * 顺便把图标的直链改成了不限速的新浪图床。。。
 * 本来打算做免VIP查看全部文章的来着,结果网页更新了,bug消失了,还好还没做φ(〃'▽'〃)
 * V 0.3.18
 * 自己做了一个比较好看的图标(复制的问题预计下次有空就可以解决了)
 * 添加“自动阅读”的vip判定(非VIP不可继续阅读按钮)
 * V 0.3.17
 * 修复“继续阅读”按钮误删操作
 * V 0.3.16
 * 修复拦截弹窗
 * V 0.3.15
 * 修复自动弹出购买页的bug
 * 暂时未解决VIP复制的问题
 * V 0.3.14
 * 解!锁!免!VIP!复!制!(似乎又是全网最优雅的解锁复制方案)
 * 规范化插件命名空间(如果重复安装请手动删除旧版本)
 * 移除“滚屏”按钮(感觉没必要了。。。因为解锁复制了)
 * 修复ctrl+p无内容(解锁vip了)
 * V 0.3.13
 * 新增屏蔽“兴趣”弹窗
 * V 0.3.12
 * 新增“自动滚屏”按钮(位于右下角)(主要用于ctrl+p渲染页面使用)
 * 点击后自动滚屏,再次点击后停止滚屏
 * 滚动过程中:向上滚动页面,滚动暂停;向下滚动则会继续滚动
 * 新增页面对打印的优化(包括移除防止打印、删除顶部栏、缩放界面等)
 * 修复了一个未识别到的广告
 * V 0.3.11
 * 新增对于【工具箱】引导的拦截
 * V 0.3.10
 * 添加对新版开屏弹窗的支持
 * V 0.3.9
 * 修复新弹窗未屏蔽的bug
 * V 0.3.8
 * 修复新弹窗未屏蔽的bug
 * 修复部分页面广告、logo未删除的bug,等
 * V 0.3.7
 * 移除文件页的水印
 * 对文库搜索页添加适配
 * 首页banner广告改为固定图片
 * 移除首页bd恰饭内容(推荐,限时降价,VIP推荐等)
 * 修改脚本运行的时机,以减少延时感
 * V 0.3.6
 * 因仅word支持背景色,暂时移除
 * V 0.3.5
 * 添加背景色
 * V 0.3.4
 * 删除文章尾部版权说明
 * V 0.3.3
 * 版本号错乱,强制升级
 * V 0.3.2
 * 修复按钮判断逻辑错误!
 * V 0.3.1
 * 修复不能自动展开文章的bug
 * 添加未登录的逻辑算法
 * 新增对于屏蔽登录框配置的保存
 * 新增点击【登陆】按钮还原的算法
 * V 0.2.2
 * 添加GPL-3.0-only协议
 * V 0.2.1
 * 锁定隐藏首页“邀请好友”banner
 * 实现免VIP全屏阅读
 * 全局滚动条美化
 * 修改文库页面的图标
 * 重构去除广告代码
 * 屏蔽文章末尾的结束提示(因为会遮盖部分界面)
 * 自动加载全部页面
 * 移除主题按钮
 * V 0.1.1
 * 初版,删除精简大部分垃圾、广告等
 * TODO : 实现免VIP全屏阅读
 * TODO : 免VIP复制等
\************************************************/
//旧版图标https://edu-wenku.bdimg.com/v1/na/0807/%E6%96%87%E5%BA%93APPicon-1603434254133.png
(function() {
    'use strict';
    const w=unsafeWindow||window;
    const saveInfo=(a)=>{
        localStorage.setItem("taozhiyuWKBeautify", JSON.stringify(a));
    };
    const getInfo=()=>{
        return JSON.parse(localStorage.getItem("taozhiyuWKBeautify"));
    };
    let isautorun=false,step=100,timer=30,windowY=0;
    let info=(getInfo()&&Object.keys(getInfo()).length>0)?getInfo():{"noLogin":0};

    function checkmodule(argument) {
        var moduleJson = {
            "(": ")",
            "[": "]",
            "{": "}",
            "\'": "\'",
            "\"": "\""
        };
        var testStr = argument;
        var tempSaveArray = testStr.replace(/\\./g, "").match(/['"\[\]\(\)\{\}]/g);
        if (tempSaveArray.length !== 0) {
            var isdan = false;
            var isshuang = false;
            for (var j = 0; j < tempSaveArray.length; j < 0 ? j = 0 : j++) {
                if (j > 0 && moduleJson[tempSaveArray[j - 1]] !== undefined && moduleJson[tempSaveArray[j - 1]] == tempSaveArray[j]) {
                    tempSaveArray.splice(j - 1, 2);
                    j -= 2;
                    isdan = false;
                    isshuang = false;
                    continue;
                }
                if (isdan || isshuang) {
                    var ischanged = false;
                    if (isdan) {
                        tempSaveArray.splice(j, 1);
                        if (tempSaveArray[j] === "\'") {
                            isdan = false;
                        }
                        ischanged = true;
                    }
                    if (isshuang) {
                        tempSaveArray.splice(j, 1);
                        if (tempSaveArray[j] === "\"") {
                            isshuang = false;
                        }
                        ischanged = true;
                    }
                    if (ischanged) {
                        j--;
                        continue;
                    }
                } else if (tempSaveArray[j] == "\"") {
                    isshuang = true;
                } else if (tempSaveArray[j] == "\'") {
                    isdan = true;
                }
            }
            if (tempSaveArray.length) {
                return false;
            } else {
                return true;
            }
        } else {
            return true;
        }
    }

    function retmatchtimes(i, endchar) {
        var txt = "([^" + endchar + "]*" + endchar + "){" + String(i) + "}";
        return txt;
    }

    function getFullFunctions(argument, exp, endchar = "\\}") {
        var matchingtimes = 0;
        try {
            var ret = "";
            while (matchingtimes <= 1000) {
                matchingtimes++;
                var tmp = argument.match(new RegExp(exp + retmatchtimes(matchingtimes, endchar), "gm"));
                if (tmp === null) break;
                if (checkmodule(tmp[0])) {
                    ret = tmp[0];
                    break;
                }
            }
            return ret;
        } catch (e) {
            console.log(e);
            return "";
        }
    }
    (w.webpackJsonp=[]).tao=w.webpackJsonp.push;
    w.webpackJsonp.push = (a) => {
        for (var x in a[1]) {
            var e = a[1][x].toString();
            if (e.match(/canCopy\s*:/)) {
                debugger
                var b = getFullFunctions(e, "canCopy\\s*:\\s*function\\s*\\([^\\)]+\\)\\s*\\{"),
                d = e.match(/function\s*\(([^,]+),([^,]+),([^)]+)\)/);
                e = e.replace(b, "canCopy:(t)=>true");//劫持复制
                a[1][x] = new Function(d[1], d[2], d[3], e.substring(e.indexOf("{") + 1, e.length - 1));
                break;
            }
        }
        w.webpackJsonp.tao(a);
    };
    const changeFavicon = link => {
        let $favicon = document.querySelector('link[rel="shortcut icon"]');
        let $favicon1 = document.querySelector('link[rel="icon"]');
        $favicon?$favicon.href = link:"";
        $favicon1?$favicon1.href = link:"";
        if(!($favicon||$favicon1)){
            $favicon = document.createElement("link");
            $favicon.rel = "icon";
            $favicon.href = link;
            document.head.appendChild($favicon);
        }
    };
    setTimeout(()=>{
        w.pageData&&w.pageData.vipInfo&&(w.pageData.vipInfo.global_vip_status=2);
        //修改logo
        changeFavicon("https://tva1.sinaimg.cn/large/008i3skNgy1gssioj9haig3040040glg.gif");
    },1000);

    const killLogin=(iskill=true)=>{
        if(iskill){
            GM_addStyle(`
.涛之雨劫持登录style,
.pop-mask,
.tang-foreground,
.left-login,
.tang-background,
#passport-login-pop{
display:none!important
width:0!important;
overflow:hidden!important;
z-index:-99999!important;
}`);
            document.querySelector(".user-icon-wrap").onclick=(a)=>{
                killLogin(false);
            };
        }else{
            info.noLogin=0;
            saveInfo(info);
            var s=document.getElementsByTagName('style');
            for(var e=0; e<s.length;e++){
                if(s[e].innerHTML.indexOf("涛之雨劫持登录style")>=0){
                    s[e].remove();
                }
            }
        }
    };
    //.vip-layer-inner,
    //.pay-layer1509-wrapper,
    // [class*=pay-]{
    // display:none!important;
    // width:0!important;
    // overflow:hidden!important;
    // }
    GM_addStyle(`.bottom-pop-wrap,
.experience-card-wrap,
.experience-card-dialog-wrap,
.experience-card-bar-wrap,
.doc-price-voucher-wrap,
.experience-card-content,
.vip-member-pop-content,
.copyright-wrap,
.edit-subscription-dialog-wrapper.mod,
.cover-img-ie8,
.user-guide-mask,
.opening-season-dialog,
[class*=pay-],
.vip-wrapper,
.client-wrapper,
.privilege-merging-dialog-wrap,
.notice-info-wrap,
.dialog-wraper,
.active-dialog-wrapper,
.client-download-wrap,
.product,
.red-text.bold-text,
#fengchaoad,
.tousu,
.new-vip-card-position,
.top-recommend-dsp-ad,
.woniu-wrap,
.topicBox,
.search-topicBox-wrap,
.author-organizition-wrapper,
.search-aside-adWrap,
#mywenku,
.doc-pack-wrapper,
.vip-content-wrapper,
.promotion-wrapper,
.user-card-wrapper,
.slide-wrapper,
.bg-wrapper,
.slide-circle-wrapper,
.operate-wrapper,
.voucher-pop-tip,
.theme-wap,
.experience-card-wrap,
.convert-btn-point,
.try-end-fold-page,
.bottom-pop-wrap,
.pure-guide-dialog,
.vip-card-wrap,
.vip-pop-wrap,
.inner-vip,
.vip-pop-wrap,
.inner-vip,
.hx-bottom-wrapper,
.hx-recom-wrapper,
.qr-wrapper,
.feedback-wrapper,
.hx-right-wrapper.sider-edge,
.app-btn,
.hx-warp,
.client-btn-wrap,
.relative-doc-ad-wrapper,
.red-point,
.tips,
.ex-wrapper,
.vip-activity-wrap-new,
.bz-doc-tool-dialog-fix,
.fixed-activity-bar,
.hx-warp,
.operation-wrapper,
.reader-page > div:nth-last-child(1),
.ppt-page-item > div:nth-last-child(1),
.doc-tool-dialog-wrapper{
display:none!important;
width:0!important;
overflow:hidden!important;
}
/*:last-of-type:nth-last-child(1)*/

.header-wrapper{
background-repeat: no-repeat;
background-position: 50% 0;
background-size: cover;
height: 100%;
background-image: url(https://edu-wenku.bdimg.com/v1/pc/2020%E4%BA%8C%E7%BA%A7%E9%A1%B5/%E5%AD%A6%E5%89%8D%E6%95%99%E8%82%B2-1584342432680.png)!important;
}
.product-line-wrap{
float: left;
padding-left: 22px;
}

.red-dot,.red-dot:after{
background-color:unset!important;
}
.small-btn-wrap{
float:unset!important;
}
.bg-items-wrapper{
margin-left:0!important;
}
body{
overflow-y: scroll!important;
}

::-webkit-scrollbar-track{
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
border-radius: 10px;background-color: #F5F5F5;
}

::-webkit-scrollbar{
width: 8px;
height: 8px;
background-color: #F5F5F5;
}

::-webkit-scrollbar-thumb{
border-radius: 10px;
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3);
background-color: #c1c1c1;
}
/*打印屏蔽*/
@media print {
body {display: unset!important}
.reader-topbar,.lazy-load{display:none}
.content-wrapper{padding:0}
/*屏蔽导出脚本*/
.crx_bdwk_down_wrap{display:none}
}

/*滚动按钮*/
.backtop-wrapper #autoroll {
    margin-bottom: 5px;
    width: 40px;
    height: 40px;
    border-radius: 6px;
    border: 1px solid #f5f5f5;
    background-size: 40px 40px;
    background-repeat: no-repeat;
    background-image: url("data:image/gif;base64,R0lGODlhMAAwAHAAACH5BAEAAPwALAAAAAAwADAAhwAAAAAAMwAAZgAAmQAAzAAA/wArAAArMwArZgArmQArzAAr/wBVAABVMwBVZgBVmQBVzABV/wCAAACAMwCAZgCAmQCAzACA/wCqAACqMwCqZgCqmQCqzACq/wDVAADVMwDVZgDVmQDVzADV/wD/AAD/MwD/ZgD/mQD/zAD//zMAADMAMzMAZjMAmTMAzDMA/zMrADMrMzMrZjMrmTMrzDMr/zNVADNVMzNVZjNVmTNVzDNV/zOAADOAMzOAZjOAmTOAzDOA/zOqADOqMzOqZjOqmTOqzDOq/zPVADPVMzPVZjPVmTPVzDPV/zP/ADP/MzP/ZjP/mTP/zDP//2YAAGYAM2YAZmYAmWYAzGYA/2YrAGYrM2YrZmYrmWYrzGYr/2ZVAGZVM2ZVZmZVmWZVzGZV/2aAAGaAM2aAZmaAmWaAzGaA/2aqAGaqM2aqZmaqmWaqzGaq/2bVAGbVM2bVZmbVmWbVzGbV/2b/AGb/M2b/Zmb/mWb/zGb//5kAAJkAM5kAZpkAmZkAzJkA/5krAJkrM5krZpkrmZkrzJkr/5lVAJlVM5lVZplVmZlVzJlV/5mAAJmAM5mAZpmAmZmAzJmA/5mqAJmqM5mqZpmqmZmqzJmq/5nVAJnVM5nVZpnVmZnVzJnV/5n/AJn/M5n/Zpn/mZn/zJn//8wAAMwAM8wAZswAmcwAzMwA/8wrAMwrM8wrZswrmcwrzMwr/8xVAMxVM8xVZsxVmcxVzMxV/8yAAMyAM8yAZsyAmcyAzMyA/8yqAMyqM8yqZsyqmcyqzMyq/8zVAMzVM8zVZszVmczVzMzV/8z/AMz/M8z/Zsz/mcz/zMz///8AAP8AM/8AZv8Amf8AzP8A//8rAP8rM/8rZv8rmf8rzP8r//9VAP9VM/9VZv9Vmf9VzP9V//+AAP+AM/+AZv+Amf+AzP+A//+qAP+qM/+qZv+qmf+qzP+q///VAP/VM//VZv/Vmf/VzP/V////AP//M///Zv//mf//zP///wAAAAAAAAAAAAAAAAjPAPcJHEiwoMGDCBMqXMiwocOHECNKnEixosWLGDNq3MixI0QAAAqC9JhwJEGQIUkaNDkQZUqVLV8KdClTJcuZIVHCxCkypU6YN/ex/Eky6M2gFmsaVbrxqNKaHIku3flzKtWRVq8S5bkTZ9auW4VCBfq0q9mzaNOqXSt2q1OvNGOGRRg35kmfNIe6XPiWq9+/X3vetUu4sFjBdPO+7Gs48N28jcsaPpxYZGTEfykfNHp58GSknzuLzuy5ZU/QSOuWZPp4bOq9bGPLnk27tsaAADs=");
}

.backtop-wrapper #autoroll:hover {
filter: drop-shadow(2px 3px 5px black);
}

.backtop-wrapper #autoroll.btnon {
    background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAXIaVRYdFhNTDpjb20uYWRvYmUueG1wAAAAAAA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA2LjAtYzAwMiA3OS4xNjQ0NjAsIDIwMjAvMDUvMTItMTY6MDQ6MTcgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+IDx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+OqNgrw3l+vc3Lllvv5YKph0Nj5Xcie+gzIjT7PYJeS9vIw+81lQG5E9kJyWZwsUWueDr4/TCD2Zu+VgNDXcjWWECxbgYIHv263oVNvC5tmGmUz3m4TwhGnXEZREtuo9wAAAABJRU5ErkJggg==");
}

`);
    let a=setInterval(()=>{
        let b=document.querySelector(".read-all")
        if(b){
            if(document.querySelector(".fold-no-vip-page-text")===null)b.click();//以后想办法解决这个vip的问题
            clearInterval(a);
        }
//        b=document.querySelector(".btn-know");
//        if(b){
//            b.click();
//        }
    },100);
    let b=setInterval(()=>{
        if(document.querySelector(".no-login")){
            clearInterval(b);
            if(info.noLogin===0){//0未知
                let c=setInterval(()=>{
                    if(!document.querySelector(".pop-mask,#passport-login-pop")){return;}
                    clearInterval(c);
                    if(confirm('是否屏蔽登录窗口?\n本浏览器本网站将一直有效,\n如需[登录]或[清除设置]请\n\n【点击右上角的登陆按钮】')){
                        info.noLogin=1;
                        saveInfo(info);
                        killLogin();
                    }else{
                        info.noLogin=2;
                        saveInfo(info);
                    }
                },100);
            }else if(info.noLogin===1){//屏蔽
                killLogin();
            }
        }
    },100);
    setTimeout(()=>{
        clearInterval(b);
        let d=document.querySelector(".small-btn-wrap");
        if(d){
            const a=document.createElement("span");
            a.innerHTML="【涛之雨】插件解锁复制";
            a.style='color: #666;font-size: 14px;font-family: PingFangSC-Regular;';
            d.append(a);
        }

        document.querySelector("body").addEventListener("copy", a=>{
            try {
                a.clipboardData.setData("text", a.target.value.replace(/\n-{56}\n作者:(.|\n)+/,""));
                a.preventDefault();
            } catch (a) { console.log("去除尾巴失败o(╥﹏╥)o");}
        });
    },2000);

    /*护眼色 > div
#reader-container{
background-color: rgb(199 237 204);
}*/
})();