Open Twitch Channel on Streamcharts in New Tab

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);
    }
})();