Merge pull request #39 from ajayyy/experimental

Fixed an issue on Firefox where the old video's sponsors would sometimes play on the next video
This commit is contained in:
Ajay Ramachandran
2019-07-28 17:56:50 -04:00
committed by GitHub
3 changed files with 22 additions and 13 deletions

View File

@@ -1,13 +1,15 @@
if(id = getYouTubeVideoID(document.URL)){ // Direct Links
videoIDChange(id);
}
//was sponsor data found when doing SponsorsLookup //was sponsor data found when doing SponsorsLookup
var sponsorDataFound = false; var sponsorDataFound = false;
//the actual sponsorTimes if loaded and UUIDs associated with them //the actual sponsorTimes if loaded and UUIDs associated with them
var sponsorTimes = undefined; var sponsorTimes = null;
var UUIDs = undefined; var UUIDs = null;
//what video id are these sponsors for
var sponsorVideoID = null;
if(id = getYouTubeVideoID(document.URL)){ // Direct Links
videoIDChange(id);
}
//the video //the video
var v; var v;
@@ -53,6 +55,7 @@ chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) {
chrome.runtime.onMessage.addListener( // Detect URL Changes chrome.runtime.onMessage.addListener( // Detect URL Changes
function(request, sender, sendResponse) { function(request, sender, sendResponse) {
console.log(request.message)
//message from background script //message from background script
if (request.message == "ytvideoid") { if (request.message == "ytvideoid") {
videoIDChange(request.id); videoIDChange(request.id);
@@ -117,13 +120,19 @@ document.onkeydown = function(e){
} }
function videoIDChange(id) { function videoIDChange(id) {
//not a url change
if (sponsorVideoID == id){
return;
}
//reset last sponsor times //reset last sponsor times
lastTime = -1; lastTime = -1;
lastUnixTimeSkipped = -1; lastUnixTimeSkipped = -1;
//reset sponsor times //reset sponsor times
sponsorTimes = undefined; sponsorTimes = null;
UUIDs = undefined; UUIDs = null;
sponsorVideoID = id;
//reset sponsor data found check //reset sponsor data found check
sponsorDataFound = false; sponsorDataFound = false;
@@ -136,9 +145,9 @@ function videoIDChange(id) {
}, function(response) { }, function(response) {
if (response != undefined) { if (response != undefined) {
let sponsorTimes = response.sponsorTimes; let sponsorTimes = response.sponsorTimes;
if (sponsorTimes != undefined && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length >= 2) { if (sponsorTimes != null && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length >= 2) {
document.getElementById("submitButton").style.display = "unset"; document.getElementById("submitButton").style.display = "unset";
} else if (sponsorTimes != undefined && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) { } else if (sponsorTimes != null && sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
toggleStartSponsorButton(); toggleStartSponsorButton();
} }
} }
@@ -232,7 +241,7 @@ function sponsorCheck(sponsorTimes) { // Video skipping
} }
function goBackToPreviousTime(UUID) { function goBackToPreviousTime(UUID) {
if (sponsorTimes != undefined) { if (sponsorTimes != null) {
//add a tiny bit of time to make sure it is not skipped again //add a tiny bit of time to make sure it is not skipped again
v.currentTime = sponsorTimes[UUIDs.indexOf(UUID)][0] + 0.001; v.currentTime = sponsorTimes[UUIDs.indexOf(UUID)][0] + 0.001;

View File

@@ -1,7 +1,7 @@
{ {
"name": "SponsorBlock - YouTube Sponsorship Blocker", "name": "SponsorBlock - YouTube Sponsorship Blocker",
"short_name": "SponsorBlock", "short_name": "SponsorBlock",
"version": "1.0.11", "version": "1.0.12",
"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": [
{ {

View File

@@ -1,7 +1,7 @@
{ {
"name": "SponsorBlock - YouTube Sponsorship Blocker", "name": "SponsorBlock - YouTube Sponsorship Blocker",
"short_name": "SponsorBlock", "short_name": "SponsorBlock",
"version": "1.0.11", "version": "1.0.12",
"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": [
{ {