javbus.waterfall

Infinite scroll @ javbus.com

Από την 04/12/2016. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name        javbus.waterfall
// @description Infinite scroll @ javbus.com
// @namespace   https://github.com/FlandreDaisuki
// @include     https://www.javbus.com/*
// @version     2016.12.05
// @grant       none
// ==/UserScript==

class Lock {
    constructor(d = false) {
        this.locked = d;
    }
    lock() {
        this.locked = true;
    }
    unlock() {
        this.locked = false;
    }
}

function addStyle(styleStr) {
    $('head').append(`<style>${styleStr}</style>`);
}

function fetchURL(url) {
    console.log(`fetchUrl = ${url}`);

    return fetch(url, {
            credentials: 'same-origin'
        })
        .then((response) => {
            return response.text();
        })
        .then((html) => {
            return new DOMParser().parseFromString(html, 'text/html');
        })
        .then((doc) => {
            let $doc = $(doc);
            let nextURL = `${location.protocol}//${location.host}${$doc.find('a#next').attr('href')}`;
            let elems = $doc.find('div.item');

            return {
                nextURL,
                elems
            };
        });
}

function* fetchSync(urli) {
    let url = urli;
    do {
        yield new Promise((resolve, reject) => {
            if (mutex.locked) {
                reject();
            } else {
                mutex.lock();
                resolve();
            }
        }).then(() => {
            return fetchURL(url).then(info => {
                url = info.nextURL;
                return info.elems;
            });
        }).then(elems => {
            mutex.unlock();
            return elems;
        }).catch((err) => {
            // Locked!
        });
    } while (url);
}

function appendElems() {
    let nextpage = pagegen.next();
    if (!nextpage.done) {
        nextpage.value.then(elems => {
            $('#waterfall').append(elems);
        });
    }
    return nextpage.done;
}

function xbottom(elem, limit) {
    return (elem.getBoundingClientRect().top - $(window).height()) < limit;
}

function end() {
    console.info('The End');
    $(document).off('scroll');
    $(document).off('wheel');
}

function scroll() {
    if (xbottom(anchor, 500) && appendElems()) {
        end();
    }
}

function wheel() {
    if (xbottom(anchor, 1000) && appendElems()) {
        end();
    }
}

const pagegen = fetchSync(location.href);
const anchor = $('.pagination')[0];
const mutex = new Lock();

if ($('div.item').length) {
    $(document).on('scroll', scroll);
    $(document).on('wheel', wheel);
    $('div.item').remove();
    appendElems();

    addStyle(`
    #waterfall {
        height: initial !important;
        width: initial !important;
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
    }
    #waterfall .item.item {
        position: relative !important;
        top: initial !important;
        left: initial !important;
        float: none;
        flex: 25%;
    }
    #waterfall .movie-box {
        width: initial !important;
        display: flex;
    }
    #waterfall .movie-box .photo-frame {
        overflow: visible;
    }`);
}