MCPcopy Create free account
hub / github.com/The-CodingSloth/haha-funny-leetcode-extension / checkIfUserSolvedProblem

Function checkIfUserSolvedProblem

background.ts:234–317  ·  view source on GitHub ↗
(
  details: chrome.webRequest.WebResponseCacheDetails
)

Source from the content-addressed store, hash-verified

232}
233
234const checkIfUserSolvedProblem = async (
235 details: chrome.webRequest.WebResponseCacheDetails
236) => {
237 // If the user has already solved the problem, then don't do anything
238 if (await storage.getProblemSolved()) return
239 // Get the current active tab's URL
240 let currentURL = ""
241 try {
242 const [activeTab] = await new Promise<chrome.tabs.Tab[]>((resolve) => {
243 chrome.tabs.query({ active: true, currentWindow: true }, resolve)
244 })
245
246 currentURL = activeTab.url
247 } catch (error) {
248 console.error("Error getting active tab:", error)
249 return
250 }
251
252 const problemUrl = await storage.getProblemUrl()
253
254 const sameUrl =
255 problemUrl === currentURL || problemUrl + "description/" === currentURL
256
257 if (!sameUrl) {
258 return
259 }
260
261 //lastCheckedUrl = details.url
262 //lastCheckedTimestamp = now
263
264 if (state.solvedListenerActive) {
265 // Remove the listener so that it doesn't fire again, since the outcome will either be success or fail
266 // And we'll add it again when the user clicks submit
267 state.solvedListenerActive = false
268 chrome.webRequest.onCompleted.removeListener(checkIfUserSolvedProblem)
269 }
270
271 if (isSubmissionSuccessURL(details.url)) {
272 try {
273 const hyperTortureMode = await getHyperTortureMode()
274 const response = await fetch(details.url)
275 const data = await response.json()
276 if (data.state === "STARTED" || data.state === "PENDING") {
277 if (!state.solvedListenerActive) {
278 state.solvedListenerActive = true
279 chrome.webRequest.onCompleted.addListener(checkIfUserSolvedProblem, {
280 urls: ["*://leetcode.com/submissions/detail/*/check/"]
281 })
282 }
283 return
284 }
285 if (data.status_msg !== "Accepted") {
286 if (hyperTortureMode) {
287 await resetHyperTortureStreak()
288 sendUserFailedMessage()
289 }
290 return
291 }

Callers

nothing calls this directly

Calls 6

getHyperTortureModeFunction · 0.90
resetHyperTortureStreakFunction · 0.90
isSubmissionSuccessURLFunction · 0.85
sendUserFailedMessageFunction · 0.85
updateStorageFunction · 0.85
sendUserSolvedMessageFunction · 0.85

Tested by

no test coverage detected