Erome.com Improved

Infinite scroll. Filter photo albums. Show/hide photos in albums.

От 27.04.2024. Виж последната версия.

// ==UserScript==
// @name         Erome.com Improved
// @namespace    http://tampermonkey.net/
// @version      1.2
// @license      MIT
// @description  Infinite scroll. Filter photo albums. Show/hide photos in albums.
// @author       smartacephale
// @match        *://*.erome.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=erome.com
// @run-at       document-end
// @grant        none
// ==/UserScript==

const LOGO = `
⡠⢡⠨⡠⢡⠨⡠⢡⠨⡠⢡⠨⡠⢡⠨⡠⢡⠨⡠⢡⠨⡠⢡⠨⡐⠜⠔⠎⠖⠜⠔⠎⠖⠜⠔⠎⠖⠜⠔⠎⠖⠜⠔⠎⠖⠜⠔⠎⠖⠜
⣐⢂⡒⣂⢒⢂⡒⣂⢒⢂⡒⣂⢒⢂⡒⣂⢒⢂⡒⣂⢒⢂⡒⡒⡐⡍⡍⢍⢍⢍⢍⢍⢍⢍⢍⢍⢍⢍⢍⢍⢍⢍⢍⢍⢍⢍⢍⢍⢍⢍
⡆⡇⡕⡜⡜⡌⡎⡆⡇⡇⡕⡜⡜⡌⡎⡆⡇⡇⡕⡜⡜⡌⡎⡜⡜⠌⠎⠜⠔⠕⠌⠦⠱⠌⠦⠱⠌⠦⠱⠌⠦⠱⠌⠦⠱⠌⠦⠱⠌⠆
⣈⣂⣑⣈⢂⡊⣂⢒⣈⢂⡊⣂⢊⡂⣊⡐⣂⢊⡂⣑⡐⣑⢈⣂⢊⠥⢭⢱⢩⠬⠭⠬⠥⠭⠬⠥⠭⠬⠥⠭⠬⠥⠭⠬⠥⠭⠬⠥⡍⡎
⠕⡐⢔⢂⢃⡊⣂⢃⡂⣃⢊⡂⣃⢊⡂⣊⢂⡃⣊⢂⡊⣂⢃⡂⡣⡱⡡⡪⠔⡅⡇⠭⡪⠥⢍⢎⠥⢍⢎⠥⢍⢎⠥⢍⢎⠥⢍⢎⢔⠥
⡕⡕⡕⣜⢔⢎⢆⢇⢎⢆⢇⢎⢆⢇⢎⢆⢇⢎⢆⢇⢎⢆⢇⢎⢖⢐⠐⡈⠌⡐⠨⢈⠄⠅⡂⡂⠅⡁⡂⠡⢁⢂⠡⢁⢂⠡⢁⠂⡂⡁
⢳⢑⣓⡒⡇⡳⡑⡇⡳⡑⡇⡳⡑⡇⡳⡑⡇⡳⡑⡇⡳⡑⡇⡳⡱⡠⡡⢡⠡⡨⡨⠄⡅⢅⠌⡄⠥⡨⠨⡨⡠⡡⠨⢄⠅⡌⠤⡡⡨⡠
⡣⣑⢢⢑⢅⢣⢑⡑⡅⡣⣑⣑⡑⣑⢅⢣⢑⡑⡅⡣⣑⣑⡑⡅⡣⠱⠸⠌⠮⠸⠨⠪⠪⠜⠜⠬⠱⠌⠇⢕⠬⠪⠩⠪⠜⠬⠱⠱⠨⡢
⢔⠢⡃⢎⠢⠣⢒⠱⡘⢔⠢⠢⡊⠆⢎⠢⠣⡊⢆⠣⡒⠔⡢⢃⠎⢕⠝⡸⡘⢕⠍⢇⠫⢪⠱⡙⢜⠱⡙⢜⠸⡘⢍⢎⠣⡹⡘⢕⠍⢎
⢔⢑⠜⡂⢝⢘⡘⣘⢘⡐⢍⢊⠪⡑⣑⢑⡑⣑⢑⢑⡘⣘⢘⡐⢍⠦⡱⡡⡪⡢⠭⠬⡪⠬⡪⢌⢎⠬⡪⢌⢎⢜⢌⠦⡱⡡⡪⡢⠭⢌
⡢⡱⡨⣊⢆⢕⢔⡢⡱⡨⡢⡱⣑⢌⢆⡲⡨⡢⣊⢆⡪⡢⡒⡌⣆⠣⡃⠇⡣⠣⠍⢇⠣⠹⡘⠜⠜⠜⠜⠜⠜⡸⠘⢜⠸⢘⠌⠎⠍⠎
⢇⢕⢕⢢⢣⢱⢑⢌⢎⢜⢌⢎⢆⢣⢱⢸⢨⠪⡢⡱⢌⢆⢇⢇⠦⡡⡨⢨⠠⡡⡡⢡⠡⡑⠌⡌⢌⢌⢌⢌⢌⢄⠍⡄⢅⠅⢅⠍⢌⠅
⢕⢅⢇⢕⢅⢇⢕⠕⡅⡇⡕⢥⢱⢡⢣⢱⢡⢣⢱⢑⢕⠥⡱⡡⡣⢱⠸⠸⡘⡌⢎⠜⡌⢎⠕⠕⡅⢇⠅⡇⠎⢆⠇⢇⢣⠹⡨⠪⠪⠪
⡐⡑⡐⡑⡐⡑⡐⡑⢌⢂⡊⣂⢑⡐⡑⣐⢑⢐⢑⡈⡢⡑⣈⢂⡊⡎⢎⠇⡇⡎⡎⡎⢎⠖⡕⡕⡕⡕⢕⢕⠝⡔⡕⡕⢕⢕⢪⢹⠸⡙
⠕⠕⢕⠕⢕⠕⠕⠝⠜⠜⠜⠜⠜⠜⠜⠜⠜⠜⠜⠜⠜⠜⠜⠜⢌⢆⢅⢎⢔⢔⢔⢌⢆⢅⠦⢬⢰⠨⡔⢤⢱⢰⢨⢰⢡⢢⢡⢢⢱⢨
⡜⣘⢔⢅⢣⢊⢎⢪⢊⢎⢪⢊⡪⡊⡎⡪⡊⡎⡪⡊⡎⡪⣊⢪⢂⢇⠕⡅⢇⢎⠪⡢⡃⢇⠣⡣⢱⢑⠕⢕⠅⡇⢕⠱⡡⢣⠱⡑⡅⢇
⡒⡔⡲⡸⡰⡑⡆⢇⢎⢆⢣⢒⢆⢣⢪⢒⢜⢔⢕⢜⢔⢜⢔⢜⢔⠅⠇⠎⢆⠣⠱⡘⠌⢎⠪⠸⠰⠡⠣⠣⠱⠸⡘⠜⠌⠆⠇⠕⠜⠔
⢃⢃⠣⡊⡢⢃⠎⡊⢆⢃⢃⠣⡊⡪⢂⠣⡊⡢⢃⢒⠱⡘⢔⢑⠢⡣⡣⡍⡆⡇⡇⡕⡍⡆⡇⡝⡌⡇⡝⡌⡇⡇⡎⡎⡎⡕⡍⡎⡕⡕
⡕⡱⡱⢸⠰⡱⡸⢸⠰⡑⡕⢕⠜⡔⢕⠕⡜⢔⠕⡕⡱⡸⡰⡑⡕⢌⠆⢕⠡⡱⢘⢌⠪⡨⢊⢌⠪⡘⢌⠪⡨⢊⠢⡱⢘⠌⡪⡘⢌⢊
⣒⢌⢆⢣⢑⢢⠪⡂⡇⢕⢌⢆⢣⢊⢆⢣⢊⢆⢣⢊⢆⢒⢢⠱⡘⢔⠍⡜⢌⠎⡌⢆⢣⠱⡡⡱⢡⠣⡱⠱⡘⡌⢎⠜⢔⠕⡱⡘⡌⢆
⢔⢕⢜⢔⢕⠕⡕⢕⢜⢜⢔⢕⢜⢔⢕⢜⢔⢕⢪⢢⠣⡣⢣⠣⡣⡑⠕⢌⠆⡣⡑⢅⠥⠱⡨⠌⢆⠕⠜⢌⠪⡨⠢⡩⠢⡱⠨⠢⢪⠨
⢣⢊⠆⡕⢌⠎⡜⢌⢆⢕⢌⢆⠕⡌⡆⡕⠜⡌⢆⠕⡅⡣⡱⡑⢅⢣⢍⢆⢣⢱⢘⢌⢪⢱⢘⢜⢌⢪⢱⢡⠣⡪⡱⡨⡱⡸⡨⢍⢆⢣
⢪⢂⢇⠣⡣⡑⡕⡱⡨⡢⡱⡘⡌⡪⡂⢇⢣⠱⣑⢱⠡⡃⡎⢜⢸⢐⠕⡌⡪⢢⠱⡡⢣⢡⠱⡡⢪⠸⡐⡅⡣⡱⢨⠪⡨⢢⠱⡡⡱⢡
⡌⢆⢣⠱⡡⡱⡘⡌⢆⢕⠜⢌⢪⢘⢌⢎⢊⢎⢢⠱⡑⡅⡣⢣⢑⢅⢇⢪⢸⠰⡱⢸⠰⡡⡣⢱⠡⡣⡱⡘⡔⡱⡡⢣⠱⡡⡣⡱⡘⡌
⠪⡊⢆⢣⠱⡨⡢⢣⢑⢢⢃⢇⢕⠱⡨⢢⢃⢎⠢⡣⢱⢘⢌⢆⢣⢊⢆⢣⢡⠣⡪⢪⠸⡐⡕⢅⠇⡕⡌⢎⢌⢆⢣⠱⡑⡱⡨⢢⠣⡱`;
console.log(LOGO);

function togglePhotoElements(){
    Array.from(document.querySelectorAll('.media-group')).forEach(a => {
        if (!a.querySelector('.video')) {
            if (config.showPhotos) {
                $(a.parentElement).css("display", "block");
            } else {
                $(a.parentElement).css("display", "none");
            }
        }
    });
}

function hidePhotoOnlyAlbums() {
    const albumsContainers = document.querySelectorAll('#albums');
    albumsContainers.forEach(a => {
        Array.from(a.children).forEach(a => {
            if (!a.querySelector('.album-videos')) {
                if (config.showPhotoAlbums) {
                    $(a).show();
                } else {
                    $(a).hide();
                }
            }
        });
    });
}

function infiniteScrollAndLazyLoading() {
    // taken from index.html of erome mobile version
    const curPage = window.location.search.match(/page=(\d+)/);
    var next_page = (curPage ? parseInt(curPage[1]) : 1) + 1;

    var infinite = $('#page').infiniteScroll({
        path: function() {
            const { pathname, search } = window.location;
            const page = `page=${next_page}`;
            let query = "";
            if (search) {
                if (/page=/.test(search)) {
                    query = search.replace(/page=(\d+)/, () => page);
                } else {
                    query = `${search}&${page}`;
                }
            } else {
                query = `?${page}`;
            }
            console.log(pathname, query)
            return pathname + query;
        },
        append: '.page-content',
        scrollThreshold: 800
    });

    $('#page').on('append.infiniteScroll', function(event, body, path, items, response) {
        hidePhotoOnlyAlbums();
        new LazyLoad();
        scrollFix();
        next_page = next_page + 1;
        if(next_page > 50 || next_page > 50){
            infinite.destroy();
        }
    });
}

