YouTube - Add "Stop Video" Button

Adds a 'Stop Video' button below the video

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name            YouTube - Add "Stop Video" Button
// @namespace       https://greasyfork.org/en/users/321-joesimmons
// @description     Adds a 'Stop Video' button below the video
// @include         http://*.youtube.com/watch*v=*
// @include         https://*.youtube.com/watch*v=*
// @include         http://youtube.com/watch*v=*
// @include         https://youtube.com/watch*v=*
// @include         http://youtube.com/user/*
// @include         https://youtube.com/user/*
// @include         http://youtube.com/channel/*
// @include         https://youtube.com/channel/*
// @include         http://*.youtube.com/user/*
// @include         https://*.youtube.com/user/*
// @include         http://*.youtube.com/channel/*
// @include         https://*.youtube.com/channel/*
// @copyright       JoeSimmons
// @version         1.1.0
// @license         GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// @require         https://greasyfork.org/scripts/2104-youtube-button-container-require/code/YouTube%20-%20Button%20Container%20(@require).js?version=5493
// @grant           GM_addStyle
// ==/UserScript==

/* CHANGELOG

    1.1.0 (12/13/2013)
        - changed license to GPLv3

    1.0.9 (12/13/2013)
        - started using my new @require for adding buttons to the page

    1.0.8 (12/11/2013)
        - started adding the stop button to a div under the movie player
            so other scripts can use that space to add buttons to also

    1.0.7 (11/23/2013)
        - fixed something I missed in 1.0.6

    1.0.6 (11/23/2013)
        - adapted to site change

    1.0.5 (9/6/2013)
        - made it work on user/channel pages

    1.0.4 (9/1/2013)
        - made it support the YouTube 'red bar' feature

    1.0.3 (8/31/2013)
        - included https pages

    1.0.2 (8/30/2013)
        - now supports native Chrome & Opera

    1.0.1
        - made it more cross-browser compatible

    1.0.0
        - created

*/

(function () {
    'use strict';

    var verif = /youtube\.com\/((watch\?[a-zA-Z]+=)|(user|channel))/,
        button_id = 'movie_stop_button';

    function run(t) {
        var s = document.createElement('script');
            s.innerHTML = t;
        document.body.appendChild(s);
        document.body.removeChild(s);
    }

    function stopVideo() {
        run('' +
            '(function () {' +
                'var player = document.querySelector("#c4-player, #movie_player");' +
                'if (player.stopVideo) {' +
                    'player.stopVideo();' +
                '} else if (player.pauseVideo) {' +
                    'player.pauseVideo();' +
                '} else if (player.pause) {' +
                    'player.pause();' +
                '}' +
            '}());' +
        '');
    }

    function addButton() {
        var button = document.getElementById(button_id);

        if (button == null) {
            addButtonToContainer('Stop Video', stopVideo, button_id);
        }
    }

    // make sure the page is not in a frame
    if (window !== window.top) { return; }

    window.setInterval(addButton, 1000);

}());