Twitch Enhancer

aiueo

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

// ==UserScript==
// @name         Twitch Enhancer
// @namespace    https://greasyfork.org/ja/users/941284-ぐらんぴ
// @version      2025-02-23
// @description  aiueo
// @author       ぐらんぴ
// @match        https://www.twitch.tv/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @license      MIT
// @run-at       document-start
// @grant        none
// ==/UserScript==

const origFetch = window.fetch;
window.fetch = async function(url, init) {
    let res = await origFetch(url, init);
    // Check for null body status codes
    if(res.status === 204 || res.status === 205) {
        return res; // Return the response as is for these status codes
    }
    let data;
    try{
        // Check if the response is not empty before parsing
        const text = await res.text();
        data = text ? JSON.parse(text) : {};
    }catch(err){
        console.log('Failed to parse JSON:', err);
        return res;
    }

    // console.log(url, data, data.length);
    try{
        if(url.startsWith('https://edge.ads.twitch.tv/ads')){//Prime Pop-up
            data = '';
        }
        if(url == 'https://gql.twitch.tv/gql#origin=twilight'){// twilight
            data.forEach(i =>{
                // login
                if(i.extensions.operationName == 'CoreActionsCurrentUser'){
                    // i.data.currentUser.roles.isStaff = true
                }
                if(i.extensions.operationName == 'FrontPageNew_User'){// followedGames
                    // i.data.currentUser.roles.isStaff = true
                }
            });
        }
    }catch(err){
        console.log('err modifying data:', err);
    }

    return new Response(JSON.stringify(data), {
        headers: res.headers,
        status: res.status,
        statusText: res.statusText,
    });
};

const origAppendChild = Element.prototype.appendChild;
Element.prototype.appendChild = function(...args){
    try{
        if(args[0].className.includes('ScCoreButton-sc-ocjdkq-0')){// Auto Channel Points Claimer
            document.querySelectorAll(".claimable-bonus__icon")[0].click()
        }
        }catch(err){// console.log(err);
       }
    return origAppendChild.apply(this, args);
};