sneedium/libbrowz.js

88 lines
2.9 KiB
JavaScript
Raw Normal View History

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}`;
}
}
2023-03-02 17:26:33 -06:00
function go() {
let browserFrame = tabGroup.getActiveTab().webview
2023-03-09 04:04:28 -06:00
let browser = tabGroup.getActiveTab()
2024-08-12 16:30:58 -05:00
let url = normalizeUrl(document.getElementById("txtUrl").value)
2023-03-09 08:03:50 -06:00
if (url.includes("youtube.com") || url.includes("youtu.be")) {
2024-08-12 18:04:40 -05:00
url = url.replaceAll("youtube.com", "invidious.perennialte.ch")
url = url.replaceAll("youtu.be", "invidious.perennialte.ch")
2023-03-09 08:18:28 -06:00
} else if (url.includes("google.com/?q")) {
url = url.replaceAll("google.com/?q", "startpage.com/?q")
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-08-12 17:38:03 -05: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 = 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 = ""
browserFrame.loadURL(url);
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
for (let i = 0; i < userscripts.length; i++) {
2023-03-09 05:25:24 -06:00
fetch(userscripts[i]).then( r => r.text() ).then( t => userscripts.executeJavaScript(t)).catch(() => {
console.log("Error loading userscripts! (Did you provide any?)")
2023-03-02 18:20:58 -06:00
})
2023-03-02 17:26:33 -06:00
}
}
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()
}
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()
}
2023-03-09 04:04:28 -06:00
}
2023-03-09 08:03:50 -06:00