Twitch - Always disable "Featured Clips Only"

Automatically toggles "Featured Clips Only" off when browsing a channels clips page.

目前为 2023-08-08 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Twitch - Always disable "Featured Clips Only"
  3. // @version 1.0
  4. // @description Automatically toggles "Featured Clips Only" off when browsing a channels clips page.
  5. // @author Taizun
  6. // @match https://www.twitch.tv/*
  7. // @grant none
  8. // @license MIT
  9. // @namespace https://greasyfork.org/en/scripts/472692-twitch-always-disable-featured-clips-only
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Flag to track if the button has been clicked during this page navigation
  16. let buttonClicked = false;
  17.  
  18. // Function to check if the SVG element exists on the page
  19. function svgExists() {
  20. const svgSrc = 'https://static-cdn.jtvnw.net/c3-vg/pinned-clips/clip.svg';
  21. const svgElements = document.querySelectorAll(`img[src="${svgSrc}"]`);
  22. const svgFound = svgElements.length > 0;
  23.  
  24. // Reset the buttonClicked flag when SVG disappears
  25. if (!svgFound) {
  26. buttonClicked = false;
  27. }
  28.  
  29. return svgFound;
  30. }
  31.  
  32. // Function to click the button
  33. function clickButton() {
  34. const button = document.getElementById('featured-clips-toggle');
  35. if (button && !buttonClicked) {
  36. button.click();
  37. buttonClicked = true; // Set the flag to true after clicking
  38. console.log('Button clicked.');
  39. }
  40. }
  41.  
  42. // Watch for changes in the DOM using MutationObserver
  43. const observer = new MutationObserver(function(mutationsList) {
  44. for (const mutation of mutationsList) {
  45. if (mutation.type === 'childList' && svgExists()) {
  46. clickButton();
  47. // The observer will keep monitoring for changes
  48. }
  49. }
  50. });
  51.  
  52. // Start observing changes in the entire document
  53. observer.observe(document, { childList: true, subtree: true });
  54.  
  55. })();