Suppress YouTube Playlist links

When opening a video from a playlist, strip out the parameters that make it open in a playlist UI

// ==UserScript==
// @name         Suppress YouTube Playlist links
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  When opening a video from a playlist, strip out the parameters that make it open in a playlist UI
// @license MIT
// @author       Igor Makarov
// @match        *://*.youtube.com/playlist*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @require      https://code.jquery.com/jquery-latest.js
// ==/UserScript==

var hrefsCount = 0;
function modifyLinks() {
    let hrefs = $('a');
    if (hrefs.length == hrefsCount) {
        return;
    }
    hrefsCount = hrefs.length;
    hrefs.each(function() {
        let href = $(this).attr('href');
        if (!href) {
            return;
        }
        // console.log(`href: ${href}`);
        let url = new URL(href, document.location);
        if (url.searchParams && url.searchParams.has('list') && url.searchParams.has('index')) {
            url.searchParams.delete('list');
            url.searchParams.delete('index');
            $(this).attr('href', url);
            // console.log(`url: ${url}`);
        }
    });
}

$(document).ready(modifyLinks);
$(document).bind("DOMSubtreeModified", modifyLinks);