function scrollFix() {
    setTimeout(() => window.dispatchEvent(new Event('scroll')), 1000);
}

const DEFAULT_CONFIG = {
    showPhotos: false,
    showPhotoAlbums: false
};

const stored = localStorage.getItem("config");
const config = JSON.parse(stored) || DEFAULT_CONFIG;


(function() {
    'use strict';

    if (/^\/a\//.test(window.location.pathname)) {
        togglePhotoElements();
        $('#user_name').parent().append('<button id="togglePhotos" class="btn btn-pink user-hide">show/hide photos</button>');
        $('#togglePhotos').on('click', () => {
            config.showPhotos = !config.showPhotos;
            localStorage.setItem("config", JSON.stringify(config));
            togglePhotoElements();
        });
    } else {
        hidePhotoOnlyAlbums();
        infiniteScrollAndLazyLoading();
        $('.navbar-nav').append('<li><a href="#" id="togglePhotoAlbums">video only</span></a></li>');
        $('#togglePhotoAlbums').css('color', !config.showPhotoAlbums ? '#eb6395' : '#a09f9d');
        $('#togglePhotoAlbums').on('click', () => {
            config.showPhotoAlbums = !config.showPhotoAlbums;
            localStorage.setItem("config", JSON.stringify(config));
            hidePhotoOnlyAlbums();
            $('#togglePhotoAlbums').css('color', !config.showPhotoAlbums ? '#eb6395' : '#a09f9d');
        });
    }

    scrollFix();
})();