Greasy Fork is available in English.

Flickr - AUTO Video Play / Replay v.5

Video Auto Play and Replay - by IA DuckDuckDo (Adaptation for Gm "Utags")

  1. // ==UserScript==
  2. // @name Flickr - AUTO Video Play / Replay v.5
  3. // @version v.6
  4. // @description Video Auto Play and Replay - by IA DuckDuckDo (Adaptation for Gm "Utags")
  5. // @icon https://external-content.duckduckgo.com/ip3/blog.flickr.net.ico
  6. // @namespace https://greasyfork.org/fr/users/8-decembre?sort=updated
  7. // @include https://www.flickr.com/photos/*
  8. // @exclude http*://*flickr.com/photos/*/favorites*
  9. // @exclude http*://*flickr.com/photos/*/favorites/*
  10. // @exclude http*://*flickr.com/photos/*/albums*
  11. // @grant GM_addStyle
  12. // ==/UserScript==
  13.  
  14. // Flickr - AUTO Video Play / Replay v.5 (delete Flickr - Video AUTO Play / Replay v.10 because this one is better)
  15.  
  16. // Muting the video before playing it is a good workaround for the autoplay policy issue
  17. function loadScript(url, callback) {
  18. var script = document.createElement('script');
  19. script.src = url;
  20. script.onload = callback;
  21. document.head.appendChild(script);
  22. }
  23.  
  24. loadScript('https://code.jquery.com/jquery-3.6.0.min.js', function() {
  25. (function($) {
  26. 'use strict';
  27.  
  28. console.log('Script loaded');
  29.  
  30. // Function to check if the modal is open
  31. function isModalOpen() {
  32. return $('.browser_extension_settings_container:visible, .utags_modal:visible').length > 0;
  33. }
  34.  
  35. // Wait for the video element to be loaded
  36. var videoElement = document.querySelector('.fluid.html-photo-page-scrappy-view video#video_1_html5_api');
  37. if (videoElement) {
  38. console.log('Video element found');
  39. // Set the video to auto play and loop
  40. videoElement.autoplay = true;
  41. videoElement.loop = true;
  42. videoElement.muted = true; // Mute the video
  43. videoElement.volume = 0.5;
  44.  
  45. console.log('Auto-play and loop properties set');
  46.  
  47. // Add an event listener to play the video when the user interacts with it
  48. videoElement.addEventListener('click', function() {
  49. if (!isModalOpen()) {
  50. this.play();
  51. }
  52. });
  53.  
  54. // Add an event listener to replay the video when it ends
  55. videoElement.addEventListener('ended', function() {
  56. if (!isModalOpen()) {
  57. this.play();
  58. }
  59. });
  60.  
  61. // Add an event listener to handle volume control
  62. videoElement.addEventListener('volumechange', function() {
  63. this.muted = false;
  64. });
  65.  
  66. // Play the video
  67. if (!isModalOpen()) {
  68. videoElement.play();
  69. }
  70.  
  71. console.log('Video played');
  72. } else {
  73. console.log('Video element not found');
  74.  
  75. // If the video element is not found, wait for it to be loaded
  76. var intervalId = setInterval(function() {
  77. if (isModalOpen()) {
  78. return;
  79. }
  80. var videoElement = document.querySelector('.fluid.html-photo-page-scrappy-view video#video_1_html5_api');
  81. if (videoElement) {
  82. console.log('Video element found after interval');
  83.  
  84. // Set the video to auto play and loop
  85. videoElement.autoplay = true;
  86. videoElement.loop = true;
  87. videoElement.muted = true; // Mute the video
  88. videoElement.volume = 0.5;
  89.  
  90. console.log('Auto-play and loop properties set after interval');
  91.  
  92. // Add an event listener to play the video when the user interacts with it
  93. videoElement.addEventListener('click', function() {
  94. if (!isModalOpen()) {
  95. this.play();
  96. }
  97. });
  98.  
  99. // Add an event listener to replay the video when it ends
  100. videoElement.addEventListener('ended', function() {
  101. if (!isModalOpen()) {
  102. this.play();
  103. }
  104. });
  105.  
  106. // Add an event listener to handle volume control
  107. videoElement.addEventListener('volumechange', function() {
  108. this.muted = false;
  109. });
  110.  
  111. // Play the video
  112. if (!isModalOpen()) {
  113. videoElement.play();
  114. }
  115.  
  116. console.log('Video played after interval');
  117.  
  118. // Clear the interval
  119. clearInterval(intervalId);
  120. }
  121. }, 100);
  122. }
  123. })(null);
  124. });