-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an option to skip through "chapters" on youtube videos using the Next/Previous bangs.
- Loading branch information
1 parent
7b40fab
commit 728974b
Showing
4 changed files
with
226 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.