Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==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: 650px; max-width: 100%; } ");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement