mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 21:47:06 +03:00
Comments
This commit is contained in:
@@ -3,21 +3,21 @@ if(id = youtube_parser(document.URL)){ // Direct Links
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener( // URL Changes
|
chrome.runtime.onMessage.addListener( // Detect URL Changes
|
||||||
function(request, sender, sendResponse) {
|
function(request, sender, sendResponse) {
|
||||||
if (request.message === 'ytvideoid') {
|
if (request.message === 'ytvideoid') { // Message for background script
|
||||||
SponsorsLookup(request.id);
|
SponsorsLookup(request.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function SponsorsLookup(id) {
|
function SponsorsLookup(id) {
|
||||||
v = document.querySelector('video')
|
v = document.querySelector('video') // Youtube video player
|
||||||
var xmlhttp = new XMLHttpRequest();
|
var xmlhttp = new XMLHttpRequest();
|
||||||
xmlhttp.open('GET', 'https://officialnoob.github.io/YTSponsorSkip-Dataset/' + id, true);
|
xmlhttp.open('GET', 'https://officialnoob.github.io/YTSponsorSkip-Dataset/' + id, true); // Dataset lookup
|
||||||
xmlhttp.onreadystatechange = function () {
|
xmlhttp.onreadystatechange = function () {
|
||||||
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||||
Sponsors = JSON.parse(xmlhttp.responseText);
|
Sponsors = JSON.parse(xmlhttp.responseText);
|
||||||
v.ontimeupdate = function () {
|
v.ontimeupdate = function () { // If exists add event to run on the videos "ontimeupdate"
|
||||||
SponsorCheck(Sponsors);
|
SponsorCheck(Sponsors);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -26,14 +26,14 @@ function SponsorsLookup(id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function SponsorCheck(Sponsors) { // Video skipping
|
function SponsorCheck(Sponsors) { // Video skipping
|
||||||
Sponsors.forEach(function (el, index) {
|
Sponsors.forEach(function (el, index) { // Foreach Sponsor in video
|
||||||
if ((Math.floor(v.currentTime)) == el[0]) {
|
if ((Math.floor(v.currentTime)) == el[0]) { // Check time has sponsor
|
||||||
v.currentTime = el[1];
|
v.currentTime = el[1]; // Set new time
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function youtube_parser(url) {
|
function youtube_parser(url) { // Returns with video id else returns false
|
||||||
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
|
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
|
||||||
var match = url.match(regExp);
|
var match = url.match(regExp);
|
||||||
return (match && match[7].length == 11) ? match[7] : false;
|
return (match && match[7].length == 11) ? match[7] : false;
|
||||||
|
|||||||
Reference in New Issue
Block a user