XHamster Mobile Tweaks

Remove promo messages, allow links to open in the same window, remove unwanted elements

スクリプトをインストールするには、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         XHamster Mobile Tweaks
// @namespace    http://tampermonkey.net/
// @version      1.0.5
// @description  Remove promo messages, allow links to open in the same window, remove unwanted elements
// @author       CurlyWurly
// @match        *://xhamster.com/*
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to remove elements
    function removeElements(selector) {
        const elements = document.querySelectorAll(selector);
        elements.forEach(el => el.remove());
    }

    // Function to clean thumb list
    function cleanThumbList() {
        const thumbLists = document.querySelectorAll('.thumb-list-mobile.thumb-list');
        thumbLists.forEach(list => {
            const items = list.children;
            for (let i = items.length - 1; i >= 0; i--) {
                const item = items[i];
                const hasCorrectClasses = 
                    item.classList.contains('thumb-list-mobile-item') && 
                    item.classList.contains('thumb-list-mobile-item--type-video');
                
                if (!hasCorrectClasses) {
                    item.remove();
                }
            }
        });
    }

    // Function to clean layout bottom section
    function cleanLayoutBottom() {
        const layoutBottom = document.querySelector('[data-role="layout-bottom"]');
        if (layoutBottom) {
            const categoriesList = layoutBottom.querySelector('#type_categories_list');
            const pagination = layoutBottom.querySelector('.mobile-pagination');
            
            // Remove all children except pagination and categories list
            Array.from(layoutBottom.children).forEach(child => {
                if (child !== categoriesList && child !== pagination) {
                    child.remove();
                }
            });
        }
    }

    // Function to modify links
    function modifyLinks() {
        const links = document.querySelectorAll('a[target="_blank"]');
        links.forEach(link => link.setAttribute('target', '_self'));
    }

    // Create a mutation observer to handle dynamically loaded content
    const observer = new MutationObserver((mutations) => {
        removeElements('[data-role="promo-messages-wrapper"]');
        removeElements('aside');
        cleanThumbList();
        cleanLayoutBottom();
        modifyLinks();
    });

    // Start observing the document with the configured parameters
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

    // Initial cleanup
    removeElements('[data-role="promo-messages-wrapper"]');
    removeElements('aside');
    cleanThumbList();
    cleanLayoutBottom();
    modifyLinks();
})();