|
14 | 14 | (async function () { |
15 | 15 | "use strict"; |
16 | 16 |
|
17 | | - function loadAudioInIframe(soundObj) { // weird thing to get around college board not allowing external audio sources to be played |
18 | | - let iframe = document.createElement('iframe') |
19 | | - iframe.id = "audioIframe" |
20 | | - iframe.src = chrome.runtime.getURL('/iframe/audioPlayerIframe.html'); |
21 | | - iframe.allow = "autoplay" |
| 17 | + function loadAudioInIframe(soundObj) { |
| 18 | + // weird thing to get around college board not allowing external audio sources to be played |
| 19 | + let iframe = document.createElement("iframe"); |
| 20 | + iframe.id = "audioIframe"; |
| 21 | + iframe.src = chrome.runtime.getURL("/iframe/audioPlayerIframe.html"); |
| 22 | + iframe.allow = "autoplay"; |
22 | 23 | iframe.style = ` |
23 | 24 | position: fixed; |
24 | 25 | top: 0; |
|
27 | 28 | height: 0; |
28 | 29 | `; |
29 | 30 | iframe.frameBorder = 0; |
30 | | - iframe.scrolling = 'no'; |
| 31 | + iframe.scrolling = "no"; |
31 | 32 |
|
32 | | - iframe.addEventListener('load', () => { |
33 | | - iframe.contentWindow.postMessage({sounds: soundObj, message: "setup"}, '*'); |
| 33 | + iframe.addEventListener("load", () => { |
| 34 | + iframe.contentWindow.postMessage({ sounds: soundObj, message: "setup" }, "*"); |
34 | 35 | }); |
35 | 36 |
|
36 | 37 | document.body.appendChild(iframe); |
37 | 38 | } |
38 | 39 |
|
39 | | - function playSoundInFrame(score){ |
40 | | - let iframe = document.getElementById("audioIframe") |
41 | | - iframe.contentWindow.postMessage({message: "score", score: score}, "*") |
| 40 | + function playSoundInFrame(score) { |
| 41 | + let iframe = document.getElementById("audioIframe"); |
| 42 | + iframe.contentWindow.postMessage({ message: "score", score: score }, "*"); |
42 | 43 | } |
43 | 44 |
|
44 | | - function getObjWithId(array, id){ |
45 | | - for (let obj of array){ |
46 | | - if (obj.id === id){ |
47 | | - return obj |
| 45 | + function getObjWithId(array, id) { |
| 46 | + for (let obj of array) { |
| 47 | + if (obj.id === id) { |
| 48 | + return obj; |
48 | 49 | } |
49 | 50 | } |
| 51 | + return null; |
50 | 52 | } |
51 | 53 |
|
52 | | - const selectSoundsObj = await chrome.storage.local.get("selectedSounds") // get the response from storage |
53 | | - const selectedSounds = selectSoundsObj.selectedSounds |
54 | | - const soundStorage = await chrome.storage.local.get("sounds") // get the response from storage |
55 | | - const soundArray = soundStorage.sounds |
56 | | - let sounds = {} |
| 54 | + const selectSoundsObj = await chrome.storage.local.get("selectedSounds"); // get the response from storage |
| 55 | + const selectedSounds = selectSoundsObj.selectedSounds; |
| 56 | + const soundStorage = await chrome.storage.local.get("sounds"); // get the response from storage |
| 57 | + const soundArray = soundStorage.sounds; |
| 58 | + let sounds = {}; |
57 | 59 |
|
58 | | - for (let score in selectedSounds) { // basically transfering this new format to the old format |
59 | | - sounds[score] = getObjWithId(soundArray, selectedSounds[score]).URL |
| 60 | + for (let score in selectedSounds) { |
| 61 | + // basically transfering this new format to the old format |
| 62 | + sounds[score] = getObjWithId(soundArray, selectedSounds[score])?.URL || ""; |
60 | 63 | } |
61 | | - console.log(sounds) |
62 | | - loadAudioInIframe(sounds) |
| 64 | + // console.log(sounds); |
| 65 | + loadAudioInIframe(sounds); |
63 | 66 |
|
64 | 67 | // Grab all of the boxes that contain scores |
65 | 68 | document.body.style.opacity = "0%"; // Hide the entire page until we can hide the scores themselves |
|
86 | 89 | ccontainer.parentNode.parentNode.style.cursor = "pointer"; // Makes the mouse display a pointer when you hover over the place the score should be |
87 | 90 | ccontainer.parentNode.children[1].style.pointerEvents = "none"; // Make the sidebar not clickable |
88 | 91 |
|
89 | | - const clickListener = (e) => { |
| 92 | + const clickListener = (e) => { |
90 | 93 | e.stopPropagation(); |
91 | 94 | const container = ccontainer.querySelector(".apscores-badge.apscores-badge-score"); // Have to do this again because reference gets messed |
92 | 95 | const scoreNode = container.childNodes[1]; // Grab the text box that holds the score number |
93 | 96 | const score = parseInt(scoreNode.nodeValue); // Get the score as a number (not a string) |
94 | | - playSoundInFrame(score) |
| 97 | + playSoundInFrame(score); |
95 | 98 | if (score >= 3) { |
96 | 99 | const { left, top } = ccontainer.getBoundingClientRect(); |
97 | 100 |
|
|
0 commit comments