Better WeRead

Let WeRead display better

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Better WeRead
// @namespace    http://fastgo.vip/
// @version      0.1.3
// @description  Let WeRead display better
// @license      GNU
// @author       AaronW
// @match        https://weread.qq.com/web/reader/**
// @icon         https://www.google.com/s2/favicons?sz=64&domain=qq.com
// @grant        none
// ==/UserScript==

function $(el){
  return document.querySelector(el);
}

let wrpWidth;

function updateImg() {
    document.querySelectorAll('.passage-content img').forEach(img => {
        if (img.classList.contains('kindle-cn-inline-image1')) return
        img.style.width = 'inherit';
        img.style.height = 'inherit';
        let transform = img.style.transform;
        let imgWidth = img.getAttribute('data-w');
        imgWidth = imgWidth.substr(0, imgWidth.length - 2)

        console.log('imgWidth', imgWidth);


        transform = transform.replace(/\(.*px,/, `(${(wrpWidth - imgWidth) / 2}px,`);
//        let translatePos = /\(.*\)$/.exec(transform)[0];
//        let transY = translatePos.split(",")[1];
        console.log('new transform: ', transform)
        img.style.transform = transform;
    })
}

(function() {
    'use strict';
    console.log("script loaded");
    let content = document.querySelector('.readerContent .app_content');
    content.style['max-width'] = window.innerWidth + "px";

    content.addEventListener('DOMNodeInserted', () => {
        wrpWidth = $('#renderTargetContent').getBoundingClientRect().width;

    console.log("wrp width", wrpWidth);
        updateImg()
        content.removeEventListener('DOMNodeInserted', () => {});
    })

    $('.readerTopBar').style['max-width'] = "inherit";
})();