mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-06 11:37:02 +03:00
Merge branch 'experimental' into patch-24
This commit is contained in:
@@ -7,29 +7,29 @@ chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
|
|||||||
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
||||||
switch(request.message) {
|
switch(request.message) {
|
||||||
case "submitTimes":
|
case "submitTimes":
|
||||||
submitTimes(request.videoID, callback);
|
submitTimes(request.videoID, callback);
|
||||||
|
|
||||||
//this allows the callback to be called later by the submitTimes function
|
//this allows the callback to be called later by the submitTimes function
|
||||||
return true;
|
return true;
|
||||||
case "addSponsorTime":
|
case "addSponsorTime":
|
||||||
addSponsorTime(request.time, request.videoID, callback);
|
addSponsorTime(request.time, request.videoID, callback);
|
||||||
|
|
||||||
//this allows the callback to be called later
|
//this allows the callback to be called later
|
||||||
return true;
|
return true;
|
||||||
case "getSponsorTimes":
|
case "getSponsorTimes":
|
||||||
getSponsorTimes(request.videoID, function(sponsorTimes) {
|
getSponsorTimes(request.videoID, function(sponsorTimes) {
|
||||||
callback({
|
callback({
|
||||||
sponsorTimes: sponsorTimes
|
sponsorTimes: sponsorTimes
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
//this allows the callback to be called later
|
//this allows the callback to be called later
|
||||||
return true;
|
return true;
|
||||||
case "submitVote":
|
case "submitVote":
|
||||||
submitVote(request.type, request.UUID, callback);
|
submitVote(request.type, request.UUID, callback);
|
||||||
|
|
||||||
//this allows the callback to be called later
|
//this allows the callback to be called later
|
||||||
return true;
|
return true;
|
||||||
case "alertPrevious":
|
case "alertPrevious":
|
||||||
chrome.notifications.create("stillThere" + Math.random(), {
|
chrome.notifications.create("stillThere" + Math.random(), {
|
||||||
type: "basic",
|
type: "basic",
|
||||||
|
|||||||
18
content.js
18
content.js
@@ -666,12 +666,15 @@ function isSubmitButtonLoaded() {
|
|||||||
return document.getElementById("submitButton") !== null;
|
return document.getElementById("submitButton") !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
|
async function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
|
||||||
if(!sponsorVideoID) return false;
|
if(!sponsorVideoID) return false;
|
||||||
wait(isSubmitButtonLoaded).then(result => {
|
|
||||||
|
//make sure submit button is loaded
|
||||||
|
await wait(isSubmitButtonLoaded);
|
||||||
|
|
||||||
//if it isn't visible, there is no data
|
//if it isn't visible, there is no data
|
||||||
let shouldHide = (uploadButtonVisible && !hideDeleteButtonPlayerControls) ? "unset":"none"
|
let shouldHide = (uploadButtonVisible && !hideDeleteButtonPlayerControls) ? "unset" : "none"
|
||||||
document.getElementById("deleteButton").style.display = shouldHide;
|
document.getElementById("deleteButton").style.display = shouldHide;
|
||||||
|
|
||||||
if (showStartSponsor) {
|
if (showStartSponsor) {
|
||||||
showingStartSponsor = true;
|
showingStartSponsor = true;
|
||||||
@@ -692,7 +695,6 @@ function changeStartSponsorButton(showStartSponsor, uploadButtonVisible) {
|
|||||||
//disable submit button
|
//disable submit button
|
||||||
document.getElementById("submitButton").style.display = "none";
|
document.getElementById("submitButton").style.display = "none";
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleStartSponsorButton() {
|
function toggleStartSponsorButton() {
|
||||||
@@ -896,7 +898,7 @@ function submitSponsorTimes() {
|
|||||||
//called after all the checks have been made that it's okay to do so
|
//called after all the checks have been made that it's okay to do so
|
||||||
function sendSubmitMessage(){
|
function sendSubmitMessage(){
|
||||||
//add loading animation
|
//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";
|
document.getElementById("submitButton").style.animation = "rotate 1s 0s infinite";
|
||||||
|
|
||||||
let currentVideoID = sponsorVideoID;
|
let currentVideoID = sponsorVideoID;
|
||||||
@@ -931,7 +933,7 @@ function sendSubmitMessage(){
|
|||||||
} else {
|
} else {
|
||||||
//show that the upload failed
|
//show that the upload failed
|
||||||
document.getElementById("submitButton").style.animation = "unset";
|
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)) {
|
if([400,429,409,502].includes(response.statusCode)) {
|
||||||
alert(chrome.i18n.getMessage(response.statusCode));
|
alert(chrome.i18n.getMessage(response.statusCode));
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "__MSG_fullName__",
|
"name": "__MSG_fullName__",
|
||||||
"short_name": "__MSG_Name__",
|
"short_name": "__MSG_Name__",
|
||||||
"version": "1.1.4",
|
"version": "1.1.6",
|
||||||
"default_locale": "en",
|
"default_locale": "en",
|
||||||
"description": "__MSG_Description__",
|
"description": "__MSG_Description__",
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
|
|||||||
54
utils.js
54
utils.js
@@ -1,42 +1,49 @@
|
|||||||
// Function that can be used to wait for a condition before returning
|
// Function that can be used to wait for a condition before returning
|
||||||
async function wait(condition, timeout = 5000, check = 100) {
|
async function wait(condition, timeout = 5000, check = 100) {
|
||||||
return await new Promise((resolve, reject) => {
|
return await new Promise((resolve, reject) => {
|
||||||
setTimeout(() => {reject("TIMEOUT")}, timeout);
|
setTimeout(() => reject("TIMEOUT"), timeout);
|
||||||
const interval = setInterval(() => {
|
|
||||||
let result = condition();
|
let intervalCheck = () => {
|
||||||
if (result !== false) {
|
let result = condition();
|
||||||
resolve(result);
|
if (result !== false) {
|
||||||
clearInterval(interval);
|
resolve(result);
|
||||||
};
|
clearInterval(interval);
|
||||||
}, check);
|
};
|
||||||
});
|
};
|
||||||
|
|
||||||
|
let interval = setInterval(intervalCheck, check);
|
||||||
|
|
||||||
|
//run the check once first, this speeds it up a lot
|
||||||
|
intervalCheck();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getYouTubeVideoID(url) {
|
function getYouTubeVideoID(url) {
|
||||||
//Attempt to parse url
|
//Attempt to parse url
|
||||||
let urlObject = null;
|
let urlObject = null;
|
||||||
try {
|
try {
|
||||||
urlObject = new URL(url);
|
urlObject = new URL(url);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("[SB] Unable to parse URL: " + url);
|
console.error("[SB] Unable to parse URL: " + url);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if valid hostname
|
//Check if valid hostname
|
||||||
if(!["www.youtube.com","www.youtube-nocookie.com"].includes(urlObject.host)) return false;
|
if(!["www.youtube.com","www.youtube-nocookie.com"].includes(urlObject.host)) return false;
|
||||||
|
|
||||||
//Get ID from searchParam
|
//Get ID from searchParam
|
||||||
if ((urlObject.pathname == "/watch" || urlObject.pathname == "/watch/") && urlObject.searchParams.has("v")) {
|
if ((urlObject.pathname == "/watch" || urlObject.pathname == "/watch/") && urlObject.searchParams.has("v")) {
|
||||||
id = urlObject.searchParams.get("v");
|
id = urlObject.searchParams.get("v");
|
||||||
return id.length == 11 ? id : false;
|
return id.length == 11 ? id : false;
|
||||||
} else if (urlObject.pathname.startsWith("/embed/")) {
|
} else if (urlObject.pathname.startsWith("/embed/")) {
|
||||||
try {
|
try {
|
||||||
return urlObject.pathname.substr(7, 11);
|
return urlObject.pathname.substr(7, 11);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("[SB] Video ID not valid for " + url);
|
console.error("[SB] Video ID not valid for " + url);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,3 +66,4 @@ function localizeHtmlPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user