mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-14 23:47:04 +03:00
Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
455189d916 | ||
|
|
1c05de3098 | ||
|
|
577baa508b | ||
|
|
aebb4313bc | ||
|
|
d42377a5cd | ||
|
|
699ca91a94 | ||
|
|
30c12e3983 | ||
|
|
15d6a48359 | ||
|
|
b700d4eec0 | ||
|
|
5be8ecb32b | ||
|
|
ccafbf663c | ||
|
|
3f7e9e22ec | ||
|
|
e5d9c75392 | ||
|
|
b34b3f5651 | ||
|
|
7c787b77e8 | ||
|
|
0c669d6b83 | ||
|
|
df1bc9d7a6 | ||
|
|
7e2925a1e3 | ||
|
|
b964d93ea9 | ||
|
|
baba619fe7 | ||
|
|
dce036b0e6 | ||
|
|
c6c8d7de49 | ||
|
|
02e11503cb | ||
|
|
2b5402fa57 | ||
|
|
7ad5e426fb | ||
|
|
9a32710ef8 | ||
|
|
d25792f39a | ||
|
|
5ee279dec7 | ||
|
|
e6fa832cb8 | ||
|
|
64befaebfc | ||
|
|
5425c54fca | ||
|
|
aae0998426 | ||
|
|
f6c9e8e235 | ||
|
|
18909ffef6 | ||
|
|
3a037818a8 |
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
# SponsorBlock
|
# SponsorBlock
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
# Available for Chrome and Firefox
|
# Available for Chrome and Firefox
|
||||||
|
|
||||||
@@ -23,11 +23,11 @@ Hopefully this project can be combined with projects like [this](https://github.
|
|||||||
|
|
||||||
# API
|
# API
|
||||||
|
|
||||||
You can read the API docs [here](https://github.com/ajayyy/SponsorBlockServer#api-docs)
|
You can read the API docs [here](https://github.com/ajayyy/SponsorBlockServer#api-docs).
|
||||||
|
|
||||||
# Previous extension
|
# Previous extension
|
||||||
|
|
||||||
This project is partially based off of [this experimental extension](https://github.com/OfficialNoob/YTSponsorSkip). That extension has the basic video skipping functionality.
|
This project is partially based off of [this experimental extension](https://github.com/OfficialNoob/YTSponsorSkip), which has the basic video skipping functionality.
|
||||||
|
|
||||||
# Build Yourself
|
# Build Yourself
|
||||||
|
|
||||||
@@ -39,4 +39,4 @@ The awesome [Invidious API](https://github.com/omarroth/invidious/wiki/API) is u
|
|||||||
|
|
||||||
Some icons made by <a href="https://www.flaticon.com/authors/gregor-cresnar" title="Gregor Cresnar">Gregor Cresnar</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a> and are licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a>
|
Some icons made by <a href="https://www.flaticon.com/authors/gregor-cresnar" title="Gregor Cresnar">Gregor Cresnar</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a> and are licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a>
|
||||||
|
|
||||||
Some icons made by <a href="https://www.flaticon.com/authors/freepik" title="Freepik">Freepik</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a> is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a>
|
Some icons made by <a href="https://www.flaticon.com/authors/freepik" title="Freepik">Freepik</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a> are licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a>
|
||||||
|
|||||||
149
background.js
149
background.js
@@ -1,11 +1,3 @@
|
|||||||
var previousVideoID = null
|
|
||||||
|
|
||||||
//the id of this user, randomly generated once per install
|
|
||||||
var userID = null;
|
|
||||||
|
|
||||||
//the last video id loaded, to make sure it is a video id change
|
|
||||||
var sponsorVideoID = null;
|
|
||||||
|
|
||||||
//when a new tab is highlighted
|
//when a new tab is highlighted
|
||||||
chrome.tabs.onActivated.addListener(
|
chrome.tabs.onActivated.addListener(
|
||||||
function(activeInfo) {
|
function(activeInfo) {
|
||||||
@@ -62,14 +54,38 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
|||||||
|
|
||||||
//add help page on install
|
//add help page on install
|
||||||
chrome.runtime.onInstalled.addListener(function (object) {
|
chrome.runtime.onInstalled.addListener(function (object) {
|
||||||
chrome.storage.sync.get(["shownInstallPage"], function(result) {
|
// TODO (shownInstallPage): remove shownInstallPage logic after sufficient amount of time,
|
||||||
let shownInstallPage = result.shownInstallPage;
|
// so that people have time to upgrade and move to shownInstallPage-free code.
|
||||||
if (shownInstallPage == undefined || !shownInstallPage) {
|
chrome.storage.sync.get(["userID", "shownInstallPage"], function(result) {
|
||||||
//open up the install page
|
const userID = result.userID;
|
||||||
chrome.tabs.create({url: chrome.extension.getURL("/help/index.html")});
|
// TODO (shownInstallPage): delete row below
|
||||||
|
const shownInstallPage = result.shownInstallPage;
|
||||||
|
|
||||||
//save that this happened
|
// If there is no userID, then it is the first install.
|
||||||
chrome.storage.sync.set({shownInstallPage: true});
|
if (!userID){
|
||||||
|
// Show install page, if there is no user id
|
||||||
|
// and there is no shownInstallPage.
|
||||||
|
// TODO (shownInstallPage): remove this if statement, but leave contents
|
||||||
|
if (!shownInstallPage){
|
||||||
|
//open up the install page
|
||||||
|
chrome.tabs.create({url: chrome.extension.getURL("/help/index.html")});
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO (shownInstallPage): delete if statement and contents
|
||||||
|
// If shownInstallPage is set, remove it.
|
||||||
|
if (!!shownInstallPage){
|
||||||
|
chrome.storage.sync.remove("shownInstallPage");
|
||||||
|
}
|
||||||
|
|
||||||
|
//generate a userID
|
||||||
|
const newUserID = generateUUID();
|
||||||
|
//save this UUID
|
||||||
|
chrome.storage.sync.set({
|
||||||
|
"userID": newUserID,
|
||||||
|
//the last video id loaded, to make sure it is a video id change
|
||||||
|
"sponsorVideoID": null,
|
||||||
|
"previousVideoID": null
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -109,9 +125,11 @@ function addSponsorTime(time, videoID, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function submitVote(type, UUID, callback) {
|
function submitVote(type, UUID, callback) {
|
||||||
getUserID(function(userID) {
|
chrome.storage.sync.get(["userID"], function(result) {
|
||||||
|
let userID = result.userID;
|
||||||
|
|
||||||
//publish this vote
|
//publish this vote
|
||||||
sendRequestToServer('GET', "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + "&type=" + type, function(xmlhttp, error) {
|
sendRequestToServer("GET", "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + "&type=" + type, function(xmlhttp, error) {
|
||||||
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||||
callback({
|
callback({
|
||||||
successType: 1
|
successType: 1
|
||||||
@@ -138,14 +156,14 @@ function submitTimes(videoID, callback) {
|
|||||||
let sponsorTimeKey = 'sponsorTimes' + videoID;
|
let sponsorTimeKey = 'sponsorTimes' + videoID;
|
||||||
chrome.storage.sync.get([sponsorTimeKey], function(result) {
|
chrome.storage.sync.get([sponsorTimeKey], function(result) {
|
||||||
let sponsorTimes = result[sponsorTimeKey];
|
let sponsorTimes = result[sponsorTimeKey];
|
||||||
|
let userID = result.userID;
|
||||||
|
|
||||||
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
||||||
//submit these times
|
//submit these times
|
||||||
for (let i = 0; i < sponsorTimes.length; i++) {
|
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||||
getUserID(function(userIDStorage) {
|
|
||||||
//submit the sponsorTime
|
//submit the sponsorTime
|
||||||
sendRequestToServer('GET', "/api/postVideoSponsorTimes?videoID=" + videoID + "&startTime=" + sponsorTimes[i][0] + "&endTime=" + sponsorTimes[i][1]
|
sendRequestToServer("GET", "/api/postVideoSponsorTimes?videoID=" + videoID + "&startTime=" + sponsorTimes[i][0] + "&endTime=" + sponsorTimes[i][1]
|
||||||
+ "&userID=" + userIDStorage, function(xmlhttp, error) {
|
+ "&userID=" + userID, function(xmlhttp, error) {
|
||||||
if (xmlhttp.readyState == 4 && !error) {
|
if (xmlhttp.readyState == 4 && !error) {
|
||||||
callback({
|
callback({
|
||||||
statusCode: xmlhttp.status
|
statusCode: xmlhttp.status
|
||||||
@@ -169,7 +187,6 @@ function submitTimes(videoID, callback) {
|
|||||||
statusCode: -1
|
statusCode: -1
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,63 +200,45 @@ function videoIDChange(currentVideoID, tabId) {
|
|||||||
id: currentVideoID
|
id: currentVideoID
|
||||||
});
|
});
|
||||||
|
|
||||||
//not a url change
|
chrome.storage.sync.get(["sponsorVideoID", "previousVideoID"], function(result) {
|
||||||
if (sponsorVideoID == currentVideoID){
|
const sponsorVideoID = result.sponsorVideoID;
|
||||||
return;
|
const previousVideoID = result.previousVideoID;
|
||||||
}
|
|
||||||
sponsorVideoID = currentVideoID;
|
|
||||||
|
|
||||||
//warn them if they had unsubmitted times
|
//not a url change
|
||||||
if (previousVideoID != null) {
|
if (sponsorVideoID == currentVideoID){
|
||||||
//get the sponsor times from storage
|
return;
|
||||||
let sponsorTimeKey = 'sponsorTimes' + previousVideoID;
|
}
|
||||||
chrome.storage.sync.get([sponsorTimeKey], function(result) {
|
|
||||||
let sponsorTimes = result[sponsorTimeKey];
|
|
||||||
|
|
||||||
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
chrome.storage.sync.set({
|
||||||
//warn them that they have unsubmitted sponsor times
|
"sponsorVideoID": currentVideoID
|
||||||
chrome.notifications.create("stillThere" + Math.random(), {
|
|
||||||
type: "basic",
|
|
||||||
title: "Do you want to submit the sponsor times for watch?v=" + previousVideoID + "?",
|
|
||||||
message: "You seem to have left some sponsor times unsubmitted. Go back to that page to submit them (they are not deleted).",
|
|
||||||
iconUrl: "./icons/LogoSponsorBlocker256px.png"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//set the previous video id to the currentID
|
|
||||||
previousVideoID = currentVideoID;
|
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
previousVideoID = currentVideoID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getUserID(callback) {
|
//warn them if they had unsubmitted times
|
||||||
if (userID != null) {
|
if (previousVideoID != null) {
|
||||||
callback(userID);
|
//get the sponsor times from storage
|
||||||
return;
|
let sponsorTimeKey = 'sponsorTimes' + previousVideoID;
|
||||||
}
|
chrome.storage.sync.get([sponsorTimeKey], function(result) {
|
||||||
|
let sponsorTimes = result[sponsorTimeKey];
|
||||||
|
|
||||||
//if it is not cached yet, grab it from storage
|
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
||||||
chrome.storage.sync.get(["userID"], function(result) {
|
//warn them that they have unsubmitted sponsor times
|
||||||
let userIDStorage = result.userID;
|
chrome.notifications.create("stillThere" + Math.random(), {
|
||||||
if (userIDStorage != undefined) {
|
type: "basic",
|
||||||
userID = userIDStorage;
|
title: "Do you want to submit the sponsor times for watch?v=" + previousVideoID + "?",
|
||||||
callback(userID);
|
message: "You seem to have left some sponsor times unsubmitted. Go back to that page to submit them (they are not deleted).",
|
||||||
|
iconUrl: "./icons/LogoSponsorBlocker256px.png"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//set the previous video id to the currentID
|
||||||
|
chrome.storage.sync.set({
|
||||||
|
"previousVideoID": currentVideoID
|
||||||
|
});
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
//double check if a UUID hasn't been created since this was first called
|
chrome.storage.sync.set({
|
||||||
if (userID != null) {
|
"previousVideoID": currentVideoID
|
||||||
callback(userID);
|
});
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//generate a userID
|
|
||||||
userID = generateUUID();
|
|
||||||
|
|
||||||
//save this UUID
|
|
||||||
chrome.storage.sync.set({"userID": userID});
|
|
||||||
|
|
||||||
callback(userID);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -263,11 +262,5 @@ function sendRequestToServer(type, address, callback) {
|
|||||||
xmlhttp.send();
|
xmlhttp.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getYouTubeVideoID(url) { // Return video id or false
|
|
||||||
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
|
|
||||||
var match = url.match(regExp);
|
|
||||||
return (match && match[7].length == 11) ? match[7] : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//uuid generator function from https://gist.github.com/jed/982883
|
//uuid generator function from https://gist.github.com/jed/982883
|
||||||
function generateUUID(a){return a?(a^Math.random()*16>>a/4).toString(16):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,generateUUID)}
|
function generateUUID(a){return a?(a^Math.random()*16>>a/4).toString(16):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,generateUUID)}
|
||||||
31
content.js
31
content.js
@@ -10,10 +10,6 @@ var sponsorVideoID = null;
|
|||||||
//the time this video is starting at when first played, if not zero
|
//the time this video is starting at when first played, if not zero
|
||||||
var youtubeVideoStartTime = null;
|
var youtubeVideoStartTime = null;
|
||||||
|
|
||||||
if(id = getYouTubeVideoID(document.URL)){ // Direct Links
|
|
||||||
videoIDChange(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
//the video
|
//the video
|
||||||
var v;
|
var v;
|
||||||
|
|
||||||
@@ -23,6 +19,10 @@ var channelURL;
|
|||||||
//is this channel whitelised from getting sponsors skipped
|
//is this channel whitelised from getting sponsors skipped
|
||||||
var channelWhitelisted = false;
|
var channelWhitelisted = false;
|
||||||
|
|
||||||
|
if(id = getYouTubeVideoID(document.URL)){ // Direct Links
|
||||||
|
videoIDChange(id);
|
||||||
|
}
|
||||||
|
|
||||||
//the last time looked at (used to see if this time is in the interval)
|
//the last time looked at (used to see if this time is in the interval)
|
||||||
var lastTime = -1;
|
var lastTime = -1;
|
||||||
|
|
||||||
@@ -1143,26 +1143,3 @@ function sendRequestToCustomServer(type, fullAddress, callback) {
|
|||||||
//submit this request
|
//submit this request
|
||||||
xmlhttp.send();
|
xmlhttp.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getYouTubeVideoID(url) { // Returns with video id else returns false
|
|
||||||
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
|
|
||||||
var match = url.match(regExp);
|
|
||||||
var id = new URL(url).searchParams.get("v");
|
|
||||||
if (url.includes("/embed/")) {
|
|
||||||
//it is an embed, don't search for v
|
|
||||||
id = match[7];
|
|
||||||
}
|
|
||||||
|
|
||||||
return (match && match[7].length == 11) ? id : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//returns the start time of the video if there was one specified (ex. ?t=5s)
|
|
||||||
function getYouTubeVideoStartTime(url) {
|
|
||||||
let searchParams = new URL(url).searchParams;
|
|
||||||
var startTime = searchParams.get("t");
|
|
||||||
if (startTime == null) {
|
|
||||||
startTime = searchParams.get("time_continue");
|
|
||||||
}
|
|
||||||
|
|
||||||
return startTime;
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "SponsorBlock for YouTube - Skip Sponsorships",
|
"name": "SponsorBlock for YouTube - Skip Sponsorships",
|
||||||
"short_name": "SponsorBlock",
|
"short_name": "SponsorBlock",
|
||||||
"version": "1.0.29",
|
"version": "1.0.30",
|
||||||
"description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
|
"description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
"all_frames": true,
|
"all_frames": true,
|
||||||
"js": [
|
"js": [
|
||||||
"config.js",
|
"config.js",
|
||||||
|
"utils.js",
|
||||||
"content.js",
|
"content.js",
|
||||||
"popup.js"
|
"popup.js"
|
||||||
],
|
],
|
||||||
@@ -32,9 +33,7 @@
|
|||||||
"icons/downvote.png",
|
"icons/downvote.png",
|
||||||
"icons/PlayerInfoIconSponsorBlocker256px.png",
|
"icons/PlayerInfoIconSponsorBlocker256px.png",
|
||||||
"icons/PlayerDeleteIconSponsorBlocker256px.png",
|
"icons/PlayerDeleteIconSponsorBlocker256px.png",
|
||||||
"popup.html",
|
"popup.html"
|
||||||
"help/index.html",
|
|
||||||
"help/style.css"
|
|
||||||
],
|
],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"tabs",
|
"tabs",
|
||||||
@@ -48,9 +47,11 @@
|
|||||||
},
|
},
|
||||||
"background": {
|
"background": {
|
||||||
"scripts":[
|
"scripts":[
|
||||||
|
"utils.js",
|
||||||
"config.js",
|
"config.js",
|
||||||
"background.js"
|
"background.js"
|
||||||
]
|
],
|
||||||
|
"persistent": false
|
||||||
},
|
},
|
||||||
"icons": {
|
"icons": {
|
||||||
"16": "icons/IconSponsorBlocker16px.png",
|
"16": "icons/IconSponsorBlocker16px.png",
|
||||||
|
|||||||
@@ -193,5 +193,6 @@
|
|||||||
|
|
||||||
<!-- Scripts that need to load after the html -->
|
<!-- Scripts that need to load after the html -->
|
||||||
<script src="config.js"></script>
|
<script src="config.js"></script>
|
||||||
|
<script src="utils.js"></script>
|
||||||
<script src="popup.js"></script>
|
<script src="popup.js"></script>
|
||||||
</html>
|
</html>
|
||||||
47
popup.js
47
popup.js
@@ -123,26 +123,6 @@ function runThePopup() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//see if whitelist button should be swapped
|
|
||||||
chrome.tabs.query({
|
|
||||||
active: true,
|
|
||||||
currentWindow: true
|
|
||||||
}, tabs => {
|
|
||||||
chrome.tabs.sendMessage(
|
|
||||||
tabs[0].id,
|
|
||||||
{message: 'isChannelWhitelisted'},
|
|
||||||
function(response) {
|
|
||||||
if (response.value) {
|
|
||||||
SB.whitelistChannel.style.display = "none";
|
|
||||||
SB.unwhitelistChannel.style.display = "unset";
|
|
||||||
|
|
||||||
SB.downloadedSponsorMessageTimes.innerText = "Channel Whitelisted!";
|
|
||||||
SB.downloadedSponsorMessageTimes.style.fontWeight = "bold";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
//if the don't show notice again letiable is true, an option to
|
//if the don't show notice again letiable is true, an option to
|
||||||
// disable should be available
|
// disable should be available
|
||||||
chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) {
|
chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) {
|
||||||
@@ -292,6 +272,26 @@ function runThePopup() {
|
|||||||
SB.videoFound.innerHTML = "No sponsors found"
|
SB.videoFound.innerHTML = "No sponsors found"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//see if whitelist button should be swapped
|
||||||
|
chrome.tabs.query({
|
||||||
|
active: true,
|
||||||
|
currentWindow: true
|
||||||
|
}, tabs => {
|
||||||
|
chrome.tabs.sendMessage(
|
||||||
|
tabs[0].id,
|
||||||
|
{message: 'isChannelWhitelisted'},
|
||||||
|
function(response) {
|
||||||
|
if (response.value) {
|
||||||
|
SB.whitelistChannel.style.display = "none";
|
||||||
|
SB.unwhitelistChannel.style.display = "unset";
|
||||||
|
|
||||||
|
SB.downloadedSponsorMessageTimes.innerText = "Channel Whitelisted!";
|
||||||
|
SB.downloadedSponsorMessageTimes.style.fontWeight = "bold";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setVideoID(request) {
|
function setVideoID(request) {
|
||||||
@@ -1127,13 +1127,6 @@ function runThePopup() {
|
|||||||
xmlhttp.send();
|
xmlhttp.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getYouTubeVideoID(url) { // Returns with video id else returns false
|
|
||||||
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
|
|
||||||
var match = url.match(regExp);
|
|
||||||
var id = new URL(url).searchParams.get("v");
|
|
||||||
return (match && match[7].length == 11) ? id : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//end of function
|
//end of function
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
37
utils.js
Normal file
37
utils.js
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
function getYouTubeVideoID(url) {
|
||||||
|
//Attempt to parse url
|
||||||
|
let urlObject = null;
|
||||||
|
try {
|
||||||
|
urlObject = new URL(url);
|
||||||
|
} catch (e) {
|
||||||
|
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;
|
||||||
|
} 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//returns the start time of the video if there was one specified (ex. ?t=5s)
|
||||||
|
function getYouTubeVideoStartTime(url) {
|
||||||
|
let searchParams = new URL(url).searchParams;
|
||||||
|
let startTime = searchParams.get("t");
|
||||||
|
if (startTime == null) {
|
||||||
|
startTime = searchParams.get("time_continue");
|
||||||
|
}
|
||||||
|
|
||||||
|
return startTime;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user