-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
84 lines (73 loc) · 3 KB
/
script.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
const urlInput = document.getElementById('url-input');
const unblockButton = document.getElementById('unblock-button');
const generateDataURLButton = document.getElementById('generate-data-url-button');
const dataURLOutput = document.getElementById('data-url-output');
const copyDataURLButton = document.getElementById('copy-data-url-button');
const copyMessage = document.getElementById('copy-message');
function unblockWebsite(url) {
try {
let validatedUrl;
if (!url.startsWith("http://") && !url.startsWith("https://")) {
validatedUrl = "https://" + url;
} else {
validatedUrl = url;
}
const blob = new Blob([`<html><body style='margin:0;padding:0;'><iframe src='${validatedUrl}' width='100%' height='100%' style='border:none;'></iframe></body></html>`], { type: 'text/html' });
const blobUrl = URL.createObjectURL(blob);
window.open(blobUrl, '_blank');
} catch (error) {
console.error("Error unblocking website:", error);
alert("Invalid URL or unable to load website.");
}
}
function generateDataURL(url) {
try {
let validatedUrl;
if (!url.startsWith("http://") && !url.startsWith("https://")) {
validatedUrl = "https://" + url;
} else {
validatedUrl = url;
}
const dataURL = `data:text/html;charset=utf-8,<script>const u=URL.createObjectURL(new Blob([\`<html><body style='margin:0;padding:0;'><iframe src='${validatedUrl}' width='100%' height='100%' style='border:none;'></iframe></body></html>\`], { type: 'text/html' }));window.location.href=u;</script>`;
dataURLOutput.value = dataURL;
} catch (error) {
console.error("Error generating data URL:", error);
alert("Invalid URL.");
}
}
urlInput.addEventListener('keyup', function (event) {
if (event.key === 'Enter') {
unblockWebsite(this.value);
}
});
unblockButton.addEventListener('click', function () {
unblockWebsite(urlInput.value);
});
generateDataURLButton.addEventListener('click', function () {
generateDataURL(urlInput.value);
});
copyDataURLButton.addEventListener('click', function () {
const dataURL = dataURLOutput.value;
if (navigator.clipboard) {
navigator.clipboard.writeText(dataURL)
.then(() => {
console.log('URL copied to clipboard:', dataURL); // Log the URL
showCopyMessage();
})
.catch((error) => {
console.error('Error copying URL:', error);
alert("Copy to clipboard failed. Please copy manually.");
});
} else {
console.log('Clipboard API not supported. Using fallback.'); // Log the fallback
dataURLOutput.select();
document.execCommand('copy');
alert("Your browser does not support automatic copy. Please copy manually.");
}
});
function showCopyMessage() {
copyMessage.classList.add('show');
setTimeout(() => {
copyMessage.classList.remove('show');
}, 2000);
}