XHamster Mobile Tweaks

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         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();
})();