Twitch Enhancements

Automatically claim channel points, enable theater mode, and claim prime rewards on https://gaming.amazon.com/

目前為 2024-06-20 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Twitch Enhancements
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Automatically claim channel points, enable theater mode, and claim prime rewards on https://gaming.amazon.com/
  6. // @author JJJ
  7. // @match https://www.twitch.tv/*
  8. // @match https://gaming.amazon.com/*
  9. // @match https://www.twitch.tv/drops/inventory*
  10. // @icon https://th.bing.com/th/id/R.d71be224f193da01e7e499165a8981c5?rik=uBYlAxJ4XyXmJg&riu=http%3a%2f%2fpngimg.com%2fuploads%2ftwitch%2ftwitch_PNG28.png&ehk=PMc5m5Fil%2bhyq1zilk3F3cuzxSluXFBE80XgxVIG0rM%3d&risl=&pid=ImgRaw&r=0
  11. // @grant none
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. (function () {
  16. 'use strict';
  17. // Constants
  18. const PLAYER_SELECTOR = '.video-player';
  19. const THEATER_MODE_BUTTON_SELECTOR = 'button[aria-label="Modo cine (alt+t)"]';
  20. const CLOSE_MENU_BUTTON_SELECTOR = 'button[aria-label="Close Menu"]';
  21. const CLOSE_MODAL_BUTTON_SELECTOR = 'button[aria-label="Close modal"]';
  22. const THEATER_MODE_CLASS = 'theatre-mode';
  23. const CLAIMABLE_BONUS_SELECTOR = '.claimable-bonus__icon';
  24. const CLAIM_DROPS_SELECTOR = '[class="ScCoreButton-sc-ocjdkq-0 ScCoreButtonPrimary-sc-ocjdkq-1 ejeLlX eHSNkH"]';
  25. const PRIME_REWARD_SELECTOR = 'span[data-a-target="tw-button-text"] p[data-a-target="buy-box_call-to-action-text"][title="Get in-game content"], p[data-a-target="buy-box_call-to-action-text"][title="Get game"]';
  26. let claiming = false;
  27.  
  28. // Check if MutationObserver is supported
  29. const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  30.  
  31. // Function to click a button
  32. function clickButton(buttonSelector) {
  33. const observer = new MutationObserver((mutationsList, observer) => {
  34. for (let mutation of mutationsList) {
  35. if (mutation.addedNodes.length) {
  36. const button = document.querySelector(buttonSelector);
  37. if (button) {
  38. button.click();
  39. observer.disconnect();
  40. return;
  41. }
  42. }
  43. }
  44. });
  45.  
  46. observer.observe(document, { childList: true, subtree: true });
  47. }
  48.  
  49. // Function to enable theater mode
  50. function enableTheaterMode() {
  51. const player = document.querySelector(PLAYER_SELECTOR);
  52. if (player) {
  53. if (!player.classList.contains(THEATER_MODE_CLASS)) {
  54. clickButton(THEATER_MODE_BUTTON_SELECTOR);
  55. }
  56. } else {
  57. console.error('Player not found');
  58. }
  59. }
  60.  
  61. // Function to hide the global menu
  62. function hideGlobalMenu() {
  63. const GLOBAL_MENU_SELECTOR = 'div.ScBalloonWrapper-sc-14jr088-0.eEhNFm';
  64. const globalMenu = document.querySelector(GLOBAL_MENU_SELECTOR);
  65. if (globalMenu) {
  66. globalMenu.style.display = 'none';
  67. } else {
  68. console.error('Global menu not found');
  69. }
  70. }
  71.  
  72. // Function to automatically claim channel points
  73. function autoClaimBonus() {
  74. if (MutationObserver) {
  75. console.log('Auto claimer is enabled.');
  76.  
  77. let observer = new MutationObserver(mutationsList => {
  78. for (let mutation of mutationsList) {
  79. if (mutation.type === 'childList') {
  80. let bonus = document.querySelector(CLAIMABLE_BONUS_SELECTOR);
  81. if (bonus && !claiming) {
  82. bonus.click();
  83. let date = new Date();
  84. claiming = true;
  85. setTimeout(() => {
  86. console.log('Claimed at ' + date.toLocaleString());
  87. claiming = false;
  88. }, Math.random() * 1000 + 2000);
  89. }
  90. }
  91. }
  92. });
  93.  
  94. observer.observe(document.body, { childList: true, subtree: true });
  95. } else {
  96. console.log('MutationObserver is not supported in this browser.');
  97. }
  98. }
  99.  
  100. // Function to claim prime rewards
  101. function claimPrimeReward() {
  102. const element = document.querySelector(PRIME_REWARD_SELECTOR);
  103. if (element) {
  104. element.click();
  105. }
  106. }
  107.  
  108. // Function to claim drops
  109. function claimDrops() {
  110. var onMutate = function (mutationsList) {
  111. mutationsList.forEach(mutation => {
  112. if (document.querySelector(CLAIM_DROPS_SELECTOR)) document.querySelector(CLAIM_DROPS_SELECTOR).click();
  113. })
  114. }
  115. var observer = new MutationObserver(onMutate);
  116. observer.observe(document.body, { childList: true, subtree: true });
  117. }
  118.  
  119. setTimeout(enableTheaterMode, 1000);
  120. setTimeout(autoClaimBonus, 1000);
  121. setTimeout(claimPrimeReward, 1000);
  122. setTimeout(() => clickButton(CLOSE_MENU_BUTTON_SELECTOR), 1000);
  123. setTimeout(() => clickButton(CLOSE_MODAL_BUTTON_SELECTOR), 1000);
  124. setTimeout(hideGlobalMenu, 1000);
  125. setTimeout(claimDrops, 1000);
  126.  
  127. setInterval(function () {
  128. if (window.location.href.startsWith('https://www.twitch.tv/drops/inventory')) {
  129. window.location.reload();
  130. }
  131. }, 15 * 60000);
  132. })();