Greasy Fork

Greasy Fork is available in English.

UU看書手機版

幫助在使用手機閱讀UU看書時,能使用滑鼠手勢輕鬆地換頁

当前为 2021-10-13 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name                UU看書手機版
// @version             0.1.6
// @description         幫助在使用手機閱讀UU看書時,能使用滑鼠手勢輕鬆地換頁
// @author              John
// @match               *://*.uukanshu.com/read.aspx*
// @grant               none
// @license             MIT License
// @namespace           http://greasyfork.icu/users/814278
// ==/UserScript==

var lastX,lastY,lastSign,afterGestures,gesturesWords,gesturesContent,gestures,signs;
const defaultFun={
    prePage:"prePage()",
    nextPage:"nextPage()"
};
var bookName = getBookName();

var filterList = ['UU看書 www.uukanshu.com'
                 ,'UU看書www.uukanshu.com'
                  ,'UU看书 www.uukanshu.com'
                  ,'UU看书www.uukanshu.com'
                  ,'請記住本書首發域名:。手機版更新最快網址:'
                  ,'\\(未完待續。\\)'
                  ,'\\(未完待续。\\)'
                  ,'\\(\\)'
                  ,'\\[\\]'
                  ,'天才一秒記住本站地址:最快更新!無廣告!'
                  ,'章節缺失、錯誤舉報'
                  ,'章节缺失、錯誤举报'
                  ,'章节缺失、错误举报'
                  ,'天才壹秒記住,為您提供精彩小說閱讀。'
                  ,'手機用戶請瀏覽m閱讀,更優質的閱讀體驗。'
                  ,'手机用户请浏览m阅读,更优质的阅读体验。'
                  ,'最新網址:'
                  ,"您可以在百度裏搜索“"+bookName+"搜小說”查找最新章節!"
                  ,"\\n\\n"+bookName+'最新章節地址:https://'
                  ,"\\n\\n"+bookName+'全文閱讀地址:https://'
                  ,"\\n\\n"+bookName+'txt下載地址:https://'
                  ,"\\n\\n"+bookName+'手機閱讀:https://'
                  ,"\\n\\n為了方便下次閱讀.*下次打開書架即可看到!"
                  ,"\\n\\n喜歡《"+bookName+"》請向你的朋友\\(QQ、博客、微信等方式\\)推薦本書,謝謝您的支持!!"
                 ];

var replaceList = {
                    ",":","
                    , ":":":"
                    , ";":';'
                    , "\\?":"?"
                    , "!":"!"
                    , "夸":"誇"
                    , "并":"並"
                    , "閑":"閒"
                    , "圣":"聖"
                    , "里":"裡"
                    , "云":"雲"
                    , "愿":"願"
                    , "后":"後"
                    , bookName:"後"
                    , "皇後":"皇后"
                    , "王後":"王后"
                    , "太後":"太后"
                    , "天後":"天后"
                    , "隻能":"只能"
                    , "隻要":"只要"
                    , "隻是":"只是"
                    , "隻可":"只可"
                    , "隻允":"只允"
                    , "隻說":"只說"
                    , "這么":"這麼"
                    , "那么":"那麼"
                    , "怎么":"怎麼"
                    , "什么":"什麼"
                    , "答復":"答覆"
                    , "開采":"開採"
                    , "采收":"採收"
                    , "采集":"採集"
                    , "采納":"採納"
                    , "舍不":"捨不"
                    , "舍棄":"捨棄"
                    , "松動":"鬆動"
                    , "干干":"乾乾"
                    , "干貨":"乾貨"
                    , "合並":"合併"
                    , "吞並":"吞併"
                    , "並吞":"併吞"
                    , "典范":"典範"
                    , "范例":"範例"
                    , "關于":"關於"
                    , "大于":"大於"
                    , "小于":"小於"
                    , "等于":"等於"
                    , "高于":"高於"
                    , "低于":"低於"
                    , "至于":"至於"
                    };

