mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-14 23:47:04 +03:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e795c8fb1 | ||
|
|
c83eb589ea | ||
|
|
7cd6b324b9 | ||
|
|
5891fccacb | ||
|
|
59233f3307 | ||
|
|
796466a72a | ||
|
|
3f35642010 | ||
|
|
5bbfcf742d | ||
|
|
aaf79fda0d | ||
|
|
519a822751 | ||
|
|
fef31c399b | ||
|
|
da21081a12 | ||
|
|
2d12f957bc | ||
|
|
c1efe02614 |
@@ -14,6 +14,7 @@
|
|||||||
<a href="https://sponsor.ajay.app/stats">Stats</a>
|
<a href="https://sponsor.ajay.app/stats">Stats</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
[](https://addons.mozilla.org/addon/sponsorblock/?src=external-github) [](https://chrome.google.com/webstore/detail/mnjggcdmjocbbbhaepdhchncahnbgone)
|
||||||
|
|
||||||
SponsorBlock is an extension that will skip over sponsored segments of YouTube videos. SponsorBlock is a crowdsourced browser extension that lets anyone submit the start and end times of sponsored segments of YouTube videos. Once one person submits this information, everyone else with this extension will skip right over the sponsored segment.
|
SponsorBlock is an extension that will skip over sponsored segments of YouTube videos. SponsorBlock is a crowdsourced browser extension that lets anyone submit the start and end times of sponsored segments of YouTube videos. Once one person submits this information, everyone else with this extension will skip right over the sponsored segment.
|
||||||
|
|
||||||
|
|||||||
@@ -135,5 +135,17 @@
|
|||||||
},
|
},
|
||||||
"submitCheck": {
|
"submitCheck": {
|
||||||
"message": "Are you sure you want to submit this?"
|
"message": "Are you sure you want to submit this?"
|
||||||
|
},
|
||||||
|
"longDescription": {
|
||||||
|
"message": "SponsorBlock is an extension that will skip over sponsored segments of YouTube videos. SponsorBlock is a crowdsourced browser extension that let's anyone submit the start and end time's of sponsored segments of YouTube videos. Once one person submits this information, everyone else with this extension will skip right over the sponsored segment.",
|
||||||
|
"description": "Full description of the extension on the store pages."
|
||||||
|
},
|
||||||
|
"website": {
|
||||||
|
"message": "Website",
|
||||||
|
"description": "Used on Firefox Store Page"
|
||||||
|
},
|
||||||
|
"sourceCode": {
|
||||||
|
"message": "Source Code",
|
||||||
|
"description": "Used on Firefox Store Page"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
24
content.js
24
content.js
@@ -238,8 +238,10 @@ function videoIDChange(id) {
|
|||||||
//setup the preview bar
|
//setup the preview bar
|
||||||
if (previewBar == null) {
|
if (previewBar == null) {
|
||||||
//create it
|
//create it
|
||||||
let progressBar = document.getElementsByClassName("ytp-progress-bar-container")[0] || document.getElementsByClassName("no-model cue-range-markers")[0];
|
wait(getControls).then(result => {
|
||||||
previewBar = new PreviewBar(progressBar);
|
let progressBar = document.getElementsByClassName("ytp-progress-bar-container")[0] || document.getElementsByClassName("no-model cue-range-markers")[0];
|
||||||
|
previewBar = new PreviewBar(progressBar);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//warn them if they had unsubmitted times
|
//warn them if they had unsubmitted times
|
||||||
@@ -271,7 +273,7 @@ function videoIDChange(id) {
|
|||||||
sponsorsLookup(id);
|
sponsorsLookup(id);
|
||||||
|
|
||||||
//make sure everything is properly added
|
//make sure everything is properly added
|
||||||
updateVisibilityOfPlayerControlsButton(true);
|
updateVisibilityOfPlayerControlsButton();
|
||||||
|
|
||||||
//reset sponsor times submitting
|
//reset sponsor times submitting
|
||||||
sponsorTimesSubmitting = [];
|
sponsorTimesSubmitting = [];
|
||||||
@@ -412,7 +414,7 @@ function updatePreviewBar() {
|
|||||||
types.push("previewSponsor");
|
types.push("previewSponsor");
|
||||||
}
|
}
|
||||||
|
|
||||||
previewBar.set(allSponsorTimes, types, v.duration);
|
wait(() => previewBar !== null).then((result) => previewBar.set(allSponsorTimes, types, v.duration));
|
||||||
|
|
||||||
//update last video id
|
//update last video id
|
||||||
lastPreviewBarUpdate = sponsorVideoID;
|
lastPreviewBarUpdate = sponsorVideoID;
|
||||||
@@ -666,12 +668,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 +697,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() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "__MSG_fullName__",
|
"name": "__MSG_fullName__",
|
||||||
"short_name": "__MSG_Name__",
|
"short_name": "__MSG_Name__",
|
||||||
"version": "1.1.5",
|
"version": "1.1.7",
|
||||||
"default_locale": "en",
|
"default_locale": "en",
|
||||||
"description": "__MSG_Description__",
|
"description": "__MSG_Description__",
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
|
|||||||
55
utils.js
55
utils.js
@@ -1,41 +1,48 @@
|
|||||||
// 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;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user