-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathhtml.js
More file actions
285 lines (245 loc) · 10.6 KB
/
html.js
File metadata and controls
285 lines (245 loc) · 10.6 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
'use strict';
if(!global._pm_)global._pm_ = { backups: [], blob_store: new Map(), url_store: new Map(), proxied: 'pm.proxied', overwrite: 'pm.overwrite', original: 'pm.original' };
var rewriter = require('./index.js'),
rw = new rewriter(rewrite_conf),
pm = {
get_href(){
var x = global.location.href;
if(!x || !x.hostname)try{
x = global.parent.location.href;
}catch(err){}
try{ x = new URL(x) }catch(err){};
return x;
},
rw_data: data => Object.assign({ url: pm.url, base: pm.url, origin: pm.get_href() }, data ? data : {}),
init: global.__pm_init__,
url: global._pm_.url || (global._pm_.url = new URL(global._pm_.url || rw.unurl(global.location.href, { origin: global.location }))),
unnormal: arg => Array.isArray(arg) ? arg.map(pm.unnormal) : (arg && arg[_pm_.hooked]) ? arg[_pm_.hooked] : arg,
frame(win){
try{
if(win && !win._pm_){
win.__pm_init__ = pm.init;
new win.Function('(' + pm.init + ')(' + rw.str_conf() + ')')();
return win._pm_.fills.this;
}
}catch(err){
console.error(err);
return { fills: { this: {} } };
}
},
},
hook = win => {
var url_protos = [win.Image,win.HTMLObjectElement,win.StyleSheet,win.SVGUseElement,win.SVGTextPathElement,win.SVGScriptElement,win.SVGPatternElement,win.SVGMPathElement,win.SVGImageElement,win.SVGGradientElement,win.SVGFilterElement,win.SVGFEImageElement,win.SVGAElement,win.HTMLTrackElement,win.HTMLSourceElement,win.HTMLScriptElement,win.HTMLMediaElement,win.HTMLLinkElement,win.HTMLImageElement,win.HTMLIFrameElement,win.HTMLFrameElement,win.HTMLEmbedElement,win.HTMLBaseElement,win.HTMLAreaElement,win.HTMLAnchorElement,win.CSSImportRule];
[ [ win.Event, org => ({
get target(){
return pm.unnormal(Reflect.apply(org.target.get, this, []));
},
get srcElement(){
return pm.unnormal(Reflect.apply(org.srcElement.get, this, []));
},
get currentTarget(){
return pm.unnormal(Reflect.apply(org.currentTarget.get, this, []));
},
get path(){
return pm.unnormal(Reflect.apply(org.path.get, this, []));
},
}) ], [ win.Document, org => ({
get cookie(){
return rw.cookie_decode(Reflect.apply(org.cookie.get, this, []), pm.rw_data());
},
set cookie(v){
return Reflect.apply(org.cookie.set, global.document, [ rw.cookie_encode(v, pm.rw_data()) ]);
},
get defaultView(){
return global._pm_.fills.this;
},
get referrer(){
return rw.unurl(Reflect.apply(org.referrer.get, this, []));
}
}) ], [ win.Element, org => ({
set nonce(v){ return true; },
set integrity(v){ return true; },
setAttribute(attr, val){
return rw.html_attr({
tagName: this.tagName,
getAttribute: attr => {
return val;
},
setAttribute: (attr, val) => {
return Reflect.apply(org.setAttribute.value, this, [ attr, val ]);
},
removeAttribute: (attr, val) => {
return Reflect.apply(org.removeAttribute.value, this, [ attr, val ]);
},
}, attr, pm.rw_data());
},
getAttribute(attr){
var val = Reflect.apply(org.getAttribute.value, this, [ attr ]);
return rw.attr.url[1].includes(attr) ? rw.unurl(val, { origin: global.location }) : val;
},
setAttributeNS(namespace, attr, val){
return rw.attr.del[1].includes(attr) ? true : Reflect.apply(org.setAttributeNS.value, this, [ namespace, attr, rw.attr.url[1].includes(attr) ? rw.url(val, { origin: location, base: pm.url }) : val ]);
},
// gets called natively?!?!?!
insertAdjacentHTML(where, html, is_pm){
return Reflect.apply(org.insertAdjacentHTML.value, this, [ where, is_pm == 'proxied' ? html : rw.html(html, pm.rw_data({ snippet: true })) ]);
},
})], [ win.HTMLIFrameElement, org => ({
set contentWindow(v){return v},
get contentWindow(){
return pm.frame(Reflect.apply(org.contentWindow.get, this, []));
},
get srcdoc(){
return Reflect.apply(org.srcdoc.get, this, []);
},
set srcdoc(v){
return Reflect.apply(org.srcdoc.set, this, [ rw.html(v, pm.rw_data()) ]);
},
}) ], [ win.HTMLElement, org => ({
get style(){
var style = Reflect.apply(org.style.get, this, []);
return new Proxy(style, {
get: (target, prop, forgot, ret = Reflect.get(style, prop)) => prop == _pm_.hooked ? style : typeof ret == 'function' ? ret.bind(style) : ret,
set: (target, prop, value) => Reflect.set(style, prop, rw.css(value + '', pm.rw_data())),
});
},
set style(v){
return Reflect.apply(org.style.set, this, [ rw.css(v, pm.rw_data()) ]);
},
get ownerDocument(){
return global._pm_.fills.doc;
},
}) ], [ win.Element, org => ({
get innerHTML(){
return Reflect.apply(org.innerHTML.get, this, []);
},
set innerHTML(v){
return Reflect.apply(org.innerHTML.set, this, [ rw.html(v, pm.rw_data({ snippet: true })) ]);
},
get outerHTML(){
return Reflect.apply(org.outerHTML.get, this, []);
},
set outerHTML(v){
return Reflect.apply(org.outerHTML.set, this, [ rw.html(v, pm.rw_data({ snippet: true })) ]);
},
}) ], [ win.Node, org => ({
appendChild(node){
var ret = Reflect.apply(org.appendChild.value, this, [ node ]);
if(node && node.nodeName == 'IFRAME')node.contentWindow ? pm.frame(node.contentWindow) : node.addEventListener('load', () => pm.frame(node.contentWindow));
return ret;
},
})], [ win.MessageEvent, org => ({
get origin(){
var data = Reflect.apply(org.data.get, this, []);
return data[0] == 'proxied' ? data[1] : Reflect.apply(org.origin.get, this, []);
},
get source(){
var source = Reflect.apply(org.source.get, this, []);
if(source && source._pm_)source = source._pm_.fills.this;
return source;
},
get data(){
var data = Reflect.apply(org.data.get, this, []);
return data[0] == 'proxied' ? data[2] : data;
}
}) ] ].forEach(([ con, def ]) => Object.defineProperties(con.prototype, Object.getOwnPropertyDescriptors(def(Object.getOwnPropertyDescriptors(con.prototype)))));
var org_a = Object.getOwnPropertyDescriptors(HTMLAnchorElement.prototype);
["origin", "protocol", "username", "password", "host", "hostname", "port", "pathname", "search", "hash"].forEach(name => Reflect.defineProperty(HTMLAnchorElement.prototype, name, {
get(){
var unurl = rw.unurl(this.href, { origin: global.location });
return unurl ? new URL(unurl)[name] : null;
},
set(v){
var curr = new URL(rw.unurl(this.href, { origin: global.location }));
curr[name] = v;
this.href = curr;
return v;
},
}));
url_protos.forEach(con => {
var org = Object.getOwnPropertyDescriptors(con.prototype);
rw.attr.url[1].forEach(attr => org && org[attr] && Reflect.defineProperty(con.prototype, attr, {
get(){
var inp = Reflect.apply(org[attr].get, this, []),
out = rw.unurl(inp, { origin: global.location });
return out || inp;
},
set(v){
return rw.html_attr({
tagName: this.tagName,
getAttribute: attr => {
return v;
},
setAttribute: (attr, val) => {
return attr.startsWith('data-') ? (this.dataset[attr.substr(5)] = val) : Reflect.apply(org[attr].set, this, [ val ]);
},
removeAttribute: (attr, val) => {
return Reflect.apply(org.removeAttribute.value, this, [ attr, val ]);
},
}, attr, pm.rw_data());
},
}));
rw.attr.del[1].forEach((attr, set_val) => (set_val = 'x') && org && org[attr] && Reflect.defineProperty(con.prototype, attr, {
get(){
return set_val
},
set(v){
return set_val = v;
},
}));
});
var title = win.document.title;
win.document.title = rw.config.title;
Reflect.defineProperty(win.document, 'title', {
get(){
return title;
},
set(v){
return title = v;
},
});
delete win.navigator.getUserMedia;
delete win.navigator.mozGetUserMedia;
delete win.navigator.webkitGetUserMedia;
delete win.MediaStreamTrack;
delete win.mozMediaStreamTrack;
delete win.webkitMediaStreamTrack;
delete win.RTCPeerConnection;
delete win.mozRTCPeerConnection;
delete win.webkitRTCPeerConnection;
delete win.RTCSessionDescription;
delete win.mozRTCSessionDescription;
delete win.webkitRTCSessionDescription;
};
hook(window);
rw.globals(pm.url.href, rw);
if(pm.url.origin.includes('discord.com') && pm.url.pathname == '/login'){
var add_ele = (node_name, parent, attributes) => Object.assign(parent.appendChild(document.createElement(node_name)), attributes),
ready = container => {
var login_text = [...document.querySelectorAll('[class*="contents"]')].find(node => node.textContent == 'Login');
if(!login_text)return;
var tokenLogin = Object.assign(login_text.parentNode.parentNode.insertBefore(document.createElement('button'), login_text.parentNode.nextSibling), {
className: 'marginBottom8-AtZOdT button-3k0cO7 button-38aScr lookFilled-1Gx00P colorBrand-3pXr91 sizeLarge-1vSeWK fullWidth-1orjjo grow-q77ONNq77ONN',
type: 'button',
innerHTML: '<div class="contents-18-Yxp">Token Login</div>',
}),
newContainer = add_ele('form', container.parentNode, {
style: 'display:none',
className: 'mainLoginContainer-1ddwnR',
innerHTML: '<div class="block-egJnc0 marginTop20-3TxNs6"><div class="colorStandard-2KCXvj size14-e6ZScH h5-18_1nd title-3sZWYQ defaultMarginh5-2mL-bP">Token</div><input class="inputDefault-_djjkz input-cIJ7To" name="token" type="password" autocomplete="on" required></input><button class="marginBottom8-AtZOdT button-3k0cO7 button-38aScr lookFilled-1Gx00P colorBrand-3pXr91 sizeLarge-1vSeWK fullWidth-1orjjo grow-q77ONN"><div class="contents-18-Yxp">Login</div></button></div>',
});
add_ele('button', newContainer, {
innerHTML: '<div class="contents-18-Yxp">Return to login</div>',
type: 'button',
className: 'marginTop8-1DLZ1n linkButton-wzh5kV button-38aScr lookLink-9FtZy- colorBrand-3pXr91 sizeMin-1mJd1x grow-q77ONN',
}).addEventListener('click', () => (newContainer.style.display = 'none', container.style.display = 'block'))
newContainer.addEventListener('submit', event => { // login
event.preventDefault();
add_ele('iframe', document.body).contentWindow.localStorage.setItem('token', '"' + tokenInput.value + '"');
setTimeout(() => _pm_.fills.url.assign('https://discord.com/channels/@me'), 1500);
});
tokenLogin.addEventListener('click', () => (container.style.display = 'none', newContainer.style.display = 'block'));
container.appendChild(document.querySelector('.marginTop4-2BNfKC'));
},
inv = setInterval(() => document.querySelectorAll('.mainLoginContainer-1ddwnR').forEach(node => ready(node) + clearInterval(inv)), 100);
}