Twitch Prime Reminder

Adds a reminder of who you used your Twitch Prime sub on and when it expires to the Subscribe button modal

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Twitch Prime Reminder
// @namespace    http://fugiman.com
// @version      1.1
// @description  Adds a reminder of who you used your Twitch Prime sub on and when it expires to the Subscribe button modal
// @match        https://www.twitch.tv/*
// ==/UserScript==

(function() {
    'use strict';

    // If this somehow runs on a non-Twitch page, or non-Ember page, abort
    if(!Twitch || !App) return;

    // Get the current user's subscriptions
    Twitch.api.get("/api/users/:login/tickets").then(function(d) {
        // Find the Twitch Prime sub
        var t = _.find(d.tickets, function(t) {
            return t.purchase_profile.payment_provider == "samus"; // "samus" is the codename for Twitch Prime
        });

        // Maybe it isn't used, or you don't have Twitch Prime?
        if(!t) return;

        // Look up the display name for the partner
        Twitch.api.get("/api/channels/"+t.product.partner_login+"/ember").then(function(u) {
            // Some nicely formatted text
            var supportHTML = 'Currently supporting <b>'+u.display_name+'</b> until <b>'+moment(t.access_end).format('MMMM Do')+'</b>';

            // Override Twitch's application to inject our string
            App.__deprecatedInstance__.registry.resolve("component:subscribe-button/prime-section").reopen({
                didInsertElement: function() {
                    this._super();

                    var span = document.createElement("span");
                    span.innerHTML = supportHTML;
                    this.get('element').appendChild(span);
                },
            });
            App.__deprecatedInstance__.registry.resolve("component:subscribe-button/upgrade-modal").reopen({
                didInsertElement: function() {
                    this._super();

                    $("button:contains('Not yet')", this.get('element')).each(function(i, button) {
                        var span = document.createElement("span");
                        span.innerHTML = supportHTML;
                        button.parentNode.appendChild(span);
                    });
                },
            });
        });
    });
})();