aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay Ramachandran <[email protected]>2019-08-24 14:03:04 -0400
committerGitHub <[email protected]>2019-08-24 14:03:04 -0400
commit8604788d272dfa51f35b95a410151cc7981d74aa (patch)
tree83afe5273bbeb505ebfcb50d2d45018be0f3bfd2
parent5802e05228f08aa18218a16ffaf57ec9549dbd69 (diff)
parent519a822751f9c365fb320f3e9e3cf7b3c08a451c (diff)
downloadSponsorBlock-8604788d272dfa51f35b95a410151cc7981d74aa.tar.gz
SponsorBlock-8604788d272dfa51f35b95a410151cc7981d74aa.zip
Merge branch 'experimental' into patch-24
-rw-r--r--background.js40
-rw-r--r--content.js18
-rw-r--r--manifest.json2
-rw-r--r--utils.js54
4 files changed, 62 insertions, 52 deletions
diff --git a/background.js b/background.js
index aa25e379..28fd6bb0 100644
--- a/background.js
+++ b/background.js
@@ -7,29 +7,29 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
switch(request.message) {
case "submitTimes":
- submitTimes(request.videoID, callback);
-
- //this allows the callback to be called later by the submitTimes function
- return true;
+ submitTimes(request.videoID, callback);
+
+ //this allows the callback to be called later by the submitTimes function
+ return true;
case "addSponsorTime":
- addSponsorTime(request.time, request.videoID, callback);
-
- //this allows the callback to be called later
- return true;
+ addSponsorTime(request.time, request.videoID, callback);
+
+ //this allows the callback to be called later
+ return true;
case "getSponsorTimes":
- getSponsorTimes(request.videoID, function(sponsorTimes) {
- callback({
- sponsorTimes: sponsorTimes
- })
- });
-
- //this allows the callback to be called later
- return true;
+ getSponsorTimes(request.videoID, function(sponsorTimes) {
+ callback({
+ sponsorTimes: sponsorTimes
+ })
+ });
+
+ //this allows the callback to be called later
+ return true;
case "submitVote":
- submitVote(request.type, request.UUID, callback);
-
- //this allows the callback to be called later
- return true;
+ submitVote(request.type, request.UUID, callback);
+
+ //this allows the callback to be called later
+ return true;
case "alertPrevious":
chrome.notifications.create("stillThere" + Math.random(), {
type: "basic",
diff --git a/content.js b/content.js
index 2be7ce4d..b2bf0f5c 100644
--- a/content.js
+++ b/content.js
@@ -666,12 +666,15 @@ function isSubmitButtonLoaded() {
return document.getElementById("submitButton") !== null;
}
-function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
- if(!sponsorVideoID) return false;
- wait(isSubmitButtonLoaded).then(result => {
+async function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
+ if(!sponsorVideoID) return false;
+
+ //make sure submit button is loaded
+ await wait(isSubmitButtonLoaded);
+
//if it isn't visible, there is no data
- let shouldHide = (uploadButtonVisible && !hideDeleteButtonPlayerControls) ? "unset":"none"
- document.getElementById("deleteButton").style.display = shouldHide;
+ let shouldHide = (uploadButtonVisible && !hideDeleteButtonPlayerControls) ? "unset" : "none"
+ document.getElementById("deleteButton").style.display = shouldHide;
if (showStartSponsor) {
showingStartSponsor = true;
@@ -692,7 +695,6 @@ function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
//disable submit button
document.getElementById("submitButton").style.display = "none";
}
- });
}
function toggleStartSponsorButton() {
@@ -896,7 +898,7 @@ function submitSponsorTimes() {
//called after all the checks have been made that it's okay to do so
function sendSubmitMessage(){
//add loading animation
- document.getElementById("submitButtonImage").src = chrome.extension.getURL("icons/PlayerUploadIconSponsorBlocker256px.png");
+ document.getElementById("submitImage").src = chrome.extension.getURL("icons/PlayerUploadIconSponsorBlocker256px.png");
document.getElementById("submitButton").style.animation = "rotate 1s 0s infinite";
let currentVideoID = sponsorVideoID;
@@ -931,7 +933,7 @@ function sendSubmitMessage(){
} else {
//show that the upload failed
document.getElementById("submitButton").style.animation = "unset";
- document.getElementById("submitButtonImage").src = chrome.extension.getURL("icons/PlayerUploadFailedIconSponsorBlocker256px.png");
+ document.getElementById("submitImage").src = chrome.extension.getURL("icons/PlayerUploadFailedIconSponsorBlocker256px.png");
if([400,429,409,502].includes(response.statusCode)) {
alert(chrome.i18n.getMessage(response.statusCode));
diff --git a/manifest.json b/manifest.json
index d9dc24d5..2e883ddf 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,7 +1,7 @@
{
"name": "__MSG_fullName__",
"short_name": "__MSG_Name__",
- "version": "1.1.4",
+ "version": "1.1.6",
"default_locale": "en",
"description": "__MSG_Description__",
"content_scripts": [
diff --git a/utils.js b/utils.js
index 32dbbf36..2ec274a5 100644
--- a/utils.js
+++ b/utils.js
@@ -1,42 +1,49 @@
// Function that can be used to wait for a condition before returning
async function wait(condition, timeout = 5000, check = 100) {
- return await new Promise((resolve, reject) => {
- setTimeout(() => {reject("TIMEOUT")}, timeout);
- const interval = setInterval(() => {
- let result = condition();
- if (result !== false) {
- resolve(result);
- clearInterval(interval);
- };
- }, check);
- });
+ return await new Promise((resolve, reject) => {
+ setTimeout(() => reject("TIMEOUT"), timeout);
+
+ let intervalCheck = () => {
+ let result = condition();
+ if (result !== false) {
+ resolve(result);
+ clearInterval(interval);
+ };
+ };
+
+ let interval = setInterval(intervalCheck, check);
+
+ //run the check once first, this speeds it up a lot
+ intervalCheck();
+ });
}
function getYouTubeVideoID(url) {
//Attempt to parse url
let urlObject = null;
try {
- urlObject = new URL(url);
+ urlObject = new URL(url);
} catch (e) {
- console.error("[SB] Unable to parse URL: " + url);
- return false;
+ console.error("[SB] Unable to parse URL: " + url);
+ return false;
}
-
+
//Check if valid hostname
if(!["www.youtube.com","www.youtube-nocookie.com"].includes(urlObject.host)) return false;
-
+
//Get ID from searchParam
if ((urlObject.pathname == "/watch" || urlObject.pathname == "/watch/") && urlObject.searchParams.has("v")) {
- id = urlObject.searchParams.get("v");
- return id.length == 11 ? id : false;
+ id = urlObject.searchParams.get("v");
+ return id.length == 11 ? id : false;
} else if (urlObject.pathname.startsWith("/embed/")) {
- try {
- return urlObject.pathname.substr(7, 11);
- } catch (e) {
- console.error("[SB] Video ID not valid for " + url);
- return false;
- }
+ try {
+ return urlObject.pathname.substr(7, 11);
+ } catch (e) {
+ console.error("[SB] Video ID not valid for " + url);
+ return false;
+ }
}
+
return false;
}
@@ -59,3 +66,4 @@ function localizeHtmlPage() {
}
}
}
+