EroMe - Sort by Views Link (Inside Page Container)

Adds a visible "Sort by Views" link just inside the #page container on EroMe profile pages to sort albums by view count descendingly.

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         EroMe - Sort by Views Link (Inside Page Container)
// @namespace    http://tampermonkey.net/
// @version      1.6
// @description  Adds a visible "Sort by Views" link just inside the #page container on EroMe profile pages to sort albums by view count descendingly.
// @author       ChatGPT
// @match        https://www.erome.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    function parseViews(text) {
        if (!text) return 0;
        let cleaned = text.replace(/[^0-9,.KM]/g, '').replace(',', '.');
        if (cleaned.includes('K')) return parseFloat(cleaned) * 1000;
        if (cleaned.includes('M')) return parseFloat(cleaned) * 1000000;
        return parseFloat(cleaned);
    }

    function sortAlbumsByViews() {
        const container = document.querySelector('#albums');
        if (!container) return;

        const albumNodes = Array.from(document.querySelectorAll('.album'));
        const sorted = albumNodes.sort((a, b) => {
            const viewsA = parseViews(a.querySelector('.album-bottom-views')?.innerText);
            const viewsB = parseViews(b.querySelector('.album-bottom-views')?.innerText);
            return viewsB - viewsA;
        });

        sorted.forEach(album => container.appendChild(album));
        console.log('Albums sorted by most views');
    }

    function restoreOriginalOrder() {
        location.reload();
    }

    function insertSortLink() {
        const pageContainer = document.querySelector('#page');
        if (!pageContainer || document.querySelector('#sortViewsLink')) return;

        const sortLink = document.createElement('a');
        sortLink.href = '#';
        sortLink.textContent = '🔽 Sort by Views';
        sortLink.id = 'sortViewsLink';
        sortLink.style.display = 'inline-block';
        sortLink.style.margin = '20px 0';
        sortLink.style.fontSize = '16px';
        sortLink.style.fontWeight = 'bold';
        sortLink.style.color = '#e91e63';

        let sorted = false;

        sortLink.addEventListener('click', (e) => {
            e.preventDefault();
            if (!sorted) {
                sortAlbumsByViews();
                sortLink.textContent = '↩ Unsort';
            } else {
                restoreOriginalOrder();
            }
            sorted = !sorted;
        });

        pageContainer.insertBefore(sortLink, pageContainer.firstChild);
    }

    const waitForElement = (selector, callback, timeout = 10000) => {
        const start = Date.now();
        const check = () => {
            const el = document.querySelector(selector);
            if (el) callback(el);
            else if (Date.now() - start < timeout) requestAnimationFrame(check);
        };
        check();
    };

    waitForElement('#page', insertSortLink);
})();