Redgifs Embed Tweaks

tweaks redgifs embed/iframe video

Mint 2023.11.18.. Lásd a legutóbbi verzió

  1. // ==UserScript==
  2. // @name Redgifs Embed Tweaks
  3. // @namespace https://greasyfork.org/pt-BR/users/821661
  4. // @match https://www.redgifs.com/ifr/*
  5. // @grant GM_registerMenuCommand
  6. // @grant GM_setValue
  7. // @grant GM_getValue
  8. // @version 0.2
  9. // @author hdyzen
  10. // @description tweaks redgifs embed/iframe video
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. 'use strict';
  16. // Autoplay state
  17. const autoplay = GM_getValue('autoplay', true);
  18. // Open state
  19. const openLink = GM_getValue('openlink', false);
  20. // Autoplay toggle
  21. function autoplayToggle() {
  22. GM_setValue('autoplay', !autoplay);
  23. location.reload();
  24. }
  25. // Open link when click on video
  26. function openLinkToggle() {
  27. GM_setValue('openlink', !openLink);
  28. location.reload();
  29. }
  30. // Prevent opening video link
  31. if (!openLink) {
  32. document.addEventListener('click', (e) => {
  33. if (!e.target.closest('.videoLink')) return;
  34. e.preventDefault();
  35. });
  36. }
  37. // Menu commands
  38. (function menuCommands() {
  39. // Autoplay
  40. const commandAutoplay = GM_registerMenuCommand('Autoplay: ON', autoplayToggle, {
  41. title: 'Click for toggle',
  42. });
  43. if (!autoplay) {
  44. GM_registerMenuCommand('Autoplay: OFF', autoplayToggle, {
  45. title: 'Click for toggle',
  46. id: commandAutoplay,
  47. });
  48. }
  49. // Open link
  50. const commandLink = GM_registerMenuCommand('Open link when click: OFF', openLinkToggle, {
  51. title: 'Click for toggle',
  52. });
  53. if (openLink) {
  54. GM_registerMenuCommand('Open link when click: ON', openLinkToggle, {
  55. title: 'Click for toggle',
  56. id: commandLink,
  57. });
  58. }
  59. })();
  60. // Mutation observer for pause video
  61. if (!autoplay) {
  62. const observer = new MutationObserver((mutations) => {
  63. mutations.forEach((mutation) => {
  64. if (mutation.type === 'childList' && mutation.target.classList.contains('routeWrapper')) {
  65. mutation.addedNodes.forEach((node) => {
  66. const video = node.querySelector('.videoLink video');
  67. if (video) {
  68. video.removeAttribute('autoplay');
  69. observer.disconnect();
  70. }
  71. });
  72. }
  73. });
  74. });
  75. observer.observe(document.body, {
  76. childList: true,
  77. subtree: true,
  78. });
  79. }
  80. })();