Twitch - Disable empty "Featured Clips Only" page

Automatically toggles "Featured Clips Only" off if the clips page doesn't have any featured clips.

  1. // ==UserScript==
  2. // @name Twitch - Disable empty "Featured Clips Only" page
  3. // @version 1.02
  4. // @description Automatically toggles "Featured Clips Only" off if the clips page doesn't have any featured clips.
  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. // This script is no longer maintained. Please install FFZ if you'd like the same functionality.
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Flag to track if the button has been clicked during this page navigation
  18. let buttonClicked = false;
  19.  
  20. // Function to check if the SVG element exists on the page
  21. function svgExists() {
  22. const svgSrc = 'https://static-cdn.jtvnw.net/c3-vg/pinned-clips/clip.svg';
  23. const svgElements = document.querySelectorAll(`img[src="${svgSrc}"]`);
  24. const svgFound = svgElements.length > 0;
  25.  
  26. // Reset the buttonClicked flag when SVG disappears
  27. if (!svgFound) {
  28. buttonClicked = false;
  29. }
  30.  
  31. return svgFound;
  32. }
  33.  
  34. // Function to click the button
  35. function clickButton() {
  36. const button = document.getElementById('featured-clips-toggle');
  37. if (button && !buttonClicked) {
  38. button.click();
  39. buttonClicked = true; // Set the flag to true after clicking
  40. console.log('Button clicked.');
  41. }
  42. }
  43.  
  44. // Watch for changes in the DOM using MutationObserver
  45. const observer = new MutationObserver(function(mutationsList) {
  46. for (const mutation of mutationsList) {
  47. if (mutation.type === 'childList' && svgExists()) {
  48. clickButton();
  49. // The observer will keep monitoring for changes
  50. }
  51. }
  52. });
  53.  
  54. // Start observing changes in the entire document
  55. observer.observe(document, { childList: true, subtree: true });
  56.  
  57. })();
  58.  
  59. // This script is no longer maintained. Please install FFZ if you'd like the same functionality.