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

Greasy fork 爱吃馍镜像

微信读书加宽度优化版

微信读书宽度调整,可加大,减少,方便的调整到想要的宽度

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

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

公众号二维码

扫码关注【爱吃馍】

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

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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

公众号二维码

扫码关注【爱吃馍】

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

// ==UserScript==
// @name         微信读书加宽度优化版
// @namespace    在原作者xvusrmqj基础上优化,主要是自用
// @version      0.1
// @description  微信读书宽度调整,可加大,减少,方便的调整到想要的宽度
// @author       yw
// @match        https://weread.qq.com/web/reader/*
// @grant        GM_log
// @grant        GM_addStyle
// @license      GPL-3.0-only
// ==/UserScript==

(function () {
  "use strict";

  // 基础方法
  function getCurrentMaxWidth(element) {
    let currentValue = window.getComputedStyle(element).maxWidth;
    currentValue = currentValue.substring(0, currentValue.indexOf("px"));
    currentValue = parseInt(currentValue);
    return currentValue;
  }

  function getCurrentMarginLeft(element) {
    let currentValue = window.getComputedStyle(element).marginLeft;
    currentValue = currentValue.substring(0, currentValue.indexOf("px"));
    currentValue = parseInt(currentValue);
    return currentValue;
  }

  function changeWidth(increse) {
    changeContentWidth(increse);
    changeControlsPosition(increse);
    const myEvent = new Event("resize");
    window.dispatchEvent(myEvent);
  }

  function changeContentWidth(increse) {
    const step = 100;
    const item = document.querySelector(".readerContent .app_content");
    // 顶部信息栏
    var top = document.querySelector(".readerContent .readerTopBar");
    const currentValue = getCurrentMaxWidth(item);
    let changedValue;
    if (increse) {
      changedValue = currentValue + step;
    } else {
      changedValue = currentValue - step;
    }
    item.style["max-width"] = changedValue + "px";
    top.style["max-width"] = changedValue + "px";
  }

  function changeControlsPosition(increse) {
    const step = 50;
    const item = document.querySelector(".readerContent .readerControls");
    // 缩放
    const zoom = document.querySelector(".zoom-controls");
    // 阅读控制和缩放控制位置一致,采用同样的就可以
    const currentValue = getCurrentMarginLeft(item);
    let changedValue;
    if (increse) {
      changedValue = currentValue + step;
    } else {
      changedValue = currentValue - step;
    }

    item.style["margin-left"] = changedValue + "px";
    zoom.style["margin-left"] = changedValue + "px";
  }

  const initMenus = function () {
    // 添加内容
    const menus = `
        <div class="zoom-controls">
            <button id='lv-button1' class="zoom_item"><span class="iconfont">&#xe684;</span></button>
            <button id='lv-button2' class="zoom_item"><span class="iconfont">&#xe897;</span></button>
        </div>
    `;
    const body = document.getElementsByTagName("body");
    body[0].insertAdjacentHTML("beforeend", menus);
    // 添加样式
    GM_addStyle(`
        @font-face {
            font-family: 'iconfont';  /* Project id 3978675 */
            src: url('//at.alicdn.com/t/c/font_3978675_ngptx8td2k.woff2?t=1679888786121') format('woff2'),
                url('//at.alicdn.com/t/c/font_3978675_ngptx8td2k.woff?t=1679888786121') format('woff'),
                url('//at.alicdn.com/t/c/font_3978675_ngptx8td2k.ttf?t=1679888786121') format('truetype');
        }
        .iconfont {
            font-family: "iconfont" !important;
            font-size: 24px;
            font-style: normal;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
            color: white;
          }
        .zoom-controls {
            width: 48px;
            overflow: visible;
            position: fixed;
            z-index: 5;
            left: 50%;
            bottom: 405px;
            margin-left: 548px;   
        }
        .zoom-controls .zoom_item {
            width: 48px;
            height: 48px;
            background-color: #1c1c1d;
            transition: background-color .2s ease-in-out;
            border-radius: 24px;
            line-height: 48px;
            text-align: center;
            position: relative;
            margin-top: 24px;
        }
        .wr_whiteTheme .zoom_item {
            background-color: #fff;
            box-shadow: 0 8px 32px rgba(0,25,104,.1);
        }
        .wr_whiteTheme .iconfont {
            color: black;
        }
    `);
    // 添加监听
    document
      .getElementById("lv-button1")
      .addEventListener("click", () => changeWidth(true));
    document
      .getElementById("lv-button2")
      .addEventListener("click", () => changeWidth(false));
  };

  initMenus();
})();