-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
61 lines (56 loc) · 2.01 KB
/
Copy pathscript.js
File metadata and controls
61 lines (56 loc) · 2.01 KB
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
;(() => {
if ("serviceWorker" in navigator) {
/* The "in" operator returns true if the specified property is in the specified
object or its prototype chain. this if statement is a form of feature detection */
window.addEventListener("load", () => {
/* we use load so that it registers as soon as the page loads. but you
could use another event if you wanted, like a click or something.. idk
why you would though */
navigator.serviceWorker.register("service-worker.js").then(
registration => {
console.log("service worker successfully registered!!!")
console.log("registration:", registration)
},
err => {
console.log("error:", err)
}
)
})
} else {
alert("service workers not supported in this browser")
}
})()
// ;(() => {
// fetch("https://opentdb.com/api.php?amount=1")
// .then(response => {
// // return {
// // response_code: 0,
// // results: [
// // {
// // type: "multiple",
// // difficulty: "medium",
// // category: "Sports",
// // question: "Who won the 2011 Stanley Cup?",
// // correct_answer: "Boston Bruins",
// // incorrect_answers: [Array],
// // },
// // ],
// // }.json()
// return response.json()
// // response.json will return a promise that should resolve to an object.
// /* once I call response.json(), the response body is removed from the
// response object to conserve memory and overhead (cpu time, network bandwidth)
// before being converted to an object.
// That's why you get an error when trying to call res.json() twice. there's nothing to parse.
// the only way to access it is returning it and using another .then() to
// resolve the promise and save it or use it somewhere. */
// })
// .then(data => {
// console.log(data)
// console.log(data.results[0].question)
// console.log(data.results[0].correct_answer)
// })
// .catch(err => {
// console.log(err)
// })
// })()