Skip to content

Instantly share code, notes, and snippets.

@jizusun
Created April 4, 2020 07:30
Show Gist options
  • Save jizusun/ffb6b0ef199a2599c3e66fc9f42cff13 to your computer and use it in GitHub Desktop.
Save jizusun/ffb6b0ef199a2599c3e66fc9f42cff13 to your computer and use it in GitHub Desktop.
GreasyMonkey script - Coursera subtitles(outside the video)
// ==UserScript==
// @name Coursera subtitles(outside the video)
// @description Coursera subtitles outside the video.
// @namespace http://tampermonkey.net/
// @version 0.2
// @author 木杉, sunjizu@gmail.com
// @include http://www.coursera.org/*
// @include https://www.coursera.org/*
// @grant none
// @run-at document-end
// ==/UserScript==
(function () {
const contentStyle = `
color: black;
font-size: 18px;
line-height: 25px;
background: beige;
padding: 12px;
`;
const content = document.createElement("div");
content.style.cssText = contentStyle;
function main(target, panel) {
panel.style.justifyContent = "center";
if (target && panel && document.querySelector("video")) {
const options = {
attributes: true,
attributeFilter: ["class"],
childList: true,
subtree: true
};
const mb = new MutationObserver(() => {
const active = target.querySelector(".active");
content.innerHTML = active.innerHTML;
});
mb.observe(target, options);
}
}
const interval = setInterval(() => {
const target = document.querySelector(".rc-Transcript");
const panel = document.querySelector(".rc-VideoToolbar.horizontal-box.align-items-spacebetween");
if (target && panel && !panel.contains(content) ) {
panel.innerHTML = "";
panel.append(content);
main(target, panel);
}
}, 1000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment