177Viewer

添加两个按钮,免翻页查看整篇漫画

Versione datata 16/03/2019. Vedi la nuova versione l'ultima versione.

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         177Viewer
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  添加两个按钮,免翻页查看整篇漫画
// @author       tmbxy
// @match        www.177pic.info/html/*.html
// @match        www.177pic001.info/html/*.html
// ==/UserScript==

(function () {
    'use strict';

    var btnOne = $('<button style="padding:3px;color:#999;margin-right:5px" >动态加载</button>');
    var btnAll = $('<button style="padding:3px;color:#999;" >加载全部</button>');
    var config;
    var cookieIndex = document.cookie.indexOf('177viewer=')

    // 读取设置
    if (!cookieIndex) {
        config = document.cookie.slice(cookieIndex + 10, cookieIndex + 11);
        if (config == 1) {
            $(btnAll).css('color', '#ff6100');
        }
        else {
            $(btnOne).css('color', '#ff6100');
        }
    }
    else {
        document.cookie = '177viewer=0'
        config = 0;
        $(btnOne).css('color', '#ff6100');
    }

    // 重新设置并刷新
    $('.c-top2').after(btnOne, btnAll);
    $(btnOne).on('click', function () {
        document.cookie = '177viewer=0';
        location = location;
    });
    $(btnAll).on('click', function () {
        document.cookie = '177viewer=1';
        location = location;
    });


    //获取页面链接
    var a = $('div.wp-pagenavi a');
    var href = [];
    for (var i = 0; i < a.length - 1; i++) {
        href[i] = (a.eq(i).attr('href'));
    }

    var wait = 0;
    var pageIndex = 0;
    // 一次性加载
    if (config == 1) {
        loadImg(0, href.length);
    }
    // 动态加载
    else {
        // 滚动加载函数
        window.onload = function () {
            window.onscroll = function () {
                if (wait == 1 || pageIndex >= href.length) {
                    return;
                }
                wait = 1;
                setTimeout(function () {
                    wait = 0;
                }, 500);
                // 快滚到底了
                if ($(this).scrollTop() + $(this).height() + 1500 >= $(document).height()) {
                    loadImg(pageIndex, href.length);
                    pageIndex++;
                }
            };
        };
    }

    // 加载图片函数
    function loadImg(page, end) {
        if (page == end) {
            return;
        }
        $('<div></div>').load(href[page] + ' .entry-content', function () {
            $('#single-navi').before($(this).children().children('p'));

            if (config == 1) {
                page++;
                loadImg(page, end);
            }
        });
    }

})();