-
Notifications
You must be signed in to change notification settings - Fork 0
/
iframe.html
236 lines (222 loc) · 6.1 KB
/
iframe.html
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
<html><head>
<meta charset="UTF-8">
<style id="webmakerstyle">
iframe {
height:100vh;
width:100vw;
border:none;
}
body {
overflow:hidden;
margin:0;
}
</style>
</head>
<body>
<iframe id="iframe1">
</iframe>
<script>// setup proxyurl
const Purl = "https://api.codetabs.com/v1/proxy?quest=";
// request with good url
function pfix(url) {
var Purl = "https://api.codetabs.com/v1/proxy?quest=";
const xhr = new XMLHttpRequest();
xhr.open("GET", url.replace(Purl + Purl, Purl), false); // Set the third parameter to false for synchronous request
try {
xhr.send();
if (xhr.status === 200) {
const text = xhr.responseText;
return text;
} else {
console.error("Error:", xhr.status, xhr.statusText);
}
} catch (error) {}
}
function request(rurl) {
const url = Purl + rurl;
const xhr = new XMLHttpRequest();
xhr.open("GET", url, false);
try {
xhr.send();
if (xhr.status === 200) {
const text = xhr.responseText;
return text;
} else {
console.error("Error:", xhr.status, xhr.statusText);
}
} catch (error) {}
}
async function applyAllStyles(doc, url) {
const styleTags = doc.querySelectorAll("style");
const linkTags = doc.querySelectorAll('link[rel="stylesheet"]');
styleTags.forEach(styleTag => {
const styleContent = styleTag.innerHTML;
const styleElement = doc.createElement("style");
styleElement.textContent = styleContent;
doc.head.appendChild(styleElement);
});
linkTags.forEach(linkTag => {
if (linkTag.href) {
var src = linkTag.href;
if (
src
.replace("https://api.codetabs.com/v1/proxy?quest=", "")
.startsWith("/")
) {
var src =
"https://api.codetabs.com/v1/proxy?quest=" +
new URL(url).origin +
src.replace("https://api.codetabs.com/v1/proxy?quest=", "");
} else {
var src = src;
}
const styleContent = pfix(src);
const styleElement = doc.createElement("style");
styleElement.textContent = styleContent;
doc.head.appendChild(styleElement);
}
});
}
async function runScript(doc, url) {
var win = document.getElementById("iframe1").contentWindow;
var scripts = doc.querySelectorAll("script");
scripts.forEach(script => {
if (script.src) {
var src = script.src;
if (
src
.replace("https://api.codetabs.com/v1/proxy?quest=", "")
.startsWith("/")
) {
var src =
"https://api.codetabs.com/v1/proxy?quest=" +
new URL(url).origin +
src.replace("https://api.codetabs.com/v1/proxy?quest=", "");
} else {
var src = src;
}
try {
setTimeout(() => {
try {
win.eval(fixHTML(pfix(src)))
} catch {
};
}, 100);
} catch {
setTimeout(() => {
win.eval(fixHTML(script.innerHTML));
}, 100);
}
} else {
setTimeout(() => {
win.eval(fixHTML(script.innerHTML));
}, 100);
}
});
}
async function IframeSRC(doc) {
var win = document.getElementById("iframe1").contentWindow;
var scripts = doc.querySelectorAll("iframe");
for (const script of scripts) {
if (script.src) {
script.src =
"https://geoloupgome.netlify.app/iframe?url=" +
script.src.replace(Purl, "");
} else {
script.src =
"https://geoloupgome.netlify.app/iframe?url=" +
script.src.replace(Purl, "");
}
}
}
function SetupImg(doc) {
var win = document.getElementById("iframe1").contentWindow;
setInterval(() => {
Img(doc);
}, 1000);
}
async function Img(doc, url) {
var win = document.getElementById("iframe1").contentWindow;
var images = doc.querySelectorAll("img");
for (const image of images) {
if (image.dataset.done == "1") {
} else {
var imgElement = document.createElement("img");
var src = image.src.replace(
"https://cors-proxy.fringe.zone/https://",
"https://api.codetabs.com/v1/proxy?quest="
);
if (
src
.replace("https://api.codetabs.com/v1/proxy?quest=", "")
.startsWith("/")
) {
var url = new URL(url).origin;
imgElement.src =
"https://api.codetabs.com/v1/proxy?quest=" +
url +
src.replace("https://api.codetabs.com/v1/proxy?quest=", "");
} else {
imgElement.src = src;
}
imgElement.alt = image.alt;
imgElement.width = image.width;
imgElement.height = image.height;
imgElement.dataset.done = "1";
imgElement.id = image.id;
imgElement.classList = image.classList;
image.replaceWith(imgElement);
}
}
}
async function ALink(doc) {
var win = document.getElementById("iframe1").contentWindow;
var scripts = doc.querySelectorAll("a");
for (const script of scripts) {
if (script.href) {
script.href =
"https://geoloupgome.netlify.app/iframe?url=" +
script.href.replace(Purl, "");
} else {
script.href =
"https://geoloupgome.netlify.app/iframe?url=" +
script.href.replace(Purl, "");
}
}
}
function fixHTML(text) {
const pattern = /https:\/\/([^\s"']+)/g;
var text = text.replace(pattern, Purl + "$1");
return text;
}
function proxy(url) {
var text = request(url);
const pattern = /https:\/\/([^\s"']+)/g;
try {
var text = text.replace(pattern, Purl + "$1");
var text = text.replaceAll('src="', 'src="' + Purl);
var text = text.replaceAll('href="', 'href="' + Purl);
var text = text.replaceAll(Purl + Purl, Purl);
} catch {}
return text;
}
function appendHTMLString(url, doc) {
var htmlString = proxy(url);
doc.body.innerHTML = htmlString;
setTimeout(() => {
runScript(doc, url);
applyAllStyles(doc, url);
IframeSRC(doc, url);
ALink(doc, url);
Img(doc, url);
SetupImg(doc, url);
}, 100);
}
var iframe = document.getElementById("iframe1");
appendHTMLString(
new URLSearchParams(window.location.search).get('url'),
iframe.contentDocument
);
//# sourceURL=userscript.js
</script>
</body></html>