Greasy Fork

手机看图、小说适配

页面旋转,自动滚动,图片集合

目前为 2023-08-21 提交的版本。查看 最新版本

// ==UserScript==
// @name         手机看图、小说适配
// @namespace    http://tampermonkey.net/
// @version      9.247
// @description  页面旋转,自动滚动,图片集合
// @author       You
// @match        *://*/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=pixabay.com
// @grant        none
// @require https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    var Dscroll = 0;

    var Dxy = 0;

    var timeDown;

    var scrollJu = 180;

    var winW;

    if ($(window).width() > $(window).height()) {

        winW = $(window).height() * 0.9;

    } else {

        winW = $(window).width();

    }

    var width = winW * 0.125;

    var height = winW * 0.1;

    var top = $(window).height() * 0.35 - winW * 0.05;

    var fontSz = winW * 0.036;

    var jianG = winW * 0.1;

    var left2 = -0.125 * winW * 0.125;

    var left = winW * 0.125 + left2;

    var degZ = 0;

    var secZ = 2;

    var scaleZ = 1;

    var xMove = 0;

    var twoCss = "position:absolute; top:0; left: 0; overflow: visible; width: 100%!important; height: auto!important; z-index: 2147483646!important; padding: 0 0 1000px 0!important; margin: 0; border: 0; background-color: black;"

    var aScss = "border-radius: " + (width * 0.1) + "px;cursor: pointer; opacity: 0.8; z-index: 2147483647!important; padding: 0!important; font-weight: bold; font-size: " + fontSz + "px !important;line-height:12px!important; border:2px solid white;height:" + height + "px;background-color:black;color:white;position:fixed;width:" + width + "px;left:0%; top: 15%; ";

    var sameCss = aScss + "margin-left:" + left + "px;";
    var sameCss2 = aScss + "margin-left:" + left2 + "px;";

    if ($('.JqScroll').length > 0) {
        return
    }
    $("body").append("<input type='button' class='JqScroll' id='Jscroll-jian' value='-' style='" + sameCss + "px;margin-top:" + (top - jianG) + "px'>")
        .append("<input type='button' class='JqScroll' id='Jscroll-rotate' value='R' style='" + sameCss + "px;margin-top:" + (top) + "px'>")
        .append("<input type='button' class='JqScroll' id='Jscroll-jia' value='+' style='" + sameCss + "px;margin-top:" + (top - 2 * jianG) + "px'>")
        .append("<input type='button' class='JqScroll' id='Jscroll-Ju' value='" + scrollJu + "' style='" + sameCss + "px;margin-top:" + (top - 3 * jianG) + "px'>")
        .append("<input type='button' class='JqScroll' id='Jscroll-sec' value='" + secZ + "' style='" + sameCss + "px;margin-top:" + (top - 4 * jianG) + "px'>")
        .append("<input type='button' class='JqScroll' id='Jscroll-width' value='W' style='" + sameCss2 + "px;margin-top:" + (top - jianG) + "px'>")
        .append("<input type='button' class='JqScroll' id='Jscroll-pic' value='P' style='" + sameCss2 + "px;margin-top:" + (top - 2 * jianG) + "px'>")
        .append("<input type='button' class='JqScroll' id='Jscroll-xy' value='▽' style='" + sameCss2 + "px;margin-top:" + (top - 3 * jianG) + "px'>")
        .append("<input type='button' class='JqScroll' id='Jscroll-del' value='X' style='" + sameCss2 + "px;margin-top:" + (top) + "px'>")

    $('<style>#Jscroll-ul *::before,#Jscroll-ul *::after{padding:0;margin:0;height:0;border:0;}</style>').appendTo('head');

    var Drotate = 0;
    $("body").on('touchstart', '#Jscroll-rotate', function() {

        Drotate += 1;

        if (Drotate % 2 != 0) {

            $("#Jscroll-rotate").css("color", "green");

            var wrap_rotate;

            var wrap_rotate_inner;

            if ($('#wrap_rotate').length == 0) {

                wrap_rotate = $('<div />', {
                    id: "wrap_rotate"
                });

                wrap_rotate_inner = $('<div />', {
                    id: "wrap_rotate_inner"
                });;

                $('body').wrapInner(wrap_rotate_inner).wrapInner(wrap_rotate);
            }

            wrap_rotate = $('#wrap_rotate');

            wrap_rotate_inner = $('#wrap_rotate_inner');

            var window_width = $(window).height();

            window.scrollTo(0, 3 * window_width);

            setTimeout(function() {

                wrap_rotate.append($(".JqScroll"));

                wrap_rotate.attr('style', "z-index: 2147483647!important; overflow-y: visible; height: " + (window_width) + "px;width:" + ($(document).height() + 10) + "px;");

                wrap_rotate_inner.attr('style', "z-index: 2147483647!important; position: relative; left: -100%; -webkit-transform: rotateZ(-90deg); -webkit-transform-origin-x: 100%; -webkit-transform-origin-y: 0%; -moz-transform: rotateZ(-90deg); -moz-transform-origin-x: 100%; -moz-transform-origin-y: 0%;float: right; width: " + window_width + "px;");

                xMove = 1;

                $("body").css({
                    "overflow-x": "visible",
                    "overflow-y": "visible",

                });

                if ($("#wrap_rotate").width() < $("#wrap_rotate_inner").outerHeight() + 1500) {
                    $("#wrap_rotate").width($("#wrap_rotate_inner").outerHeight() + 1500);
                }
                window.scrollTo(0, 0);
            }, 200);
        } else {
            $("#Jscroll-rotate").css("color", "white");

            xMove = 0;

            setTimeout(function() {
                $('#wrap_rotate').attr('style', "");
                $('#wrap_rotate_inner').attr('style', "");

            }, 200);
        }

    });

    var fSize;
    var fontZ;
    var widthN = 12;

    $("body").on('touchstart', '#Jscroll-width', function() {

        fSize = parseInt($(document).width() / widthN);

        $("#Jscroll-width").css("color", "green");

        if (widthN > 17) {

            fSize = "inherit";
            $("#Jscroll-width").css("color", "white");

        }

        function interFn() {
            $(":not(:has(div,li))").filter(function() {
                return $(this).is('p') || $(this).clone().children().remove().end().text().length > 100;
            }).css({
                "background-color": "black",
                "color": "white",
                "font-size": fSize,
                "line-height": "normal"
            });

        }

        clearInterval(fontZ);
        interFn();
        fontZ = setInterval(interFn, 4 * 1000);

        $("#Jscroll-width").val(20 - widthN);
        if (widthN == 18) {
            $("#Jscroll-width").val("W");

        }
        if (fSize == "inherit") {
            widthN = 10;
        }

        widthN += 2;

    });

    function shallowEqual(object1, object2) {
        const keys1 = Object.keys(object1);
        const keys2 = Object.keys(object2);

        if (keys1.length !== keys2.length) {
            return false;
        }

        for (let index = 0; index < keys1.length; index++) {
            const val1 = object1[keys1[index]];
            const val2 = object2[keys2[index]];
            if (val1 !== val2) {
                return false;
            }
        }

        return true;
    }

    var widthZ;
    var picZ = 0;
    var imgAr;
    var newImgAr;
    $("body").on('touchstart', "#Jscroll-pic", function() {

        clearInterval(widthZ);

        $("#Jscroll-ul").remove();

        picZ += 1;

        function interFn() {
            var preSrc = "";
            var preSrc_2 = "";
            var preData = {};

            newImgAr = []

            if (picZ == 1 || picZ == 2) {

                $("*").each(function() {
                    var _img = $(this);
                    var _a;

                    if (!_img.parent().is("#Jscroll-ul") && !_img.parent().parent().is("#Jscroll-ul")) {

                        var urlS = "";

                        if (_img.is("img[src]") && _img.outerHeight() > 60) {

                            urlS = _img.attr("src").split(" ")[0];

                            if (picZ == 1){

                                newImgAr.push("<img src='" + urlS + "'>");

                            }

                            if (picZ == 2 && _img.closest("a").length != 0 && urlS != preSrc){

                                _a = _img.closest("a");

                                newImgAr.push(_a.clone(true).empty().append("<img src='" + urlS + "'>"));

                                preSrc = urlS;

                            }

                        }

                        if (_img.is("[srcset]")) {

                            urlS = _img.attr("srcset").split(" ")[0];

                            if (picZ == 1){

                                newImgAr.push("<img src='" + urlS + "'>");

                            }

                            if (picZ == 2 && _img.closest("a").length != 0 && urlS != preSrc_2){

                                _a = _img.closest("a");

                                newImgAr.push(_a.clone(true).empty().append("<img src='" + urlS + "'>"));

                                preSrc_2 = urlS;

                            }

                        }

                        if (!shallowEqual(_img.data(), preData)) {

                            var preI = "";

                            $.each(_img.data(), function(v, i) {

                                if (i.toString().indexOf("//") > -1) {

                                    i = i.split(" ")[0];

                                    if(i != preI){

                                        if (picZ == 1){

                                            newImgAr.push("<img src='" + i + "'>");

                                        }

                                        if (picZ == 2 && _img.closest("a").length != 0 && i.toString().indexOf(" ") == -1 && i != urlS){

                                            _a = _img.closest("a");

                                            newImgAr.push(_a.clone(true).empty().append("<img src='" + i + "'>"));

                                        }

                                        preI = i;
                                    }
                                }

                            });

                            preData = _img.data();

                        }

                    }

                });

            }

            if (picZ == 3) {

                $("*").each(function() {

                    var _aImg = $(this);

                    if (_aImg.css("background-image").indexOf("url") > -1) {

                        var _backImg = _aImg.css("background-image").split("\"")[1].split(" ")[0];

                        if (_aImg.is("a") && _backImg != preSrc) {

                            newImgAr.push(_aImg.clone(true).empty().append("<img src='" + _backImg + "'>"));

                            preSrc = _backImg;

                        } else {

                            if (_aImg.closest("a").length != 0 && _backImg != preSrc_2){

                                var _a = _aImg.closest("a");

                                newImgAr.push(_a.clone(true).empty().append("<img src='" + _backImg + "'>"));

                                preSrc_2 = _backImg;

                            }else{

                                newImgAr.push("<img src='" + _backImg + "'>");

                            }
                        }
                    }

                });

            }

            if (picZ == 4) {

                $("*").each(function() {

                    var _aImg = $(this);

                    if (!_aImg.parent().is("#Jscroll-ul")) {

                        if (!shallowEqual(_aImg.data(), preData)) {

                            $.each(_aImg.data(), function(v, i) {

                                if (i.toString().indexOf("//") > -1) {

                                    newImgAr.push("<img src='" + i.split(" ")[0] + "'>");
                                }

                            });

                            preData = _aImg.data();

                        }

                        if (_aImg.is("img[src]")) {

                            newImgAr.push("<img src='" + _aImg.attr('src').split(" ")[0] + "'>");
                        }

                        if (_aImg.is("[srcset]")) {

                            newImgAr.push("<img src='" + _aImg.attr('srcset').split(" ")[0] + "'>");
                        }

                        if (_aImg.css("background-image").indexOf("url") > -1) {

                            var _backImg = _aImg.css("background-image").split("\"")[1].split(" ")[0];

                            newImgAr.push("<img src='" + _backImg + "'>");

                        }

                        if (_aImg.is("a") && _aImg.outerHeight() > 0 && _aImg.outerWidth() > 80) {

                            if (_aImg.is("[href]") && _aImg.attr("href") != preSrc) {

                                var _href = _aImg.attr("href");
                                var _clone;

                                if(/^\//.test(_href)){
                                    _clone = _aImg.clone(true).empty().attr("href",window.location.protocol + "//" + window.location.host + _href);
                                }else{
                                    _clone = _aImg.clone(true).empty();
                                }

                                newImgAr.push(_clone);
                                preSrc = _aImg.attr("href")
                            }

                            if (!_aImg.is("[href]")) {

                                newImgAr.push(_aImg.clone(true).empty());

                            }

                        }

                    }

                });

            }

            newImgAr = Array.from(new Set(newImgAr));

            if (newImgAr.toString() != imgAr.toString()) {

                imgAr = newImgAr;
                $("#Jscroll-ul").empty().append(imgAr);

                $("#Jscroll-ul *").attr("style", "font-size: 0; padding: 0; margin: 0; border: 0; position: static; float: none;");

                $("#Jscroll-ul img,#Jscroll-ul a").css({
                    "height": "auto",
                    "width": "100%",
                    "opacity": "1",
                    "display": "block",
                    "object-fit": "contain",
                    "max-height": 2500,
                    "min-height": 80,
                    "background-color": "black",
                });

                $("#Jscroll-ul>img").css({
                    "border": "1px solid gray",
                });
                $("#Jscroll-ul a").css({
                    "border": "1px solid red",
                });

                var isSupportLoading = 'loading' in document.createElement('img');
                if (isSupportLoading) {
                    $("#Jscroll-ul img").attr("loading", "lazy");
                }

            }

            if (xMove == 1) {
                if ($("#wrap_rotate").width() < $("#Jscroll-ul").outerHeight() + 500) {

                    $("#wrap_rotate").width($("#Jscroll-ul").outerHeight() + 500);
                }

            } else {

                if ($("body").height() < $("#Jscroll-ul").outerHeight()) {

                    $("body").height($("#Jscroll-ul").outerHeight());
                }

            }

        }

        if (picZ < 5) {
            if (xMove == 1) {
                $("#wrap_rotate_inner").prepend("<div id='Jscroll-ul' style='" + twoCss + "'>");
            } else {
                $("body").prepend("<div id='Jscroll-ul' style='" + twoCss + "'>");
            }

            imgAr = []

            $("#Jscroll-pic").css("color", "green").val(picZ);
            interFn()
            widthZ = setInterval(interFn, 4000);

        } else {

            $("#Jscroll-pic").css("color", "white").val("P");

            if (xMove == 1) {
                $("#wrap_rotate").width($("#wrap_rotate_inner").outerHeight() + 1500);
            } else {
                $("body").css({
                    "height": "auto"
                });
            }
            picZ = 0;
        }

    });

    $("body").on('click', "#Jscroll-ul", function(e) {

        var touchX = e.clientX;
        var touchY = e.clientY;
        var howH = 0.8;

        if (xMove == 1) {
            if (touchX > $(window).width() / 2) {
                window.scrollBy($(window).width() * howH, 0)

            } else {
                window.scrollBy($(window).width() * howH * -1, 0)

            }
        } else {
            if (touchY > $(window).height() / 2) {
                window.scrollBy(0, $(window).height() * howH);

            } else {
                window.scrollBy(0, $(window).height() * howH * -1);

            }
        }

    });

    var timeout_7;

    $("body").on('touchstart', '#Jscroll-pic', function() {
        timeout_7 = setTimeout(function() {
            clearInterval(widthZ);

            $("#Jscroll-ul").remove();
            $("#Jscroll-pic").css("color", "white").val("P");

            if (xMove == 1) {
                $("#wrap_rotate").width($("#wrap_rotate_inner").outerHeight() + 1500);
            } else {
                $("body").css({
                    "height": "auto"
                });
            }
            picZ = 0;
        }, 600);
    }).on('touchend touchmove', '#Jscroll-pic', function() {
        clearTimeout(timeout_7);
    });

    $("body").on('touchstart', '#Jscroll-sec', function() {

        secZ -= 1;

        if (secZ < 0) {
            secZ = 3
        }
        if (secZ < 1) {
            secZ = 0.6
        }
        $("#Jscroll-sec").val(secZ);

    });

    $("body").on('touchstart', '#Jscroll-jia', function() {

        scrollJu += 45;
        $("#Jscroll-Ju").val(scrollJu);

    });

    var toH;

    $("body").on('touchstart', '#Jscroll-xy', function() {
        if (xMove != 1) {
            toH = $(document).height();

        } else {
            toH = $("#wrap_rotate_inner").outerHeight() - 250;

        }
        Dxy += 1;
        if (Dxy % 2 != 0) {

            if (xMove == 1) {
                window.scrollTo(toH, 0);

            } else {
                window.scrollTo(0, toH);
            };
            $("#Jscroll-xy").val("△");
        } else {
            window.scrollTo(0, 0)
            $("#Jscroll-xy").val("▽");
        }
    });

    setTimeout(function() {
        $(".JqScroll").hide();
        $("#Jscroll-del").show().css({
            "opacity": "0.4",
            "-webkit-transform": "scale(0.72)",
            "-moz-transform": "scale(0.72)",
            "transform": "scale(0.72)",

        });
    }, 100);

    var Dhide = 1;

    $("body").on('touchstart', '#Jscroll-del', function() {

        Dhide += 1;

        if (Dhide % 2 != 0) {
            $(".JqScroll").hide();
            $("#Jscroll-del").show().css({
                "opacity": "0.4",
                "-webkit-transform": "scale(0.72)",
                "-moz-transform": "scale(0.72)",
                "transform": "scale(0.72)",
            });

        } else {
            $(".JqScroll").show();
            $("#Jscroll-del").css({
                "opacity": "0.8",
                "-webkit-transform": "scale(1)",
                "-moz-transform": "scale(1)",
                "transform": "scale(1)",

            });
            if (Dscroll % 2 != 0 && secZ < 1.5) {
                Dscroll += 1;
                $("#Jscroll-Ju").css("color", "white");

                clearInterval(timeDown);
            }

        }
    });

    var timeout_2;
    $("body").on('touchstart', '#Jscroll-del', function() {
        timeout_2 = setTimeout(function() {

            $(".JqScroll").hide();
            $("#Jscroll-del").css({
                "opacity": "0.4",
                "-webkit-transform": "scale(0.72)",
                "-moz-transform": "scale(0.72)",
                "transform": "scale(0.72)",

            });
            if (Dhide % 2 == 0) {
                Dhide += 1;
            }

        }, 700);
    }).on('touchend touchmove', '#Jscroll-del', function() {
        clearTimeout(timeout_2);
    });

    var timeout_3;
    $("body").on('touchstart', function() {
        timeout_3 = setTimeout(function() {

            $("#Jscroll-del").show();
        }, 600);
    }).on('touchend touchmove', function() {
        clearTimeout(timeout_3);
    });

    $("body").on('touchstart', '#Jscroll-jian', function() {

        scrollJu -= 45;

        $("#Jscroll-Ju").val(scrollJu);

    });

    var timeout_4;
    $("body").on('touchstart', '#Jscroll-jian', function() {
        timeout_4 = setTimeout(function() {

            scrollJu -= 135;

            $("#Jscroll-Ju").val(scrollJu);

        }, 600);
    }).on('touchend touchmove', '#Jscroll-jian', function() {
        clearTimeout(timeout_4);
    });

    var timeout_5;
    $("body").on('touchstart', '#Jscroll-jia', function() {
        timeout_5 = setTimeout(function() {

            scrollJu += 135;

            $("#Jscroll-Ju").val(scrollJu);

        }, 600);
    }).on('touchend touchmove', '#Jscroll-jia', function() {
        clearTimeout(timeout_5);
    });

    var timeout_6;
    $("body").on('touchstart', '#Jscroll-Ju', function() {
        timeout_6 = setTimeout(function() {

            scrollJu = 180;

            $("#Jscroll-Ju").val(scrollJu);

            Dscroll += 1;

            if (Dscroll % 2 != 0) {
                $("#Jscroll-Ju").css("color", "green");

                clearInterval(timeDown);
                timeDown = setInterval(function() {
                    if (xMove == 1) {
                        window.scrollBy(scrollJu, 1)
                        window.scrollBy(0, -1);
                    } else {
                        window.scrollBy(0, scrollJu)
                    }

                }, secZ * 1000);

            } else {
                $("#Jscroll-Ju").css("color", "white");

                clearInterval(timeDown);

            }
        }, 600);
    }).on('touchend touchmove', '#Jscroll-Ju', function() {
        clearTimeout(timeout_6);
    });

    $("body").on('touchstart', '#Jscroll-Ju', function() {

        Dscroll += 1;

        if (Dscroll % 2 != 0) {
            $("#Jscroll-Ju").css("color", "green");

            clearInterval(timeDown);
            timeDown = setInterval(function() {
                if (xMove == 1) {
                    window.scrollBy(scrollJu, 0)
                } else {
                    window.scrollBy(0, scrollJu)
                }

            }, secZ * 1000);

        } else {
            $("#Jscroll-Ju").css("color", "white");

            clearInterval(timeDown);

        }

    });
    // Your code here...
})();