function prePage(){
    var url = $("#read_pre").attr("href");
    if (url == undefined){
        url = $("#prev").attr("href");
    }
    if (url == undefined){
        return false;
    }
    window.location.href = url;
}

function nextPage(){
    var url = $("#read_next").attr("href");
    if (url == undefined){
        url = $("#next").attr("href");
    }
    if (url == undefined){
        return false;
    }
    window.location.href = url;
}

function initEventListener(start,move,end,tracer,clientX,clientY,startBool){
    var isMouse=start=="mousedown";
    function moveFun(e){
        tracer(eval(clientX),eval(clientY), isMouse);
        gesturesWords.innerHTML=signs;
        var gesturesWidth=signs.length*51+40;
        gesturesContent.style.width=gesturesWidth+"px";
        gesturesContent.style.marginLeft=-gesturesWidth/2+"px";
    };

    document.addEventListener(start, function(e) {
        if(!startBool || eval(startBool)){
            lastX=eval(clientX);
            lastY=eval(clientY);
            lastSign=signs="";
            document.addEventListener(move, moveFun, false);
        }
    }, false);

    function endFun(e) {
        document.removeEventListener(move, moveFun, false);
        setTimeout(function(){if(gesturesContent.parentNode)gesturesContent.parentNode.removeChild(gesturesContent);},500);
        if(signs){
            if(afterGestures)afterGestures();
            for(var g of gestures){
                var gSign=g.gesture;
                if(signs==gSign){
                    if(!isMouse) document.body.appendChild(gesturesContent);
                    var fun=defaultFun[g.fun];
                    if(fun===undefined || !fun){
                        eval(g.fun);
                    }else{
                        eval(fun);
                    }
                    e.stopPropagation();
                    e.preventDefault();
                    break;
                }
            }
            signs="";
        }
    };

    document.addEventListener(end, endFun, false);
    document.addEventListener("mouseup", endFun, false);
}

function fullToHalf(val) {
    var result = "";

    try{
        var value = val || "";
        if (value) {
            for (var i = 0; i <= value.length; i++) {
                if (value.charCodeAt(i) == 12288) {
                    result += " ";
                } else {
                    if (value.charCodeAt(i) > 65280 && value.charCodeAt(i) < 65375) {
                        result += String.fromCharCode(value.charCodeAt(i) - 65248);
                    } else {
                        result += String.fromCharCode(value.charCodeAt(i));
                    }
                }
            }
        }
    }catch(e){
        console.error(e);
    }

  return result;
}

function alterContent(){
    try{
        var obj = document.getElementById("bookContent");
        obj.style.cssText += 'word-break: break-all;';
        var val = fullToHalf(obj.innerText);
        console.log("val..."+val)
        for(const str of filterList){
            val = val.replace(new RegExp(str,"gi"),'');
        }

        setTimeout(function() {
            for (var key in replaceList) {
                val = val.replace(new RegExp(key, "gi"), replaceList[key]);
            }
            obj.innerText = val;
        },5);
    }catch(e){
        console.error(e);
    }
}

function addNexPagetLink(){
    try{
        var newEle = document.createElement("div");
        var oldEle = document.querySelector(".rp-switch");
        var nextLinkEle = document.getElementById("read_next")

        var leftEle = nextLinkEle.cloneNode(true);
        var rightEle = nextLinkEle.cloneNode(true);
        leftEle.style.cssText = 'left:0px;position:absolute;';
        rightEle.style.cssText = 'right:0px;position:absolute;';
        newEle.appendChild(leftEle);
        newEle.appendChild(rightEle);
        oldEle.parentNode.insertBefore(newEle ,oldEle);
    }catch(e){
        console.error(e);
    }
}


function alterEleLoction(){
    var toolbtm1Ele = document.getElementById("tool_btm1");
    var toolbtm2Ele = document.getElementById("tool_btm2");
    var fontBtbEle = document.getElementById("funfont");
    var nextBtnEle = document.getElementById("funnext");
    fontBtbEle.style = 'width:50px;position: absolute;right:10px;left:auto;padding-top: 12px;';
    nextBtnEle.style = 'width:50px;position: absolute;left:10px;';

    toolbtm1Ele.insertBefore(nextBtnEle, fontBtbEle);
    toolbtm1Ele.removeChild(fontBtbEle);
    toolbtm2Ele.appendChild(fontBtbEle);
}

function getBookName(){
    var result = "";
    try{
        var headerEle = document.querySelector("header");
        var aa = headerEle.innerText.split("\n");
        result = aa[1];
    }catch(e){
        console.error(e);
    }
    return result;
}

(function() {
    'use strict';
    const minLength=256;
    const tg=0.5;
    gestures=[
          {gesture:"→", fun:"prePage"},
          {gesture:"←", fun:"nextPage"},
         ];

    function tracer(curX,curY,showSign) {
        let distanceX=curX-lastX,distanceY=curY-lastY;
        let distance=(distanceX*distanceX)+(distanceY*distanceY);
        if (distance>minLength) {
            lastX=curX;
            lastY=curY;
            let direction="";
            let slope=Math.abs(distanceY/distanceX);
            if(slope>tg){
                if(distanceY>0) {
                    direction="↓";
                }else{
                    direction="↑";
                }
            }else if(slope<=1/tg) {
                if(distanceX>0) {
                    direction="→";
                }else{
                    direction="←";
                }
            }
            if(lastSign!=direction) {
                signs+=direction;
                lastSign=direction;
                if(showSign){
                    document.body.appendChild(gesturesContent);
                }
            }
        }
    }

    gesturesContent=document.createElement("div");
    gesturesContent.id="gesturesContent";
    gesturesContent.style.cssText="width:300px;height:70px;position:fixed;left:50%;top:50%;margin-top:-25px;margin-left:-150px;z-index:999999999;background-color:#000;border:1px solid;border-radius:10px;opacity:0.65;filter:alpha(opacity=65);box-shadow:5px 5px 20px 0px #000;";
    gesturesContent.innerHTML='<div id="gesturesWords" style="position:absolute;left:20px;top:5px;font:bold 50px \'黑体\';color:#ffffff"></div>';
    gesturesWords = gesturesContent.querySelector("#gesturesWords");

    initEventListener("touchstart","touchmove","touchend",tracer,"e.changedTouches[0].clientX","e.changedTouches[0].clientY");
    initEventListener("mousedown","mousemove","contextmenu",tracer,"e.clientX","e.clientY","e.which === 3");

    alterContent();
    // alterEleLoction();
    addNexPagetLink();

    try{
        document.querySelector('.samebooks1').style.display = 'none';
        document.querySelector('.socialBtn').style.display = 'none';
    }catch(e){
        console.error(e);
    }

    BookReader.ReadSetting.SetFontSize = function(val) {
        val = parseInt(val);
        var rf = parseInt(Common.GetCookie("ziti") || "18");
        if (isNaN(rf)) {
            rf = 20
        }
        val = val + rf;
        if (val > 36) {
            Common.Toast("已經是最大了...");
            val = 36
        }
        if (val < 16) {
            Common.Toast("已經是最小了...");
            val = 16
        }
        Common.SetCookie("ziti", val, (new Date()).AddDays(365), "/");
        $(BookReader.Display.Containers.ChapterDivId).css("font-size", val + "px");
        $(BookReader.Display.Containers.ChapterDivId).children("p").css("font-size", val + "px");
        $(BookReader.Display.Containers.ChapterDivId).css("line-height", val * BookReader.Options.Config.lineHeightRate +"px");
        $(BookReader.Display.Containers.ChapterDivId).children("p").css("line-height", val * BookReader.Options.Config.lineHeightRate + "px")
    }
})();