-
Notifications
You must be signed in to change notification settings - Fork 2
/
chrome-home.ts
197 lines (168 loc) · 5 KB
/
chrome-home.ts
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// A JS shortcut that adds proper keyboard shortcuts to StackBlitz and doubles
// the speed of a video in YouTube when activated. #bookmarklet
import { produce } from "immer"
namespace Device {
export function isPWA() {
return window.matchMedia("(display-mode: standalone)").matches
}
export function isMac() {
return navigator.platform.includes("Mac")
}
}
namespace Keyboard {
export function Keys({ altKey, ctrlKey, metaKey, shiftKey }: KeyboardEvent) {
let altOnly = altKey && !metaKey && !ctrlKey
let ctrlOnly = ctrlKey && !metaKey && !altKey
let metaOnly = metaKey && !ctrlKey && !altKey
let cmdOnly = Device.isMac() ? metaOnly : ctrlOnly
return {
altOnly,
cmdOnly,
ctrlOnly,
metaOnly,
shift: shiftKey,
}
}
}
namespace VideoPlayer {
export function Initialize() {
for (let video of document.querySelectorAll("video")) {
video.playbackRate = 2
}
}
}
namespace StackBlitz {
export function Handler(event: KeyboardEvent) {
let { cmdOnly, ctrlOnly } = Keyboard.Keys(event)
let { editorBar, editorCloseButton, terminalCloseButton } = GetFocused()
if (event.key === "w" && ((Device.isPWA() && cmdOnly) || ctrlOnly)) {
if (terminalCloseButton) {
;(terminalCloseButton as any).click()
} else if (editorCloseButton) {
;(editorCloseButton as any).click()
} else if (!editorBar) {
// close window
return
}
event.preventDefault()
}
}
export function GetFocused() {
let editorTab =
document.querySelector(
'[class*="Editor-module-panel"]:focus-within #editor-tabbar-0 > [class*=focused]',
) || undefined
let terminal =
document.querySelector(".terminal-tile:focus-within") || undefined
return {
terminal,
terminalCloseButton:
terminal?.querySelector(".Action:last-of-type") ?? undefined,
editorTab,
editorCloseButton: editorTab?.children[1]!,
editorBar: document.querySelector("#editor-tabbar-0") ?? undefined,
}
}
if (window.__stackblitzPreviousHandler) {
window.removeEventListener("keydown", window.__stackblitzPreviousHandler)
}
export function Initialize() {
window.__stackblitzPreviousHandler = Handler
window.addEventListener("keydown", Handler)
}
}
namespace GoogleDocs {
function createFrame() {
const frame = document.createElement("iframe")
frame.style.display = "block"
frame.style.position = "fixed"
frame.style.zIndex = "1000000"
frame.style.top = "122.5px"
frame.style.right = "72px"
frame.style.width = "420px"
frame.style.height = "calc(100vh - 185px)"
frame.style.border = "none"
frame.setAttribute("crossorigin", "anonymous")
frame.src = "https://zsnout.com/"
return frame
}
export function Initialize() {
const frame = createFrame()
window.frame = frame
document.body.appendChild(frame)
}
}
namespace MySchoolApp {
export function SignIn() {
const field = document.getElementById("Username")
const next = document.getElementById("nextBtn")
if (!(field instanceof HTMLInputElement)) return
if (!next) return
field.value = "[email protected]"
next.click()
}
}
namespace BlackBaud {
export function ClickGoogleSignIn() {
const el = document.getElementById("googleButtonLabel")
if (!el) return
el.click()
}
}
namespace Blooket {
export function Initialize() {
const root = document.querySelector("#app > div > div")
if (!root) {
console.error("no root found on this page")
} else {
const values = Object.values(root)[1]!.children
const reactRoot = (values[1] || values[0])._owner
Object.assign(window, { react: reactRoot })
const stateNode = reactRoot.stateNode
Object.assign(window, { sn: stateNode })
Object.defineProperty(window, "s", {
configurable: true,
get() {
return stateNode.state
},
set(value) {
if (typeof value == "function") {
stateNode.setState(produce(value))
} else {
stateNode.setState(value)
}
},
})
}
}
}
namespace YouTube {
export function Initialize() {
location.href =
"https://zsnout.com/youtube-downloader?url=" +
encodeURIComponent(location.href)
}
}
if (location.host.includes("stackblitz.com")) {
StackBlitz.Initialize()
} else if (
location.host.includes("docs.google.com") &&
location.pathname.startsWith("/document")
) {
GoogleDocs.Initialize()
} else if (location.host == "sfbrandeis.myschoolapp.com") {
MySchoolApp.SignIn()
} else if (location.host == "app.blackbaud.com") {
BlackBaud.ClickGoogleSignIn()
} else if (location.host.includes("blooket.com")) {
Blooket.Initialize()
} else if (location.host.includes("youtube.com")) {
YouTube.Initialize()
} else if (document.querySelector("video")) {
VideoPlayer.Initialize()
}
declare global {
var __stackblitzPreviousHandler: typeof StackBlitz.Handler
var frame: HTMLIFrameElement
}
export {}