close ish
This commit is contained in:
		
							parent
							
								
									92ab49147f
								
							
						
					
					
						commit
						cb6f2bf817
					
				
					 4 changed files with 122081 additions and 30 deletions
				
			
		| 
						 | 
					@ -4,7 +4,7 @@
 | 
				
			||||||
    <meta charset="UTF-8" />
 | 
					    <meta charset="UTF-8" />
 | 
				
			||||||
    <link rel="icon" type="image/svg+xml" href="/vite.svg" />
 | 
					    <link rel="icon" type="image/svg+xml" href="/vite.svg" />
 | 
				
			||||||
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 | 
					    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 | 
				
			||||||
    <title>Vite + TS</title>
 | 
					    <title>T3 Search</title>
 | 
				
			||||||
  </head>
 | 
					  </head>
 | 
				
			||||||
  <body>
 | 
					  <body>
 | 
				
			||||||
    <div id="app"></div>
 | 
					    <div id="app"></div>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										122054
									
								
								src/bang.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										122054
									
								
								src/bang.ts
									
										
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							| 
						 | 
					@ -1,9 +0,0 @@
 | 
				
			||||||
export function setupCounter(element: HTMLButtonElement) {
 | 
					 | 
				
			||||||
  let counter = 0
 | 
					 | 
				
			||||||
  const setCounter = (count: number) => {
 | 
					 | 
				
			||||||
    counter = count
 | 
					 | 
				
			||||||
    element.innerHTML = `count is ${counter}`
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  element.addEventListener('click', () => setCounter(counter + 1))
 | 
					 | 
				
			||||||
  setCounter(0)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										46
									
								
								src/main.ts
									
										
									
									
									
								
							
							
						
						
									
										46
									
								
								src/main.ts
									
										
									
									
									
								
							| 
						 | 
					@ -1,24 +1,30 @@
 | 
				
			||||||
import './style.css'
 | 
					import { bangs } from "./bang";
 | 
				
			||||||
import typescriptLogo from './typescript.svg'
 | 
					 | 
				
			||||||
import viteLogo from '/vite.svg'
 | 
					 | 
				
			||||||
import { setupCounter } from './counter.ts'
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
document.querySelector<HTMLDivElement>('#app')!.innerHTML = `
 | 
					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>
 | 
					  <div>
 | 
				
			||||||
    <a href="https://vite.dev" target="_blank">
 | 
					    <h1>T3 Search</h1>
 | 
				
			||||||
      <img src="${viteLogo}" class="logo" alt="Vite logo" />
 | 
					 | 
				
			||||||
    </a>
 | 
					 | 
				
			||||||
    <a href="https://www.typescriptlang.org/" target="_blank">
 | 
					 | 
				
			||||||
      <img src="${typescriptLogo}" class="logo vanilla" alt="TypeScript logo" />
 | 
					 | 
				
			||||||
    </a>
 | 
					 | 
				
			||||||
    <h1>Vite + TypeScript</h1>
 | 
					 | 
				
			||||||
    <div class="card">
 | 
					 | 
				
			||||||
      <button id="counter" type="button"></button>
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
    <p class="read-the-docs">
 | 
					 | 
				
			||||||
      Click on the Vite and TypeScript logos to learn more
 | 
					 | 
				
			||||||
    </p>
 | 
					 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
`
 | 
					`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
setupCounter(document.querySelector<HTMLButtonElement>('#counter')!)
 | 
					setupCounter(document.querySelector<HTMLButtonElement>("#counter")!);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue