Skip to content

Instantly share code, notes, and snippets.

@vincekd
Created July 4, 2023 01:21
Show Gist options
  • Save vincekd/a859bdc16f784c62c53b16168b3f6a5d to your computer and use it in GitHub Desktop.
Save vincekd/a859bdc16f784c62c53b16168b3f6a5d to your computer and use it in GitHub Desktop.
Improvements to Themis bar prep website (set video speeds; turn on captions; indent outline properly)
// ==UserScript==
// @name Themis Tweaks
// @namespace https://github.com/vincekd
// @version 0.1
// @description Set video speeds; turn on captions; indent outline properly
// @author https://github.com/vincekd
// @match https://www.themisbar.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=themisbar.com
// @run-at document-end
// @grant none
// ==/UserScript==
(function() {
'use strict';
function onLoad(event, element) {
// set playback rate to 1.75/check local storage
element.playbackRate = parseFloat(window.localStorage.getItem("vkd-playback-rate") || 1.75, 10);
// turn on captions
element.parentNode.querySelector(".fp-subtitle-menu [data-subtitle-index='0']").click();
// enable fullscreen
// element.parentNode.querySelector(".fp-fullscreen").click();
// add better speeds
insertSpeeds(element);
}
function insertSpeeds(e) {
const speeds = [1.25, 1.75, 2.5];
const speedMenu = e.parentNode.querySelector(".fp-speed-menu");
speeds.forEach(speed => {
const a = document.createElement("a", {"className": ".fp-speed-menu"});
a.setAttribute("data-speed", speed);
a.textContent = speed;
const prev = Array.of(...speedMenu.querySelectorAll("a")).find(sp => parseFloat(sp.getAttribute("data-speed"), 10) >= speed);
if (!prev) {
speedMenu.appendChild(a);
} else if (parseFloat(prev.getAttribute("data-speed"), 10) !== speed) {
speedMenu.insertBefore(a, prev);
}
});
}
function setVideoSettings() {
document.querySelectorAll("video").forEach(e => {
e.addEventListener("loadeddata", event => { onLoad(event, e); }, false);
e.addEventListener("ratechange", event => {
window.localStorage.setItem("vkd-playback-rate", e.playbackRate);
}, false);
});
}
function setOutlineSettings() {
// underline/indent sub-headers
const headers = ["[0-9]+\\.", "[a-z]+\\.", "[0-9]+\\)", "[a-z]+\\)", "[ivx]+\\)"];
document.querySelectorAll("#outlineContent p").forEach(e => {
if (/^[a-zA-Z0-9]+[\)\.]\s+/.test(e.textContent.trim())) {
if (/\:$/.test(e.previousElementSibling.textContent.trim()) || (e.previousElementSibling.classList.contains("vkd-list-item") &&
/;( (and|or))?$/.test(e.previousElementSibling.textContent.trim()))) {
e.classList.add("vkd-list-item");
} else {
e.classList.add("vkd-header");
const index = headers.findIndex(reg => (new RegExp("^" + reg)).test(e.textContent.trim()));
e.classList.add("vkd-header-h" + (index + 1));
}
}
});
}
setTimeout(setOutlineSettings, 250);
setVideoSettings();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment