Open Twitch Channel on Streamcharts in New Tab

Adds a button to open the Twitch channel in a new tab with Streamscharts analytics data.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Open Twitch Channel on Streamcharts in New Tab
// @namespace    http://tampermonkey-scripts/
// @version      3
// @description  Adds a button to open the Twitch channel in a new tab with Streamscharts analytics data.
// @match        https://www.twitch.tv/*
// @grant        GM_setClipboard
// ==/UserScript==

(function() {
    'use strict';

    // Get the Twitch channel name from the URL
    const twitchUrlRegex = /https:\/\/www\.twitch\.tv\/([^/]+)/;
    const match = twitchUrlRegex.exec(window.location.href);
    if (!match) {
        return;
    }
    const channelName = match[1];

    // Create a button to open the channel in a new tab with Streamscharts analytics data
    const button = document.createElement('button');
    button.innerText = 'stats';
    button.style.position = 'absolute';
//    button.style.opacity = '0.55';
    button.style.top = '0';
    button.style.left = '97%';
    button.style.right = '0';
    // button.style.transform = 'translateY(48.5%)';
    button.style.transform = 'translateY(49%)';
    button.style.zIndex = '9999';
    button.style.padding = '5px 10px';
    button.addEventListener('mouseenter', () => {
        button.style.color = '#772CE8'; // change text color on hover
    });
    button.addEventListener('mouseleave', () => {
        button.style.color = '#ffffff'; // reset text color when not hovering
    });
    button.addEventListener('click', () => {
        const streamschartsUrl = `https://streamscharts.com/channels/${channelName}`;
        GM_setClipboard(streamschartsUrl);
        window.open(streamschartsUrl, '_blank');
    });

    // Add the button to the Twitch page
    const playerElement = document.querySelector('div[data-a-target="video-player"]');
    if (playerElement) {
        playerElement.parentNode.insertBefore(button, playerElement);
    }
})();