Skip to content

Instantly share code, notes, and snippets.

View Fanoflix's full-sized avatar
🤖
Its hustlin' time

Muhammad Ammar Fanoflix

🤖
Its hustlin' time
View GitHub Profile
@Fanoflix
Fanoflix / ctrl-enter.ts
Last active May 13, 2024 07:51
Ctrl + Enter to submit Form (Typescript)
document.body.addEventListener("keydown", (e: KeyboardEvent) => {
if (!(e.key === "Enter" && (e.metaKey || e.ctrlKey))) return
const form = (e.target as HTMLFormElement).form
if (form) form.submit() // or form.requestSubmit() depending on your usecase
})
@Fanoflix
Fanoflix / getHighlightedText.ts
Last active June 22, 2023 09:33
Method to get highlighted/selection text
const getSelectionText = () => {
const selectionText = window.getSelection()?.toString()
if (selectionText?.length) return selectionText
}