-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathexpress.js
130 lines (118 loc) · 3.97 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// 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 == "/console/get-current-user-playlists/") {
spotifyCode();
}
else {
window.location = "https://developer.spotify.com/console/get-current-user-playlists/";
}
}
function doScopeSelect(){
var scopes = ['#scope-playlist-read-private', '#scope-user-library-modify', '#scope-playlist-modify-private', '#scope-user-library-read', '#scope-playlist-modify-public'];
for (i in scopes){
if (! document.querySelector(scopes[i]).checked){document.querySelector(scopes[i]).click(); };
}
}
function clickGetToken(){
localStorage.setItem('portifyTime', new Date().getTime().toString());
document.querySelector('.btn-green').click()
window.setTimeout(function(){
doScopeSelect()
window.setTimeout(function(){
document.querySelector('#oauthRequestToken').click();
}, 750);
}, 750);
}
function spotifyCode(){
if (window.location.pathname.indexOf('authorize') == -1){
if (document.querySelector('#oauth-input').value.length > 0){
var lasttime = localStorage.getItem('portifyTime');
var coclick = false;
if (lasttime === null){
clickGetToken();
coclick = true;
} else {
if ((new Date().getTime() - parseInt(lasttime))/1000 > 3600){
clickGetToken();
coclick = true;
}
else{
goToGoogle(document.querySelector('#oauth-input').value);
}
}
} else { // no oauth listed
clickGetToken();
}
} else {
document.querySelector('#auth-accept').click();
}
}
function goToGoogle(oauth){
window.location = "https://play.google.com/music/listen?spotifyoauth=" + oauth;
}
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;
}();