YouTube | Stop Autoplay

Disabled automatic playback ("Autoplay") of YouTube videos.

As of 22.07.2018. See ბოლო ვერსია.

// ==UserScript==
// @name            YouTube | Stop Autoplay
// @namespace       de.sidneys.greasemonkey
// @homepage        https://gist.githubusercontent.com/sidneys/0a5bea36f989d445cdfbd776023a94ca/raw/
// @version         1.0.0
// @description     Disabled automatic playback ("Autoplay") of YouTube videos.
// @author          sidneys
// @icon            https://www.youtube.com/favicon.ico
// @include         http*://www.youtube.com/*
// @require         https://greasyfork.org/scripts/38888-greasemonkey-color-log/code/Greasemonkey%20%7C%20Color%20Log.js
// @run-at          document-end
// ==/UserScript==

/**
 * @external
 */
/* global DEBUG */

/**
 * @default
 * @constant
 */
DEBUG = false


/**
 * @default
 * @constant
 */
const urlPath = '/watch'


/**
 * Stop YouTube Video Player
 * @param {Element} element - YouTube Video Player
 */
let stopPlayback = () => {
    console.debug('stopPlayback')

    const player = document.querySelector('.html5-video-player')

    player.stopVideo()
    player.showControls()

    // DEBUG
    console.debug('playerState:', player.getPlayerState())
    console.debug('videoTitle:', player.getVideoData().title)
}


/**
 * Init
 */
let init = () => {
    console.info('init')

    // Check URL
    if (!location.pathname.startsWith(urlPath)) { return }

    stopPlayback()
}


/**
 * @listens window:Event#load
 */
window.addEventListener('load', () => {
    console.debug('window#load')

    init()
})

/**
 * @listens window:Event#spfdone
 */
window.addEventListener('spfdone', () => {
    console.debug('window#spfdone')

    init()
})