-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathurl.js
99 lines (80 loc) · 2.85 KB
/
url.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
const overwrites = {
"www.youtube.com": "yt.stonklat.com",
"youtube.com": "yt.stonklat.com"
};
function isWebsite(input) {
if (validator.isURL(input)) {
console.info("The provided input is indeed a URL")
return true;
} else {
console.info("The provided input is is NOT a URL")
return false;
}
}
// Function from uv source code to encode the url into the ultraviolet XOR encryption standard
function encode(str) {
if (!str) return str;
return encodeURIComponent(
str
.toString()
.split('')
.map((char, ind) =>
ind % 2 ? String.fromCharCode(char.charCodeAt() ^ 2) : char
)
.join('')
);
};
function createURL(str) {
const proxyURL = "https://inf.stonklat.com/uv/service/"
let nURI = str.trim();
console.info(nURI);
const searchEngineURLs = {
'duckduckgo': "https://duckduckgo.com/?k7=w&kt=e&k1=-1&kn=-1&kz=-1&k9=1a0dab&ko=s&q=",
'bing': "https://www.bing.com/search?q=",
'yahoo': "https://search.yahoo.com/search?p=",
'brave': "https://search.brave.com/search?q=",
'yandex': "https://yandex.com/search/?text=",
'ask': "https://www.ask.com/web?q=",
'qwant': "https://www.qwant.com/?q=",
'naver': "https://search.naver.com/search.naver?query=",
'dog': "https://www.dogpile.com/serp?q=",
'aol': "https://search.aol.co.uk/aol/search?q="
};
const selectedEngine = document.getElementById('searchEngine').value;
let searchEngineURL = searchEngineURLs[selectedEngine] || "https://www.google.com/search?q=";
if (!isWebsite(nURI)) {
console.info("USING SEARCH ENGINE: " + selectedEngine);
nURI = searchEngineURL + nURI.replace(/\s+/g, '+');
} else if (!nURI.startsWith("http://") && !nURI.startsWith("https://")) {
console.info("USING URL: " + nURI);
nURI = "https://" + nURI;
}
const matchingKey = Object.keys(overwrites).find(key => nURI.includes(key));
if (matchingKey) {
console.info(`URI overwritten from "${nURI}" to`)
nURI = nURI.replace(matchingKey, overwrites[matchingKey])
console.log(nURI)
}
function getHostnameFromURL(urlString) {
var parser = document.createElement('a');
parser.href = urlString;
var parts = parser.hostname.split('.');
if(parts.length > 2) {
return parts.slice(1).join('.');
} else {
return parser.hostname;
}
}
const domain = getHostnameFromURL(nURI);
const proxyDomain = getHostnameFromURL(proxyURL);
if (domain == proxyDomain) {
console.info("No need to proxy!")
var URL = nURI
} else {
console.info(`Using ${proxyDomain} as proxy.`)
// Encode the URI
nURI = encode(nURI)
var URL = proxyURL + nURI
}
return URL;
}