Skip to content

Commit

Permalink
feat: Remove tabs permission, add reset via logo
Browse files Browse the repository at this point in the history
Fixes #13 temporarily. Will resubmit to the Chrome Web Store after this
change.

Users can now reset the video onscreen and the extension properties by
clicking the Dance Monkey icon. I'd like to create a more intuitive
method of doing this, though!

I may switch to using browser local storage to save default
configurations for saved videos once I implement the Saved Videos page.
  • Loading branch information
tararoshan committed Mar 5, 2024
1 parent 37c7351 commit dd1fdc8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
Binary file added chrome_dance_monkey.zip
Binary file not shown.
Binary file removed firefox_dance_monkey.zip
Binary file not shown.
3 changes: 1 addition & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
},
"permissions": [
"scripting",
"storage",
"tabs"
"storage"
],
"host_permissions": [
"*://*.youtube.com/*",
Expand Down
2 changes: 1 addition & 1 deletion popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<body>
<div class="title-div">
<img class="title-icon icon" src="../assets/icon.svg">
<img id="dm-logo" class="title-icon icon" src="../assets/icon.svg">
<h1 class="title-text">dance monkey</h1>
</div>

Expand Down
45 changes: 43 additions & 2 deletions popup/popup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// popup.js - BACKGROUND SCRIPT
// popup.js - BACKGROUND SCRIPT (mostly, see end)

/**
* Note: chrome doesn't debug background scripts properly for manifest v3, see
Expand All @@ -16,6 +16,9 @@ var browser = chrome || browser;
/**
* ADD EVENT LISTENERS TO EXTENSION ELEMENTS
*/
var dmLogo = document.getElementById("dm-logo");
dmLogo.addEventListener("click", logoHandler);

var mirrorCheckbox = document.getElementById("mirror-checkbox");
mirrorCheckbox.addEventListener("change", mirrorHandler);

Expand All @@ -42,6 +45,38 @@ var delayNumInput = document.getElementById("delay-num");
// Make the styles on the extension reflect those on the video
loadStylesFromStorage();

/**
* LOGO HANDLER - CLEAR ALL PROPERTIES
*/
async function logoHandler() {
// Clear values from storage and reset affected video elements
browser.storage.session.clear();
// Clear mirror
if (mirrorCheckbox.checked) {
// Remove the mutation observer, reset the video
mirrorCheckbox.checked = false;
mirrorHandler();
}
// Clear playback speed
speedNumInput.value = 1;
speedHandler.bind(!SLIDER_INPUT)();
// Clear loop -- if out of bounds of video duration, clears the loop
let loopStartTime = 0;
let loopStopTime = Number.MAX_SAFE_INTEGER;
browser.scripting.executeScript({
args: [loopStartTime, loopStopTime],
func: loopVideoContentScript,
target: {
tabId: await getActiveTabId(),
allFrames: true,
},
});
loopStartMinsec.value = "";
loopStopMinsec.value = "";
// Clear delay
delayNumInput.value = 0;
}

/**
* MIRROR VIDEO HANDLER
*/
Expand Down Expand Up @@ -230,7 +265,13 @@ async function getActiveTabId() {
}

/**
*
* Clears the previous loop and starts looping with the new start and stop time.
* If the stop time is past the end of the video, loops to the end of the video.
*
* Note that this function is a content script and runs in the same context as
* the scripts in observerContent.js. I'll move it there later when I clean up
* the code!
*
* @param {*} loopStartTime
* @param {*} loopStopTime
*/
Expand Down

0 comments on commit dd1fdc8

Please sign in to comment.