forked from jordam/Portify.JS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
express.js
110 lines (101 loc) · 3.55 KB
/
express.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Portify.JS Express Chainloader
// Should complete all steps needed to load portify.js
// Also mutates the google listen.js file to selectively block images
window.portifyURL = 'https://rawgit.com/jordam/Portify.JS/master';
function insertBeforeLastOccurrence(strToSearch, strToFind, strToInsert) {
var n = strToSearch.lastIndexOf(strToFind);
if (n < 0) return strToSearch;
return strToSearch.substring(0,n) + strToInsert + strToSearch.substring(n);
}
function addscript(url, cbname){
var script = document.createElement('script');
script.src = url;
script.type = 'text/javascript';
script.onload =function(){cbname()};
document.getElementsByTagName('head')[0].appendChild(script);
}
if ((document.readyState == 'complete' || document.readyState == 'interactive') && window.portifyExpress != true){
window.portifyExpress = true;
if (window.jQuery === undefined){
addscript('https://code.jquery.com/jquery-1.11.0.min.js', locationmapper);
} else {
locationmapper();
}
} else {
if (window.canImage === true){
addstyle("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css");
window.modalstage = 2;
dospotimport();
}
}
function locationmapper(){
if (window.location.pathname == "/music/listen" && window.QueryString && window.QueryString.spotifyoauth) {
gplayTakeover();
}
else if (window.location.pathname == "/web-api/console/get-current-user-playlists/") {
spotifyCode();
}
else {
window.location = "https://developer.spotify.com/web-api/console/get-current-user-playlists/";
}
}
function spotifyCode(){
if (window.location.pathname.indexOf('authorize') != -1){
document.querySelector('.auth-allow').click();
} else {
var lasttime = localStorage.getItem('portifyTime');
var coclick = false;
if (lasttime === null){
localStorage.setItem('portifyTime', new Date().getTime().toString());
jQuery('#clearOauth').click();
coclick = true;
} else {
if ((new Date().getTime() - parseInt(lasttime))/1000 > 3600){
localStorage.setItem('portifyTime', new Date().getTime().toString());
jQuery('#clearOauth').click();
coclick = true;
}
}
if (jQuery('#oauth').attr('value').length > 0 && !coclick){
window.location = "https://play.google.com/music/listen?spotifyoauth=" + jQuery('#oauth').attr('value');
} else {
jQuery('#oauthPopup').click();
jQuery('input[type=checkbox]').attr('checked', 'checked');
jQuery('#oauthRequestToken').click();
}
}
}
function gplayTakeover(){
window.spotifyoauth = window.QueryString.spotifyoauth;
jQuery.getScript(window.portifyURL + "/portify.js");
}
window.mutateInput = function(input){
if (window.canImage != true){
var re = /src=/g;
return input.replace(re, 'nosrc=');
} else{
return input;
}
}
window.QueryString = function () {
// This function is anonymous, is executed immediately and
// the return value is assigned to QueryString!
var query_string = {};
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
// If first entry with this name
if (typeof query_string[pair[0]] === "undefined") {
query_string[pair[0]] = decodeURIComponent(pair[1]);
// If second entry with this name
} else if (typeof query_string[pair[0]] === "string") {
var arr = [ query_string[pair[0]],decodeURIComponent(pair[1]) ];
query_string[pair[0]] = arr;
// If third or later entry with this name
} else {
query_string[pair[0]].push(decodeURIComponent(pair[1]));
}
}
return query_string;
}();