thomper / Disable Youtube autoplay

// ==UserScript==
// @namespace    http://ontbee.com/gmscripts
// @name         Disable Youtube autoplay
// @description  Disable Youtube's autoplay setting by checking if it's enabled every 10 seconds and clicking the button if so.
// @author       thomper
// @copyright    2020, thomper (https://openuserjs.org/users/thomper)
// @license      MIT
// @version      1.1
// @include      https://www.youtube.com/*
// @grant        none
// ==/UserScript==

// ==OpenUserJS==
// @author       thomper
// ==/OpenUserJS==

(function() {
    'use strict';

    function toggleAutoplayIfOn() {
        let autoplayButton = document.getElementsByClassName('ytp-autonav-toggle-button')[0];
        let autoplayEnabled = autoplayButton && autoplayButton.getAttribute('aria-checked') === 'true';
        if (autoplayEnabled) {
            console.log("Greasemonkey script 'Disable Youtube autoplay' will now try to toggle autoplay off.");
            autoplayButton.click();
        }
    }

    toggleAutoplayIfOn();
    setInterval(toggleAutoplayIfOn, 10000);
})();