Kick.com - Auto select best quality

Auto select best quality

当前为 2024-09-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Kick.com - Auto select best quality
  3. // @namespace https://greasyfork.org/en/users/1200587-trilla-g
  4. // @version 3.0
  5. // @author Trilla_G
  6. // @description Auto select best quality
  7. // @match *://kick.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=kick.com
  9. // @grant GM_addStyle
  10. // @run-at document-start
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Function to check if a quality option is selected and click it if not
  18. let checkQuality = (quality) => {
  19. // Select all divs with the given class
  20. let buttons = document.querySelectorAll("div[class*='betterhover\\:hover:text-primary'].relative.flex.h-\\[30px\\].cursor-pointer.select-none.items-center.rounded-\\[3px\\].px-\\[15px\\].pl-\\[20px\\].text-sm.font-medium.leading-none.text-white.outline-none");
  21.  
  22. for (let button of buttons) {
  23. if (button.textContent.includes(quality)) {
  24. if (button.getAttribute('aria-checked') === 'true' && button.getAttribute('data-state') === 'checked') {
  25. return true; // Already selected, stop further checks
  26. }
  27. // Modify attributes to simulate selection
  28. button.setAttribute('aria-checked', 'true');
  29. button.setAttribute('data-state', 'checked');
  30. button.click(); // Simulate the click to select the quality
  31. return true;
  32. }
  33. }
  34. return false;
  35. };
  36.  
  37. // Function to set the stream quality
  38. let setStreamQuality = () => {
  39. // Try to select the best available quality and stop the interval if successful
  40. if (checkQuality('1080p60') ||
  41. checkQuality('1080p') ||
  42. checkQuality('936p60') ||
  43. checkQuality('720p60') ||
  44. checkQuality('720p') ||
  45. checkQuality('Auto')) {
  46. clearInterval(qualityCheckInterval); // Stop checking once the quality is set
  47. return true;
  48. }
  49. return false;
  50. };
  51.  
  52. // Run the setStreamQuality function every 500 ms until the quality is set
  53. let qualityCheckInterval = setInterval(() => {
  54. setStreamQuality();
  55. }, 500);
  56.  
  57. })();
  58.