Autoplay & Loop on Youtube (PC/Mobile)

You can autoplay and loop on youtube in all device.

As of 2020-02-16. See the latest version.

// ==UserScript==
// @name         Autoplay & Loop on Youtube (PC/Mobile)
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  You can autoplay and loop on youtube in all device.
// @author       Solitary Walker
// @match        https://*.youtube.com/*
// @grant        none
// ==/UserScript==

/*You only change follow flags if you change */
const AUTOPLAY = true;
const LOOP = true;
/******************************/

(function() {
    'use strict';
    const playButton = document.getElementsByClassName("ytp-cued-thumbnail-overlay-image")[0];
    if(playButton != null && AUTOPLAY) {
        playButton.click();
    }
    const video = document.getElementsByTagName("video")[0];
    if(video != null) {
        video.autoplay = AUTOPLAY;
        video.loop = LOOP;
        video.addEventListener("loadstart", function(event){
            event.target.autoplay = AUTOPLAY;
            event.target.loop = LOOP;
        });
    }
})();