|
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" |
| 22 | + iframe.style = ` |
| 23 | + position: fixed; |
| 24 | + top: 0; |
| 25 | + left: 0; |
| 26 | + width: 0; |
| 27 | + height: 0; |
| 28 | + `; |
| 29 | + iframe.frameBorder = 0; |
| 30 | + iframe.scrolling = 'no'; |
| 31 | + |
| 32 | + iframe.addEventListener('load', () => { |
| 33 | + iframe.contentWindow.postMessage({sounds: soundObj, message: "setup"}, '*'); |
| 34 | + }); |
| 35 | + |
| 36 | + document.body.appendChild(iframe); |
| 37 | + } |
| 38 | + |
| 39 | + function playSoundInFrame(score){ |
| 40 | + let iframe = document.getElementById("audioIframe") |
| 41 | + iframe.contentWindow.postMessage({message: "score", score: score}, "*") |
| 42 | + } |
| 43 | + |
| 44 | + function getObjWithId(array, id){ |
| 45 | + for (let obj of array){ |
| 46 | + if (obj.id === id){ |
| 47 | + return obj |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 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 = {} |
| 57 | + |
| 58 | + for (let score in selectedSounds) { // basically transfering this new format to the old format |
| 59 | + sounds[score] = getObjWithId(soundArray, selectedSounds[score]).URL |
| 60 | + } |
| 61 | + console.log(sounds) |
| 62 | + loadAudioInIframe(sounds) |
| 63 | + |
17 | 64 | // Grab all of the boxes that contain scores |
18 | 65 | document.body.style.opacity = "0%"; // Hide the entire page until we can hide the scores themselves |
19 | 66 | let ccontainers = []; |
|
39 | 86 | ccontainer.parentNode.parentNode.style.cursor = "pointer"; // Makes the mouse display a pointer when you hover over the place the score should be |
40 | 87 | ccontainer.parentNode.children[1].style.pointerEvents = "none"; // Make the sidebar not clickable |
41 | 88 |
|
42 | | - const clickListener = (e) => { |
| 89 | + const clickListener = (e) => { |
43 | 90 | e.stopPropagation(); |
44 | 91 | const container = ccontainer.querySelector(".apscores-badge.apscores-badge-score"); // Have to do this again because reference gets messed |
45 | 92 | const scoreNode = container.childNodes[1]; // Grab the text box that holds the score number |
46 | 93 | const score = parseInt(scoreNode.nodeValue); // Get the score as a number (not a string) |
| 94 | + playSoundInFrame(score) |
47 | 95 | if (score >= 3) { |
48 | 96 | const { left, top } = ccontainer.getBoundingClientRect(); |
49 | 97 |
|
|
0 commit comments