|
// ==UserScript== |
|
// @name Dropout auto subtitles |
|
// @version 0.1 |
|
// @description enable subtitles by default in dropout.tv |
|
// @author @[email protected] |
|
// @match *://embed.vhx.tv/videos/* |
|
// @icon data:image/gif;base64,R0lGODdhEAAQAPUAAAAAIAACIQAAH25lJ6aZLX50KEA8IzEvI4+EKt3MNv/0PbmrMA8UIm1kJ+PRNtHBNPPgOaibLm5mJ+vZOAAAHIqAKujWN0RAJDw5I4V6KYZ8KSwrIqSXLcKzMQ4TIo6DKqyfLgYOIbepMPXiOp2RLAAAGEdDJP/3Poh+KWBZJf/6Pv/8Psq6MpeMK9jHNci4Ms++M9DAM1ZQJYZ7KfDdOezaOO7bOOTSN7anL0ZBJCooIgYOIslFJslFJslFJslFJiH5BAEAADwALAAAAAAQABAAAAZ+QIBwSCwaj0hAgCgQGJuAAWo6LRQN0wPixD0pTgvGsMGdch0PCDcylJRRXA4FdTs5LkJMRrOBn+QAHSc0GkIeTQIfawEhOCcjKEJ+KBpcJCU5CScWKZIqKxqVJy8tLgoKL0MoMDChXV4nCTJHGTYWFhMJOHhHOqGhO0nCw0dBADs= |
|
// @grant none |
|
// @run-at document-start |
|
// ==/UserScript== |
|
|
|
|
|
(function() { |
|
'use strict'; |
|
|
|
const li_listeners = []; |
|
|
|
const r = /english/i; |
|
|
|
function activateCC() |
|
{ |
|
console.log("Found " + li_listeners.length + " entries"); |
|
for (var i = 0; i < li_listeners.length; ++i) |
|
{ |
|
// Get the label with the text. We will be looking for one that has the text "english" in it (it seems it's usually called "English CC", but just in case) |
|
var span = li_listeners[i].target.querySelector("span"); |
|
if (span && r.test(span.textContent)) |
|
{ |
|
console.log("Clicking " + span.textContent); |
|
// Just simulate a click on the button, this should enable the english subtitles |
|
li_listeners[i].target.click(); |
|
return; |
|
} |
|
} |
|
} |
|
|
|
var timeout = null; |
|
|
|
// Override the addEventListener to be able to catch when the buttons are set up |
|
const orig = EventTarget.prototype.addEventListener; |
|
EventTarget.prototype.addEventListener = function(...args) { |
|
if (this instanceof HTMLElement && args[0] == "click" && this.tagName.toLowerCase() == "li") { |
|
// A click event for a <li> tag was created, let's add it to the list of listeners to check later |
|
//console.log("Added click listener for " + this.getAttribute("class")); |
|
li_listeners.push({ |
|
type: args[0], |
|
fn: args[1], |
|
target: this, |
|
}); |
|
|
|
// Clear the timeout if it's already running |
|
if (timeout !== null) |
|
{ |
|
window.clearTimeout(timeout); |
|
} |
|
// Set a timeout to check the list of buttons in a second, to allow it to finish everything up |
|
timeout = window.setTimeout(function() { timeout = null; activateCC();}, 1000); |
|
} |
|
// Call the original addEventListener function |
|
return orig.apply(this, args); |
|
}; |
|
|
|
})(); |