coursera Interactive Transcript modifier

a coursera Interactive Transcript modifier

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         coursera Interactive Transcript modifier
// @namespace    http://tampermonkey.net/
// @version      0.1.5
// @description  a coursera Interactive Transcript modifier
// @match        https://www.coursera.org/learn/*
// @grant        none
// @home-url https://greasyfork.org/en/scripts/408858-cousera-interactive-transcript-modifier
// @homepageURL https://greasyfork.org/en/scripts/408858-cousera-interactive-transcript-modifier
// @author LiAlbert
// @license MIT 
// ==/UserScript==
var flag = 0


function changeSub() {
    if (flag == 0) {
        var activePhrase = document.querySelector('.rc-Phrase.active');
        if (activePhrase) {
            document.querySelector('.rc-Transcript').style.display = 'none';
            var header = document.querySelector(".rc-ItemHeader");
            if(header) header.parentElement.removeChild(header);

            document.querySelector('.ItemPageLayout_container').style.top = 0;
            document.querySelector('.ItemPageLayout_container').style.height = "100%";

            var div = document.createElement('div');
            div.id = 'currentsub'
            if (activePhrase) div.textContent = activePhrase.textContent
            var video = document.querySelector('.video-container');
            if (video == null) {
                video = document.querySelector('.video-main-player-container');
                document.querySelector('.video-name').style.display = 'none';
            }
            video.parentElement.insertBefore(div, video.nextSibling);

            div.style.textAlign = "center";
            div.style.fontSize = "40px";
            div.style.marginTop = "10px";
            div.style.lineHeight = "41px";
            div.style.height = "82px";
            div.style.fontFamily = "Times New Roman";
            div.style.fontWeight = "bold";
            var player = document.querySelector('video');
            div.onmouseover = function () {
                player.pause();
                div.onmouseout = function () { player.play(); };
            };
            div.onmouseout = function () { player.play(); };
            div.onclick = function () {
                var text = window.getSelection().toString();
                navigator.clipboard.writeText(text).then(function () {
                    console.log('Async: Copying ' + text + ' to clipboard was successful!');
                }, function (err) {
                    console.error('Async: Could not copy text: ', err);
                });
                div.onmouseout = function () { };
            };

            player.onkeypress = function (event) {
                var x = event.keyCode;
                if (x == 37) { player.pause(); player.currentTime = player.currentTime - 0.1; player.play(); }
                if (x == 39) { player.pause(); player.currentTime = player.currentTime + 0.1; player.play(); }
            }
            flag = 1;
        }
    }
    else {
        div = document.getElementById('currentsub');
        if (div) {
            if(div.textContent !== document.querySelector('.rc-Phrase.active').textContent)
            {
                div.textContent = document.querySelector('.rc-Phrase.active').textContent;
                if (document.querySelector('.rc-Transcript').style.display != 'none') document.querySelector('.rc-Transcript').style.display = 'none';
            }
        }
        else { flag = 0; }

    }

}
setInterval(changeSub, 30);