Advertisement
Guest User

SA forum vid script

a guest
Oct 17th, 2019
1,488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. // ==UserScript==
  2. // @name SA Video Helper
  3. // @namespace https://forums.somethingawful.com/
  4. // @include https://forums.somethingawful.com/*
  5. // @description Sets embedded video size caps, auto-enables controls, embeds webms
  6. // @author Elysiume
  7. // @version 1.0.0
  8. // @updateURL https://gist.github.com/elysiumeproto/b5b3f528699f58af4b47b83005790c83/raw/somethingAwfulVideoHelper.user.js
  9. // @downloadURL https://gist.github.com/elysiumeproto/b5b3f528699f58af4b47b83005790c83/raw/somethingAwfulVideoHelper.user.js
  10. // ==/UserScript==
  11.  
  12. const styleAnchorId = "styleAnchor_c909cf7a-62a0-4c45-928b-e62703e1def2";
  13.  
  14. window.addEventListener("load", function() {
  15. // Enable controls for other videos.
  16. $("video").attr("controls", "controls");
  17.  
  18. // Pull in every <a> tag
  19. $('a').filter(function() {
  20. // Filter it down to just the ones that are a pure link to a webm (hypothetically)
  21. return this.text.endsWith('.webm') && this.href.endsWith('.webm');
  22. }).each(function() {
  23. activeWebm = $(this).attr("href");
  24. console.log('Replacing the webm link for ' + activeWebm + '.');
  25. // And replace them with an embedded video
  26. $(this).replaceWith('<video autoplay loop controls><source src="' + activeWebm + '" type="video/webm"></video>');
  27. });
  28. }, false);
  29.  
  30. function addStyle(css) {
  31. // We need to create an anchor element that we can attach styles to. Check if it already exists to avoid creating multiples.
  32. const style = document.getElementById(styleAnchorId) || (function() {
  33. // We want a style-type element with a unique enough ID that it hopefully isn't conflicting with something.
  34. const style = document.createElement('style');
  35. style.type = 'text/css';
  36. style.id = styleAnchorId;
  37. document.head.appendChild(style);
  38. return style;
  39. })();
  40. const sheet = style.sheet;
  41. sheet.insertRule(css, (sheet.rules || sheet.cssRules || []).length);
  42. };
  43.  
  44. addStyle("video { max-height: 650px; max-width: 100%; } ");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement