mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-15 16:07:06 +03:00
Updated it to use my database
This commit is contained in:
@@ -1,12 +1,15 @@
|
|||||||
if(id = youtube_parser(document.URL)){ // Direct Links
|
if(id = getYouTubeVideoID(document.URL)){ // Direct Links
|
||||||
SponsorsLookup(id);
|
sponsorsLookup(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//was sponsor data found when doing SponsorsLookup
|
||||||
|
var sponsorDataFound = false;
|
||||||
|
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener( // Detect URL Changes
|
chrome.runtime.onMessage.addListener( // Detect URL Changes
|
||||||
function(request, sender, sendResponse) {
|
function(request, sender, sendResponse) {
|
||||||
if (request.message === 'ytvideoid') { // Message from background script
|
if (request.message === 'ytvideoid') { // Message from background script
|
||||||
SponsorsLookup(request.id);
|
sponsorsLookup(request.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
//messages from popup script
|
//messages from popup script
|
||||||
@@ -16,35 +19,42 @@ chrome.runtime.onMessage.addListener( // Detect URL Changes
|
|||||||
|
|
||||||
if (request.message === 'infoFound') {
|
if (request.message === 'infoFound') {
|
||||||
sendResponse({
|
sendResponse({
|
||||||
found: true
|
found: sponsorDataFound
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function SponsorsLookup(id) {
|
function sponsorsLookup(id) {
|
||||||
v = document.querySelector('video') // Youtube video player
|
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); // Dataset lookup
|
|
||||||
|
//check database for sponsor times
|
||||||
|
xmlhttp.open('GET', 'http://localhost/api/getVideoSponsorTimes?videoID=' + id, true);
|
||||||
|
|
||||||
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);
|
sponsorDataFound = true;
|
||||||
v.ontimeupdate = function () { // If exists add event to run on the videos "ontimeupdate"
|
|
||||||
SponsorCheck(Sponsors);
|
sponsors = JSON.parse(xmlhttp.responseText);
|
||||||
|
|
||||||
|
// If the sponsor data exists, add the event to run on the videos "ontimeupdate"
|
||||||
|
v.ontimeupdate = function () {
|
||||||
|
sponsorCheck(sponsors);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
xmlhttp.send(null);
|
xmlhttp.send(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
function SponsorCheck(Sponsors) { // Video skipping
|
function sponsorCheck(sponsors) { // Video skipping
|
||||||
Sponsors.forEach(function (el, index) { // Foreach Sponsor in video
|
sponsors.forEach(function (el, index) { // Foreach Sponsor in video
|
||||||
if ((Math.floor(v.currentTime)) == el[0]) { // Check time has sponsor
|
if ((Math.floor(v.currentTime)) == el[0]) { // Check time has sponsor
|
||||||
v.currentTime = el[1]; // Set new time
|
v.currentTime = el[1]; // Set new time
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function youtube_parser(url) { // Returns with video id else returns false
|
function getYouTubeVideoID(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;
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
"https://*.youtube.com/*"
|
"https://*.youtube.com/*"
|
||||||
],
|
],
|
||||||
"js": [
|
"js": [
|
||||||
"contentScript.js"
|
"content.js"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user