coursera Interactive Transcript modifier

a coursera Interactive Transcript modifier

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);