Hide Watched Videos on PH

Hides watched videos on xHamster and adds a toggle button to turn this feature on/off. Saves state to cookies.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Hide Watched Videos on PH
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Hides watched videos on xHamster and adds a toggle button to turn this feature on/off. Saves state to cookies.
// @author       Your Name
// @match        *://*.pornhub.com/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // Create floating toggle button
    const button = document.createElement('button');
    button.textContent = 'Watched On';
    button.style.position = 'fixed';
    button.style.top = '60px';
    button.style.right = '10px';
    button.style.zIndex = '9999';
    button.style.padding = '10px 15px';
    button.style.backgroundColor = '#FF5722';
    button.style.color = 'white';
    button.style.border = 'none';
    button.style.borderRadius = '5px';
    button.style.cursor = 'pointer';
    button.style.fontSize = '14px';
    document.body.appendChild(button);

    // Helper functions for working with cookies
    function setCookie(name, value, days) {
        const expires = new Date();
        expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000);
        document.cookie = `${name}=${value};expires=${expires.toUTCString()};path=/`;
    }

    function getCookie(name) {
        const cookies = document.cookie.split('; ');
        for (const cookie of cookies) {
            const [key, value] = cookie.split('=');
            if (key === name) return value;
        }
        return null;
    }

    // Initialize state from cookies or default
    let hideWatched = getCookie('hideWatched') === 'true';

    // Update button text based on state
    function updateButtonText() {
        button.textContent = hideWatched ? 'Watched On' : 'Watched Off';
    }

    // Function to hide/show watched videos
    function toggleWatchedVideos() {
        const videoCards = document.querySelectorAll('li.pcVideoListItem.js-pop.videoblock');
        videoCards.forEach((card) => {
            const watchedBadge = card.querySelector('div.bgShadeEffect.hideOnPreview.watchedVideo');
            if (watchedBadge) {
                card.style.display = hideWatched ? '' : 'none';
            }
        });
    }

    // Add click event to the button
    button.addEventListener('click', () => {
        hideWatched = !hideWatched;
        setCookie('hideWatched', hideWatched, 30); // Save state for 30 days
        updateButtonText();
        toggleWatchedVideos();
    });

    // Initial setup
    updateButtonText();
    toggleWatchedVideos();

    // Observe changes to dynamically loaded content
    const observer = new MutationObserver(() => {
        toggleWatchedVideos();
    });

    observer.observe(document.body, { childList: true, subtree: true });
})();