Panopto Annoyances Remover

Fixes many annoyances in Panopto. Space button now always controls the video.

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Panopto Annoyances Remover
// @namespace    http://github.com/jaytohe/
// @version      1.2.0
// @description  Fixes many annoyances in Panopto. Space button now always controls the video.
// @author       jaytohe
// @match        https://*.panopto.eu/Panopto/Pages/Viewer.aspx?id=*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';
    const BlackListIDs = ['quickRewindButton','quickFastForwardButton','volumeControl', 'captionsButton', 'playButton', 'playSpeedButton', 'qualityButton', 'captionStyleOptions'];

    function checkID(val) {
     if (typeof val !== 'undefined') {
         const thumb_regex = /thumbnail\d+thumbnailList/g;
         const event_regex = /^event\d+$/g;
         const transcript_regex = /^UserCreatedTranscript-\d+$/g;
        if ( BlackListIDs.includes(val)
            || thumb_regex.test(val)
            || event_regex.test(val)
            || transcript_regex.test(val)
           ) {
                 return true;
        }
     }
     return false;
    }
    if (EventTarget.prototype.original_addEventListener == null) {
        EventTarget.prototype.original_addEventListener = EventTarget.prototype.addEventListener;
        EventTarget.prototype.addEventListener =function override_listener(typ, fn, opt) {

            if (checkID(this.id) && typ === 'keydown') {
                const tmp_func = function(e) {
                    const original = fn;
                    if (e.keyCode === 32) {
                        e.stopImmediatePropagation();
                        e.preventDefault(); //prevent scrolling of sidebar.
                        document.getElementById('playButton').click();
                        return;
                    }
                    original(e);
                }
                this.original_addEventListener(typ, tmp_func, opt);
            }

            this.original_addEventListener(typ, fn, opt);
        }
        }
})();