Skip to content

Commit

Permalink
1.0.5
Browse files Browse the repository at this point in the history
Add an option to skip through "chapters" on youtube videos using the
Next/Previous bangs.
  • Loading branch information
aminomancer committed Dec 11, 2022
1 parent 7b40fab commit 728974b
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 86 deletions.
24 changes: 4 additions & 20 deletions Options.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,27 +164,11 @@ <h1>WebNowPlaying Options</h1>
</div>
</div>

<p style="float:left;">Websocket connection settings</p>
<p style="font-size: 1rem;font-weight: 300;">
&#160;(Not yet implemented)
</p>
<div id="websocketOptions" class="disabled suboptions">
<p>YouTube settings</p>
<div id="youtubeOptions" class="suboptions">
<label>
<input
type="checkbox"
id="WNP"
disabled="disabled"
checked="checked"
/>
Send detected music info to the WebNowPlaying Rainmeter plugin
</label>
<label>
<input type="checkbox" id="UNP" disabled="disabled" /> Send detected
music info to the UnNowPlaying Rainmeter plugin (Unreleased)
</label>
<label>
<input type="checkbox" id="Twitch" disabled="disabled" /> Send
detected music info to the WebNowPlaying Twitch extension (Unreleased)
<input type="checkbox" id="useChapters" /> Skip to chapters within the
current video when using Next/Previous bangs (if chapters exist)
</label>
</div>

Expand Down
92 changes: 37 additions & 55 deletions Options.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,57 @@
var thisDoGeneric = false;
var thisUseGenericList = false;
var thisWhitelistOrBlacklist = "whitelist";
var thisGenericList = ["streamable.com", "www.adultswim.com"];
const options = {
doGeneric: false,
useGenericList: false,
whitelistOrBlacklist: "whitelist",
genericList: ["streamable.com", "www.adultswim.com"],
useChapters: false,
};

// Saves options to chrome.storage
function saveOptions() {
thisDoGeneric = document.getElementById("generic").checked;
thisUseGenericList = document.getElementById("useGenericList").checked;
thisWhitelistOrBlacklist = document.getElementById("listType").value;
thisGenericList = document.getElementById("genericList").value.split("\n");
chrome.storage.sync.set({
doGeneric: thisDoGeneric,
useGenericList: thisUseGenericList,
whitelistOrBlacklist: thisWhitelistOrBlacklist,
genericList: thisGenericList,
});
function updateOptions() {
options.doGeneric = document.getElementById("generic").checked;
options.useGenericList = document.getElementById("useGenericList").checked;
options.whitelistOrBlacklist = document.getElementById("listType").value;
options.genericList = document
.getElementById("genericList")
.value.split("\n");
options.useChapters = document.getElementById("useChapters").checked;
}

// Restores select box and checkbox state using the preferences
// stored in chrome.storage.
function restoreOptions() {
// Use default value color = 'red' and likesColor = true.
chrome.storage.sync.get(
{
doGeneric: false,
useGenericList: false,
whitelistOrBlacklist: "whitelist",
genericList: ["streamable.com", "www.adultswim.com"],
},
function(items) {
document.getElementById("generic").checked = items.doGeneric;
document.getElementById("useGenericList").checked = items.useGenericList;
document.getElementById("listType").value = items.whitelistOrBlacklist;
document.getElementById("genericList").value = items.genericList.join(
"\n"
);
chrome.storage.sync.get(options, function(items) {
document.getElementById("generic").checked = items.doGeneric;
document.getElementById("useGenericList").checked = items.useGenericList;
document.getElementById("listType").value = items.whitelistOrBlacklist;
document.getElementById("genericList").value = items.genericList.join("\n");
document.getElementById("useChapters").checked = items.useChapters;

thisDoGeneric = document.getElementById("generic").checked;
thisUseGenericList = document.getElementById("useGenericList").checked;
thisWhitelistOrBlacklist = document.getElementById("listType").value;
thisGenericList = document
.getElementById("genericList")
.value.split("\n");
}
);
updateOptions();
});
}

function checkSaveOptions() {
var isChanged = thisDoGeneric != document.getElementById("generic").checked;
isChanged =
isChanged ||
thisUseGenericList != document.getElementById("useGenericList").checked;
isChanged =
isChanged ||
thisWhitelistOrBlacklist != document.getElementById("listType").value;
isChanged =
isChanged ||
thisGenericList.toString() !=
function maybeSaveOptions() {
let isChanged =
options.doGeneric != document.getElementById("generic").checked ||
options.useGenericList !=
document.getElementById("useGenericList").checked ||
options.whitelistOrBlacklist != document.getElementById("listType").value ||
options.genericList.toString() !=
document
.getElementById("genericList")
.value.split("\n")
.toString();
.toString() ||
options.useChapters != document.getElementById("useChapters").checked;
if (isChanged) {
saveOptions();
updateOptions();
chrome.storage.sync.set(options);
}
}

document.addEventListener("DOMContentLoaded", restoreOptions);
document.addEventListener("input", maybeSaveOptions);
window.onbeforeunload = function(e) {
saveOptions();
updateOptions();
chrome.storage.sync.set(options);
};

//Check if changed before saving so rate limit should not be hit
setInterval(checkSaveOptions, 500);
Loading

0 comments on commit 728974b

Please sign in to comment.