Last active
May 6, 2019 12:58
-
-
Save elysiumeproto/b5b3f528699f58af4b47b83005790c83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name SA Video Helper | |
// @namespace https://forums.somethingawful.com/ | |
// @include https://forums.somethingawful.com/* | |
// @description Sets embedded video size caps, auto-enables controls, embeds webms | |
// @author Elysiume | |
// @version 1.0.0 | |
// @updateURL https://gist.github.com/elysiumeproto/b5b3f528699f58af4b47b83005790c83/raw/somethingAwfulVideoHelper.user.js | |
// @downloadURL https://gist.github.com/elysiumeproto/b5b3f528699f58af4b47b83005790c83/raw/somethingAwfulVideoHelper.user.js | |
// ==/UserScript== | |
const styleAnchorId = "styleAnchor_c909cf7a-62a0-4c45-928b-e62703e1def2"; | |
window.addEventListener("load", function() { | |
// Enable controls for other videos. | |
$("video").attr("controls", "controls"); | |
// Pull in every <a> tag | |
$('a').filter(function() { | |
// Filter it down to just the ones that are a pure link to a webm (hypothetically) | |
return this.text.endsWith('.webm') && this.href.endsWith('.webm'); | |
}).each(function() { | |
activeWebm = $(this).attr("href"); | |
console.log('Replacing the webm link for ' + activeWebm + '.'); | |
// And replace them with an embedded video | |
$(this).replaceWith('<video autoplay loop controls><source src="' + activeWebm + '" type="video/webm"></video>'); | |
}); | |
}, false); | |
function addStyle(css) { | |
// We need to create an anchor element that we can attach styles to. Check if it already exists to avoid creating multiples. | |
const style = document.getElementById(styleAnchorId) || (function() { | |
// We want a style-type element with a unique enough ID that it hopefully isn't conflicting with something. | |
const style = document.createElement('style'); | |
style.type = 'text/css'; | |
style.id = styleAnchorId; | |
document.head.appendChild(style); | |
return style; | |
})(); | |
const sheet = style.sheet; | |
sheet.insertRule(css, (sheet.rules || sheet.cssRules || []).length); | |
}; | |
addStyle("video { max-height: 750px; max-width: 100%; } "); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment