aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOfficial Noob <[email protected]>2019-01-18 19:59:34 +0000
committerGitHub <[email protected]>2019-01-18 19:59:34 +0000
commit4bf3cac622208dccf8f01b793290ee55accbbc65 (patch)
tree0740e5652e30b19f0fe6201b8e53307b966e584e
parente4884b3dae257d6564c22047ecbab11f10c47dbb (diff)
downloadSponsorBlock-4bf3cac622208dccf8f01b793290ee55accbbc65.tar.gz
SponsorBlock-4bf3cac622208dccf8f01b793290ee55accbbc65.zip
Comments
-rw-r--r--ContentScript.js18
1 files changed, 9 insertions, 9 deletions
diff --git a/ContentScript.js b/ContentScript.js
index 7ef58317..1ddcde8f 100644
--- a/ContentScript.js
+++ b/ContentScript.js
@@ -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) {
- if (request.message === 'ytvideoid') {
+ if (request.message === 'ytvideoid') { // Message for background script
SponsorsLookup(request.id);
}
});
function SponsorsLookup(id) {
- v = document.querySelector('video')
+ v = document.querySelector('video') // Youtube video player
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 () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
Sponsors = JSON.parse(xmlhttp.responseText);
- v.ontimeupdate = function () {
+ v.ontimeupdate = function () { // If exists add event to run on the videos "ontimeupdate"
SponsorCheck(Sponsors);
};
}
@@ -26,14 +26,14 @@ function SponsorsLookup(id) {
}
function SponsorCheck(Sponsors) { // Video skipping
- Sponsors.forEach(function (el, index) {
- if ((Math.floor(v.currentTime)) == el[0]) {
- v.currentTime = el[1];
+ Sponsors.forEach(function (el, index) { // Foreach Sponsor in video
+ if ((Math.floor(v.currentTime)) == el[0]) { // Check time has sponsor
+ 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 match = url.match(regExp);
return (match && match[7].length == 11) ? match[7] : false;