alenga / Last.fm PRO adblock

// ==UserScript==
// @name        Last.fm PRO adblock
// @namespace   Violentmonkey Scripts
// @match       https://www.last.fm/*
// @grant       none
// @icon        https://www.google.com/s2/favicons?domain=last.fm
// @version     1.0
// @author      Alenga
// @description -
// @license     GPL-3.0-only
// ==/UserScript==

/*
    GPL-3.0 License

    Copyright (C) [year] [your name]

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

(function() {
    'use strict';

    // Function to remove elements by CSS selector
    const removeElements = (selector) => {
        const elements = document.querySelectorAll(selector);
        elements.forEach((element) => {
            element.remove();  // Removes the element from the DOM
        });
    };

    // Function to remove specific blocks by their selectors
    const removeBlocks = () => {
        removeElements('.buffer-2');
        removeElements('.secondary-nav-item--events');
        removeElements('.play-this-track-playlink--itunes');
        removeElements('.resource-external-link--apple-music');
        removeElements('.subscribe-cta');
        removeElements('.secondary-nav-item-link--active');
        removeElements('.listening-report-row.listening-report-row--centered.listening-report-row--upsell');
        removeElements('.mpu-subscription-upsell');
        removeElements('.auth-dropdown-menu-item.auth-dropdown-pro-text');

        // Add more selectors here if needed
    };

    // MutationObserver to watch for changes in the DOM (e.g., new content is added dynamically)
    const observer = new MutationObserver(() => {
        // When new content is added or the page is updated, remove unwanted blocks
        removeBlocks();
    });

    // Start observing the body of the document for added child elements
    observer.observe(document.body, { childList: true, subtree: true });

    // Initial call to remove elements when the page first loads
    removeBlocks();
})();