sneedium/libbrowz.js

114 lines
4.1 KiB
JavaScript
Raw Normal View History

2024-08-13 16:38:10 -05:00
const userAgents = [
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Firefox/128.0",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Edg/120.0.0.0",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Edg/98.0.0.0",
"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
2024-11-21 14:57:11 -06:00
"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0"
2024-08-13 16:38:10 -05:00
];
function getRandomUserAgent() {
const randomIndex = Math.floor(Math.random() * userAgents.length);
return userAgents[randomIndex];
}
let currentUA = "" // We haven't loaded any websites yet. It should be blank.
2023-03-02 17:26:33 -06:00
let tabGroup = document.querySelector("tab-group");
2024-08-12 16:30:58 -05:00
function normalizeUrl(url) {
// Define regex patterns for matching URL schemes and local addresses
const httpPattern = /^http:\/\//i;
const httpsPattern = /^https:\/\//i;
const filePattern = /^file:\/\//i;
const indexPattern = /^index\.html/i;
const localPattern = /^(192\.168|127\.0|localhost)/i;
// Check if the URL already has a valid scheme
if (httpPattern.test(url) || httpsPattern.test(url) || filePattern.test(url) || indexPattern.test(url)) {
return url;
}
// Determine if the URL starts with a local address or needs HTTPS
if (localPattern.test(url)) {
return `http://${url}`;
} else {
return `https://${url}`;
}
}
2024-08-13 14:35:15 -05:00
let url = undefined
let browserFrame = undefined
2023-03-02 17:26:33 -06:00
function go() {
2024-08-13 16:38:10 -05:00
currentUA = getRandomUserAgent()
2024-08-13 14:35:15 -05:00
browserFrame = tabGroup.getActiveTab().webview
2023-03-09 04:04:28 -06:00
let browser = tabGroup.getActiveTab()
2024-08-13 14:35:15 -05:00
url = normalizeUrl(document.getElementById("txtUrl").value)
if (url.includes("google.com/search?q") || url.includes("google.com/?q")) {
2024-08-13 18:31:17 -05:00
// Define the URL object
const serachUrlObj = new URL(url);
//Get query from old url
const query = serachUrlObj.searchParams.get('q');
// Define the pattern for URL replacement
const searchPattern = "https://search.sparksammy.com/search.php?q=!!!QUERY!!!&p=0&t=0";
url = searchPattern.replaceAll("!!!QUERY!!!", query)
2023-03-09 08:27:36 -06:00
} else if (url.includes("https://news.google.com")) {
url = url.replaceAll("https://news.google.com", "http://68k.news")
2024-11-21 15:12:04 -06:00
} else if (url.includes("google.com") && !url.includes("maps") && !url.includes("news") && !url.includes("webstore") && !url.includes("drive") && !url.includes("docs") && !url.includes("sheets") && !url.includes("slides") && !url.includes("mail") && !url.includes("webstore")) {
2024-08-12 17:38:03 -05:00
url = url.replaceAll("google.com", "search.sparksammy.com")
2023-03-09 08:03:50 -06:00
}
2023-03-09 06:00:35 -06:00
document.getElementById("txtUrl").value = ""
2024-08-13 14:35:15 -05:00
browserFrame.loadURL(url,
2024-08-13 16:38:10 -05:00
{userAgent: currentUA});
2023-03-09 04:04:28 -06:00
browserFrame.addEventListener('dom-ready', () => {
browserFrame.insertCSS(`
::-webkit-scrollbar {
display: none;
}
`)
})
2023-03-02 17:26:33 -06:00
browserFrame.addEventListener("page-title-updated", (titleEvent) => {
let title = browserFrame.getTitle()
tabGroup.getActiveTab().setTitle(title)
console.log(title)
})
}
2023-03-09 04:04:28 -06:00
function stop() {
let browserFrame = tabGroup.getActiveTab().webview
browserFrame.stop()
}
2023-03-02 17:26:33 -06:00
function back() {
let browserFrame = tabGroup.getActiveTab().webview
browserFrame.goBack()
}
2023-03-09 04:04:28 -06:00
2023-03-02 17:26:33 -06:00
function forward() {
let browserFrame = tabGroup.getActiveTab().webview
browserFrame.goForward()
}
2024-08-13 14:35:15 -05:00
function refresh() {
if (typeof url != undefined) {
browserFrame.loadURL(browserFrame.getURL(),
2024-08-13 16:38:10 -05:00
{userAgent: currentUA});
2024-08-13 14:35:15 -05:00
} else {
window.location.reload()
}
}
2023-03-02 17:26:33 -06:00
tabGroup.setDefaultTab({
title: CONF.homepageTitle,
src: CONF.homepage,
active: true
});
tabGroup.addTab()
2023-03-09 04:04:28 -06:00
2023-03-02 17:26:33 -06:00
function clickPress(keyEvent) {
if (keyEvent.keyCode == 13) {
go()
}
2024-08-13 14:35:15 -05:00
}