forked from jordam/Portify.JS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpress.js
152 lines (146 loc) · 5.34 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Portify.JS Express Chainloader
// Should complete all steps needed to load portify.js
// Also mutates the google listen.js file to selectively block images
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(){
switch(window.location.pathname) {
case "/music/portifyjs":
gplayTakeover();
break;
case "/web-api/console/get-current-user-playlists/":
spotifyCode();
break;
default:
window.location = "https://developer.spotify.com/web-api/console/get-current-user-playlists/";
break;
}
}
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());
$('#clearOauth').click();
coclick = true;
} else {
if ((new Date().getTime() - parseInt(lasttime))/1000 > 3600){
localStorage.setItem('portifyTime', new Date().getTime().toString());
$('#clearOauth').click();
coclick = true;
}
}
if ($('#oauth').attr('value').length > 0 && !coclick){
window.location = "https://play.google.com/music/portifyjs?spotifyoauth=" + $('#oauth').attr('value');
} else {
$('#oauthPopup').click();
$('input[type=checkbox]').attr('checked', 'checked');
$('#oauthRequestToken').click();
}
}
}
function gplayTakeover(){
window.spotifyoauth = window.QueryString.spotifyoauth;
$.ajax({
url : 'https:\/\/play.google.com\/music\/listen?u\x3d0\x26hl\x3den-US',
dataType: "text",
success : function (data) {
window.htmldata = data;
window.basejs = "https://" + window.htmldata.split("/listen.js")[0].split('https://')[window.htmldata.split("/listen.js")[0].split('https://').length-1] + "/";
window.listensrc = window.basejs + "listen.js";
window.sjsrc = window.basejs + "sj_srcs.js";
document.write(data.replace("listen.js", "").replace("sj_srcs.js",""));
$.ajax({
url : window.sjsrc,
dataType: "text",
success : function (datac) {
$('<script>')
.attr('type', 'text/javascript')
.text(datac.replace('animationConfig', 'notAnimationConfig'))
.appendTo('body');
}
});
setTimeout(function() {
$.ajax({
url : window.listensrc,
dataType: "text",
success : function (datab) {
//var inject = ";var DP=function(a,b,c,e){var localtxt = (BP(b(c||CP,void 0,e)));var re = /src=/g;var result = localtxt.replace(re, 'nosrc=');a.innerHTML=result;};" // Our string to inject at the bottom of the listen.js page. Replaces obfusicated function DP with a patched version that replaces 'src' with 'nosrc'.
var functionIndicator = "=function(a,b,c,e){a.innerHTML="; // This string is used to locate the function we need to modify
var i = datab.split(functionIndicator)[1].indexOf('}');
var splits = [datab.split(functionIndicator)[1].slice(0,i), datab.split(functionIndicator)[1].slice(i+1)];
var smod = datab.split(functionIndicator)[0] + "=function(a,b,c,e){a.innerHTML=window.mutateInput(" + splits[0] + ")}" + splits[1];
console.log(smod);
$('<script>')
.attr('type', 'text/javascript')
.text(smod)
.appendTo('body');
$('<style>')
.attr('type', 'text/css')
.text('* {transition: none !important;}')
.appendTo('head');
document.close();
$.getScript("https://rawgit.com/jordam/Portify.JS/master/portify.js");
}
});
}, 1000);
}
});
}
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;
}();