Twitch Enhancer

aiueo

目前为 2025-02-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Twitch Enhancer
  3. // @namespace https://greasyfork.org/ja/users/941284-ぐらんぴ
  4. // @version 2025-02-23
  5. // @description aiueo
  6. // @author ぐらんぴ
  7. // @match https://www.twitch.tv/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @license MIT
  10. // @run-at document-start
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. const origFetch = window.fetch;
  15. window.fetch = async function(url, init) {
  16. let res = await origFetch(url, init);
  17. // Check for null body status codes
  18. if(res.status === 204 || res.status === 205) {
  19. return res; // Return the response as is for these status codes
  20. }
  21. let data;
  22. try{
  23. // Check if the response is not empty before parsing
  24. const text = await res.text();
  25. data = text ? JSON.parse(text) : {};
  26. }catch(err){
  27. console.log('Failed to parse JSON:', err);
  28. return res;
  29. }
  30.  
  31. // console.log(url, data, data.length);
  32. try{
  33. if(url.startsWith('https://edge.ads.twitch.tv/ads')){//Prime Pop-up
  34. data = '';
  35. }
  36. if(url == 'https://gql.twitch.tv/gql#origin=twilight'){// twilight
  37. data.forEach(i =>{
  38. // login
  39. if(i.extensions.operationName == 'CoreActionsCurrentUser'){
  40. // i.data.currentUser.roles.isStaff = true
  41. }
  42. if(i.extensions.operationName == 'FrontPageNew_User'){// followedGames
  43. // i.data.currentUser.roles.isStaff = true
  44. }
  45. });
  46. }
  47. }catch(err){
  48. console.log('err modifying data:', err);
  49. }
  50.  
  51. return new Response(JSON.stringify(data), {
  52. headers: res.headers,
  53. status: res.status,
  54. statusText: res.statusText,
  55. });
  56. };
  57.  
  58. const origAppendChild = Element.prototype.appendChild;
  59. Element.prototype.appendChild = function(...args){
  60. try{
  61. if(args[0].className.includes('ScCoreButton-sc-ocjdkq-0')){// Auto Channel Points Claimer
  62. document.querySelectorAll(".claimable-bonus__icon")[0].click()
  63. }
  64. }catch(err){// console.log(err);
  65. }
  66. return origAppendChild.apply(this, args);
  67. };