Last active
July 22, 2017 00:05
-
-
Save rakslice/f51ff131b4396c34c9d5c535a15c5acb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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== | |
// original at https://greasyfork.org/en/scripts/30821-twitch-prime-reminder | |
(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; | |
// No prime sub currently | |
if(t.product.partner_login === null) 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); | |
}); | |
}, | |
}); | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment