Skip to content

Instantly share code, notes, and snippets.

@elysiumeproto
Last active May 6, 2019 12:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elysiumeproto/b5b3f528699f58af4b47b83005790c83 to your computer and use it in GitHub Desktop.
Save elysiumeproto/b5b3f528699f58af4b47b83005790c83 to your computer and use it in GitHub Desktop.
// ==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