🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

微信读书网页版 plus

修改标题等字体,修改内容字体为苍耳今楷,更改背景/字体颜色,全屏,上划隐藏头部侧栏,自动滚动加速/减速/暂停/继续,代码复制与图片下载

As of 2024-03-11. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         微信读书网页版 plus
// @version      1.0.0
// @license MIT
// @namespace    https://greasyfork.org/zh-CN/users/1272865
// @description  修改标题等字体,修改内容字体为苍耳今楷,更改背景/字体颜色,全屏,上划隐藏头部侧栏,自动滚动加速/减速/暂停/继续,代码复制与图片下载
// @contributor  Li_MIxdown;hubzy;xvusrmqj;LossJ;JackieZheng;das2m;harmonyLife
// @author       brewin
// @match        https://weread.qq.com/web/reader/*
// @require      https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js
// @require      http://cdn.staticfile.org/jquery/1.8.3/jquery.min.js
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// @icon         https://weread.qq.com/favicon.ico
// @grant        GM_log
// @grant        GM_addStyle
// @grant        unsafeWindow
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_openInTab
// @grant        GM_download
// @grant        GM_setClipboard
// @grant        GM_notification
// @downloadURL
// @updateURL
// ==/UserScript==

GM_addStyle("*{font-family: SourceHanSerifCN !important;}");
GM_addStyle(".readerTopBar{font-family: SourceHanSerifCN-Bold !important;}");
GM_addStyle(".bookInfo_title{font-family: SourceHanSerifCN-Bold !important;}");
GM_addStyle(".readerTopBar_title_link{font-family: SourceHanSerifCN-Bold; !important; font-weight:bold !important;}");
GM_addStyle(".readerTopBar_title_chapter{font-family: SourceHanSerifCN-Bold !important;}");
GM_addStyle(".wr_whiteTheme .renderTargetContainer .renderTargetContent .wr_readerImage_opacity {background-color: rgba(216,226,200,80) !important;}");
GM_addStyle(".wr_whiteTheme .renderTargetContainer .renderTargetContent .wr_readerBackground_opacity{background-color: rgba(216,226,200,80) !important;}");
GM_addStyle(".wr_whiteTheme .readerContent .app_content{background-color: rgba(216,226,200,80) !important;}");
GM_addStyle(".readerChapterContent{color: rgba(0,0,0,100) !important;}");
GM_addStyle(".readerControls{margin-left: calc(50% - 200px) !important;}");
GM_addStyle(".readerControls{margin-bottom: -28px !important;}");
//GM_addStyle(".readerChapterContent{font-weight: bold !important;}");

$(window).on('load', async function () {
    'use strict';

    // 基于jQuery检测dom出现
    function jianceDOM(classname){
        return new Promise(res=>{
            let max=80;
            let jiance=setInterval(()=>{
                if(document.querySelectorAll(classname).length){
                    clearInterval(jiance)
                    res(true)
                }
                if(max<=0){
                    clearInterval(jiance)
                    res(false)
                }
                max--
            },100)
            })
    }

    // 检测文章内容发生变化
    $("body").append(`
    <div id="module_box" style="
    position: fixed;
    left:0;
    top:200px;
    bottom:0;
    right:0;
    margin:auto;
    width: 200px;
    height: 100px;
    text-align: center;
    line-height: 100px;
    background-color: rgba(0, 0, 0, 0.3);
    font-size: 24px;
    z-index:999999;
    display:none;">复制成功</div>
    `)


    async function add_copy_code_btn() {
        // 检测代码段是否存在
        let res_dom_code = await jianceDOM("pre")
        let copy_code_btn_length = $("#copy_code").length
        if (res_dom_code && copy_code_btn_length==0) {
            // $("pre").css("position","relative")
            $("pre").append(`
            <button id="copy_code" style="position: absolute;right: 0;top: 0;color:white;cursor:pointer;z-index:99999;">📋</button>
            `)
        }
    }

    add_copy_code_btn()

    // 复制按钮
    $(document).on("click","#copy_code",function(){
        // let code_text = $(this).closest('pre').text().replace("📋","")
        //let code_text = $(this).closest('pre')[0].childNodes[0].textContent
          let code_text = $(this).closest('pre')[0].textContent.replace("📋","")
        GM_setClipboard(code_text)
        $("#module_box").fadeIn()
        setTimeout(() => {
            $("#module_box").fadeOut()
        },1000)
        // GM_notification({text:'复制成功',timeout:0})
    })

    $(document).on("click","button[title='下一章']",function(){
        // console.log("下一章按钮")
        add_copy_code_btn()
        add_copy_img_btn()
    })
    $(document).on("click",".chapterItem",function(){
        add_copy_code_btn()
        add_copy_img_btn()
    })


    async function add_copy_img_btn() {
        let res_dom_img = await jianceDOM('.wr_readerImage_opacity')
        let open_img_btn_length = $("button[name='btn_cxy_open_img_page']").length
        let get_img_btn_length = $("button[name='btn_cxy_get_img']").length
        if (res_dom_img && open_img_btn_length == 0 && get_img_btn_length == 0) {
            console.log("图片个数===",$('.wr_readerImage_opacity').length)
            $('.wr_readerImage_opacity').each((ind,ele) => {
                let btn =  document.createElement("button")
                btn.name = "btn_cxy_open_img_page"
                btn.innerHTML = "📋"

                let btn2 =  document.createElement("button")
                btn2.name = "btn_cxy_get_img"
                btn2.innerHTML = "▼"

                // 设置指定位置
                // let xy = $(ele)[0].getBoundingClientRect()

                btn.style.cssText = `position: absolute;right: 0px;top: ${ele.offsetTop-50}px;color:white;z-index:9999; cursor:pointer`
                btn2.style.cssText = `position: absolute;right: 0px;top: ${ele.offsetTop-20}px;color:#888;z-index:9999; cursor:pointer`

                // 添加按钮
                ele.after(btn)
                ele.after(btn2)
            })
        }
    }
    add_copy_img_btn()


    // 打开新窗口 显示图片
    $(document).on("click","button[name='btn_cxy_open_img_page']",function(){
        let link = $(this).prev().prev().attr("src")
        GM_openInTab(link, { active: true });
    })

    // 下载图片按钮
    $(document).on("click","button[name='btn_cxy_get_img']",function(){
        let link = $(this).prev().attr("src")
        // console.log(link);
        GM_download({
            url: link,
            name: new Date().getTime()+'.jpg',
            headers: {
                "User-Agent": "netdisk;6.7.1.9;PC;PC-Windows;10.0.17763;WindowsBaiduYunGuanJia",
            },
            onprogress: function (e) {
                //   console.log(JSON.stringify(e))
            },
        });
    })

    function getCurrentMaxWidth(element) {
        let currentValue = window.getComputedStyle(element).maxWidth;
        currentValue = currentValue.substring(0, currentValue.indexOf('px'));
        currentValue = parseInt(currentValue);
        return currentValue;
    }

    function changeWidth(increse) {
        const step = 100;
        const item1 = document.querySelector(".readerContent .app_content");
        const item2 = document.querySelector('.readerTopBar');
        const currentValue = getCurrentMaxWidth(item1);
        let changedValue;
        if (increse) {
            changedValue = currentValue + step;
        } else {
            changedValue = currentValue - step;
        }
        item1.style['max-width'] = changedValue + 'px';
        item2.style['max-width'] = changedValue + 'px';
        const myEvent = new Event('resize');
        window.dispatchEvent(myEvent)
    }
    function changeToFullScreen() {
        const windowsWidth = window.innerWidth;
        const item1 = document.querySelector(".readerContent .app_content");
        const item2 = document.querySelector('.readerTopBar');
        const currentValue = getCurrentMaxWidth(item1);
        item1.style['max-width'] = windowsWidth + 'px';
        item2.style['max-width'] = windowsWidth + 'px';
        const myEvent = new Event('resize');
        window.dispatchEvent(myEvent)
    }

    // 添加内容
    var butDiy = "<button id='lv-button0' class='readerControls_item widthIncrease' style='color:#6a6c6c;cursor:pointer;'>全屏</button>"
    //var butDiy = "<button id='lv-button0' class='readerControls_item widthIncrease' style='color:#6a6c6c;cursor:pointer;'>全屏</button><button id='lv-button1' class='readerControls_item widthIncrease' style='color:#6a6c6c;cursor:pointer;'>加宽</button><button id='lv-button2' class='readerControls_item widthDecrease' style='color:#6a6c6c;cursor:pointer;'>减宽</button>"

    $('.readerControls').append(butDiy);
    // 添加监听
    document.getElementById('lv-button0').addEventListener('click', () => changeToFullScreen());
//    document.getElementById('lv-button1').addEventListener('click', () => changeWidth(true));
//    document.getElementById('lv-button2').addEventListener('click', () => changeWidth(false));

        var butDiy2 = "<button id='autoScrollAcc' class='readerControls_item autoScroll' style='color:#6a6c6c;cursor:pointer;'>滚动加速</button><button id='autoScrollDec' class='readerControls_item autoScroll' style='color:#6a6c6c;cursor:pointer;'>滚动减速</button><button id='autoScrollPause' class='readerControls_item autoScrollOff' style='color:#6a6c6c;cursor:pointer;'>开始滚动</button>"
    $('.readerControls').append(butDiy2);

    let scrollSpeed = 1; // 初始滚动速度
    let isScrolling = false; // 初始滚动状态
    let scrollInterval; //滚动间隔
    $('#autoScrollAcc').click(function () {
        scrollSpeed++;
        var text=$("#autoScrollPause").text().substring(0, 2)
        $('#autoScrollPause').html(text + scrollSpeed)
    })
    $('#autoScrollDec').click(function () {
        scrollSpeed--;
        var text=$("#autoScrollPause").text().substring(0, 2)
        $('#autoScrollPause').html(text + scrollSpeed)
    })
    $('#autoScrollPause').click(function () {
        isScrolling=!isScrolling;
        if(isScrolling){
            scrollInterval = setInterval(autoScroll, 20);
            $('#autoScrollPause').html('暂停' + scrollSpeed)
        }else{
            clearInterval(scrollInterval)
            $('#autoScrollPause').html('继续' + scrollSpeed)
        }
    })

    function autoScroll() {
        var distance = scrollSpeed;
        window.scrollBy(0, distance);
    }
    
    var windowTop = 0;
    $(window).scroll(function () {
        let scrollS = $(this).scrollTop();
        let selBtn = document.querySelector('.readerTopBar');
        let readerControl = document.querySelector(".readerControls");
        $('.readerControls').mouseenter ( function () {
            $('.readerControls').css('opacity','1')
        })
        $('.readerControls').mouseleave ( function () {
            $('.readerControls').css('opacity','0')
        })
        if (scrollS >= windowTop) {
            // 上划显示
            selBtn.style.opacity = 0;
            windowTop = scrollS;

        } else {
            // 下滑隐藏
            selBtn.style.opacity = 1;
            windowTop = scrollS;
        }
    });
})();