Add embed option and component

Other fixes: tiles in proxy page for settings, updated search function, fixed defaults
This commit is contained in:
MotorTruck1221 2023-12-26 03:35:41 -07:00
parent 6235ebfe24
commit 3a9024d1e0
10 changed files with 78 additions and 23 deletions

View file

@ -1,5 +1,8 @@
import { RammerheadEncode } from "../util/RammerheadEncode";
import { searchUtil } from "../util/searchUtil";
import { useEffect, useState } from "preact/hooks";
//import our Iframe component
import { Iframe } from "../components/iframe/Iframe";
declare global {
interface Window {
@ -10,21 +13,16 @@ declare global {
export function ProxyFrame(props: { url: string }) {
// pass the URL encoded with encodeURIcomponent
var localProxy = localStorage.getItem("proxy") || "automatic";
var proxyMode = localStorage.getItem("proxyMode") || "direct";
const localProxy = localStorage.getItem("proxy") || "automatic";
const proxyMode = localStorage.getItem("proxyMode") || "direct";
var [ProxiedUrl, setProxiedUrl] = useState<string | undefined>(undefined);
const [ProxiedUrl, setProxiedUrl] = useState<string | undefined>(undefined);
var decodedUrl = decodeURIComponent(props.url);
let decodedUrl = decodeURIComponent(props.url);
//attempt to convert to a valid url
decodedUrl = searchUtil(decodedUrl, "https://google.com/search?q=%s");
var proxyRef;
if (!decodedUrl.includes(".")) {
decodedUrl = "https://www.google.com/search?q=" + decodedUrl; // If the users input has no . then we change it to a google query. TODO: Feature to change search engines
}
if (!decodedUrl.startsWith("http://") || !decodedUrl.startsWith("https://")) {
decodedUrl = "https://" + decodedUrl;
}
let proxyRef;
useEffect(() => {
// For now we can redirect to the results. In the future we will add an if statement looking for the users proxy display choice
@ -50,7 +48,8 @@ export function ProxyFrame(props: { url: string }) {
if (proxyMode == "direct") {
window.location.href = ProxiedUrl;
} else if (proxyMode == "aboutblank") {
}
else if (proxyMode == "aboutblank") {
const newWindow = window.open("about:blank", "_blank");
const newDocument = newWindow.document.open();
newDocument.write(`
@ -73,13 +72,13 @@ export function ProxyFrame(props: { url: string }) {
`);
newDocument.close()
window.location.replace("/");
} else {
// iframe
}
return (
<div class="h-screen w-screen bg-primary">
{proxyMode === "direct" && <h1>Loading {localProxy}...</h1>}
{proxyMode === "aboutblank" && <h1>Loading {localProxy}...</h1>}
{proxyMode === "embed" && <Iframe url={ProxiedUrl} normalUrl={decodedUrl} />}
</div>
); // @TODO: Routing (iframe, ab, direct, etc.)
);
}