AsianSister.com Quick preview on homepage

Allows to Quick preview image collections on Homepage

Verze ze dne 08. 06. 2020. Zobrazit nejnovější verzi.

// ==UserScript==
// @name:pl         AsianSister.com Szybki podgląd na strone głównej
// @name:en         AsianSister.com Quick preview on homepage
// @name            AsianSister.com Quick preview on homepage
// @namespace       http://tampermonkey.net/
// @version         1.1
// @description:en  Allows to Quick preview image collections on Homepage
// @description:pl  Umożliwia szybki podgląd kolecji obrazów na stronie głównej
// @author          TheUnsleepingAlchemist
// @include         /https?:\/\/asiansister.com\/(tag.|search.|_page[0-9]?).+/
// @match           https://asiansister.com/
// @grant           GM_addStyle
// @run-at          document-idle
// @noframes
// @description     Allows to Quick preview image collections on Homepage
// ==/UserScript==

(function() {
    'use strict';
    //init varables
    let collections = [],
        collectionsList = [],
        images = document.querySelectorAll(".imageBox img"),
        currentId = 0,
        imageQuality = "lq"; //imageQuality represent quality of presented image possible options are "lq" and "hq", the last one is not recommended if you haven't good network connection
    //adding necessary CSS
    GM_addStyle(`.viewCountBox {pointer-events: none}`)
    //scraping image from links
    document.querySelectorAll(".itemBox a").forEach((link,index) => {
        let xhr = new XMLHttpRequest();
        xhr.responseType = "document"
        collectionsList.push({collId: +link.href.match(/.+_([0-9]+)_.+/)[1], id: index})
        xhr.addEventListener("load", function() {
            if (xhr.status === 200) {
                let request = xhr.response,
                    output = {id: +xhr.responseURL.match(/.+_([0-9]+)_.+/)[1], images: []}
                request.querySelectorAll(".lazyload.showMiniImage").forEach(el => output.images.push(el.dataset.src))
                collections.push(output)
                let collId = collectionsList.filter(el => el.collId === output.id);
                if (collId.length === 1) document.querySelectorAll('.viewCountBox')[collId[0].id].innerHTML = "✔  " + document.querySelectorAll('.viewCountBox')[collId[0].id].innerHTML
                if (collections.length === 40) {collections.sort((a, b) => a.id < b.id ? 1 : -1); console.log(collections)}

            }
        });
        xhr.open("GET", link.href, true);
        xhr.send();
    })
    //adding events
    images.forEach(image => {
        image.addEventListener('mouseenter', enterImgTrue);
        image.addEventListener('mousemove', hoverImgTrue);
        image.addEventListener('mouseleave', leaveImgTrue);
    })
    //functions
    function hoverImgTrue(e) {
        let distance = e.clientY - this.y, //calculating distance from top
            id = collections.findIndex(el => el.id === currentId);
        if (id === -1) return;
        let step = this.height / collections[id].images.length, //calculating amount of steps
            target = Math.round(distance/step); //pointing single image
        if (collections.length > 0 && imageQuality === "hq") this.src = `https://asiansister.com/${collections[id].images[target].slice(0,-6)}.jpg`
        if (collections.length > 0 && imageQuality === "lq") this.src = `https://asiansister.com/${collections[id].images[target]}`
    }
    function enterImgTrue() {
        currentId = +this.parentElement.parentElement.href.match(/.+_([0-9]+)_.+/)[1]
    }
    function leaveImgTrue() {
        currentId = 0;
        this.src = this.dataset.src;
    }
})();