This repository has been archived by the owner on Jul 4, 2022. It is now read-only.
forked from meganz/webclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
e10s.js
executable file
·106 lines (90 loc) · 2.32 KB
/
e10s.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
(function(window) {
"use strict";
Components.utils.import('resource://gre/modules/Services.jsm');
const webNav = docShell.QueryInterface(Components.interfaces.nsIWebNavigation);
const _hosts = {
"mega.co.nz" : 1,
"mega.is" : 1,
"mega.io" : 1,
"mega.nz" : 1,
"me.ga" : 1
};
const pathToHash = function(l) {
var path = String(l.hash || l.pathname).substr(1);
if (!path || (!~path.indexOf('.') && path.substr(0,5) !== 'linux')) {
var embed = '';
if (String(l.pathname).indexOf('/embed') != -1) {
embed = 'E';
}
return '#' + embed + path + l.search;
}
return l.hash + l.search;
};
const shouldLoad = function(l) {
var hash;
if ((l.protocol === 'https:' || l.protocol === 'http:') && _hosts[l.host]) {
hash = pathToHash(l);
}
return hash;
};
var mID = String(Components.stack.filename).split("=").pop();
addMessageListener("MEGA:"+mID+":bcast", m =>
{
m = m.data.split(':');
if (mID === m[1] && m[2]+m[0] === 'da')
{
mID = 0;
}
});
addEventListener("DOMContentLoaded", ev =>
{
var doc = ev.originalTarget;
if (mID && doc.nodeName === "#document")
{
var hash;
var l = doc.location;
if ((hash = shouldLoad(l)))
{
l = 'mega:' + hash;
try
{
webNav.loadURI(l,0x80,null,null,null);
}
catch(e)
{
if (e.result === 0x804b0012) sendSyncMessage('MEGA:'+mID+':loadURI', l);
}
}
else if (l.protocol === 'mega:'
&& Services.appinfo.processType
== Services.appinfo.PROCESS_TYPE_CONTENT
|| l.host === 'bug1305316.nz') {
sendSyncMessage('MEGA:'+mID+':loadURI', 'mega:' + pathToHash(l));
}
else if (l.host === 'adf.ly') {
var win = doc.defaultView;
try {
var str = doc.head.textContent.match(/ysmm\s*=\s*['"](.*?)['"]/)[1];
var chunk = ['', ''];
for (var i in str) {
if (!(i % 2)) {
chunk[0] += str[i];
}
else {
chunk[1] = str[i] + chunk[1];
}
}
var link = atob(chunk.join("")).substr(2);
if (link.indexOf('redirecting/aHR0') > 0) {
link = atob(link.split('/').pop());
}
if (/^https:\/\/mega\.nz/.test(link.toLowerCase())) {
sendAsyncMessage('MEGA:'+mID+':event', {name: 'mega-event-log4', link: l.href, target: link});
win.location = link;
}
}
catch (ex) {}
}
}
});
})(content);