XHamster Mobile Tweaks

Remove promo messages, allow links to open in the same window, remove <aside> elements and widget items

As of 2024-12-04. See the latest version.

// ==UserScript==
// @name         XHamster Mobile Tweaks
// @namespace    http://tampermonkey.net/
// @version      1.0.1
// @description  Remove promo messages, allow links to open in the same window, remove <aside> elements and widget items
// @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 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');
        removeElements('.thumb-list-mobile-item--widget');
        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');
    removeElements('.thumb-list-mobile-item--widget');
    modifyLinks();
})();