aboutsummaryrefslogtreecommitdiff
path: root/src/main.ts
blob: 3992e63cef7f2db94d0139cb1a0ca1730c822c1c (plain)
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
import { bangs } from "./bang";

const defaultBang = bangs.find((b) => b.t === "g");

function doBangRedirect() {
  const url = new URL(window.location.href);
  const query = url.searchParams.get("q")?.trim() ?? "";
  if (!query) return null;
  const match = query.match(/!([a-z]+)/i);
  if (!match) return null;
  const bangCandidate = match[1].toLowerCase();
  const selectedBang = bangs.find((b) => b.t === bangCandidate) ?? defaultBang;

  return selectedBang;
}

const bang = doBangRedirect();
if (bang) {
  console.log("bang", bang);

  // window.location.replace(bang.d + "?q=" + encodeURIComponent(query));
}

document.querySelector<HTMLDivElement>("#app")!.innerHTML = `
  <div>
    <h1>T3 Search</h1>
  </div>
`;

setupCounter(document.querySelector<HTMLButtonElement>("#counter")!);