Compare commits

...

14 Commits

Author SHA1 Message Date
Ajay Ramachandran
ff9badf2e9 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
2019-07-28 17:56:50 -04:00
Ajay Ramachandran
aefc880486 Merge branch 'master' of https://github.com/ajayyy/SponsorBlock into experimental
# Conflicts:
#	content.js
#	firefox_manifest.json
#	manifest.json
2019-07-28 17:24:25 -04:00
Ajay Ramachandran
e749456719 Updated version number. 2019-07-28 17:23:01 -04:00
Ajay Ramachandran
a2312a10be Fixed an issue on Firefox where the old video's sponsors would sometimes play on the next video. 2019-07-28 17:22:05 -04:00
Ajay Ramachandran
b0090a3334 Merge pull request #37 from OfficialNoob/patch-5
getYouTubeVideoID Better ID Parser
2019-07-27 17:30:01 -04:00
Official Noob
7100831956 getYouTubeVideoID Video ID Parser 2019-07-27 22:18:43 +01:00
Ajay Ramachandran
30c1b2d919 Added reference and updated version number. 2019-07-27 11:18:50 -04:00
Ajay Ramachandran
3ec6caee9d Merge pull request #32 from OfficialNoob/patch-3
Added references
2019-07-27 11:13:21 -04:00
Ajay Ramachandran
7f505a52ca Merge pull request #30 from OfficialNoob/patch-1
Added confirm for submitSponsorTimes
2019-07-27 11:12:36 -04:00
Ajay Ramachandran
84b8e59b39 Merge branch 'master' into patch-1 2019-07-27 11:12:27 -04:00
Ajay Ramachandran
808dfe42ce Merge pull request #35 from ajayyy/experimental
Made it not possible to submit from the hotkey when not ready
2019-07-27 11:10:23 -04:00
Ajay Ramachandran
600365d998 Made it not possible to submit from the hotkey when not ready. 2019-07-27 11:08:29 -04:00
Official Noob
569699cbc1 Added references 2019-07-27 13:57:04 +01:00
Official Noob
08cb324125 Added confirm for submitSponsorTimes 2019-07-27 12:57:44 +01:00
4 changed files with 88 additions and 61 deletions

View File

@@ -1,13 +1,15 @@
if(id = getYouTubeVideoID(document.URL)){ // Direct Links
videoIDChange(id);
}
//was sponsor data found when doing SponsorsLookup
var sponsorDataFound = false;
//the actual sponsorTimes if loaded and UUIDs associated with them
var sponsorTimes = undefined;
var UUIDs = undefined;
var sponsorTimes = null;
var UUIDs = null;
//what video id are these sponsors for
var sponsorVideoID = null;
if(id = getYouTubeVideoID(document.URL)){ // Direct Links
videoIDChange(id);
}
//the video
var v;
@@ -53,6 +55,7 @@ chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) {
chrome.runtime.onMessage.addListener( // Detect URL Changes
function(request, sender, sendResponse) {
console.log(request.message)
//message from background script
if (request.message == "ytvideoid") {
videoIDChange(request.id);
@@ -117,13 +120,19 @@ document.onkeydown = function(e){
}
function videoIDChange(id) {
//not a url change
if (sponsorVideoID == id){
return;
}
//reset last sponsor times
lastTime = -1;
lastUnixTimeSkipped = -1;
//reset sponsor times
sponsorTimes = undefined;
UUIDs = undefined;
sponsorTimes = null;
UUIDs = null;
sponsorVideoID = id;
//reset sponsor data found check
sponsorDataFound = false;
@@ -136,9 +145,9 @@ function videoIDChange(id) {
}, function(response) {
if (response != undefined) {
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";
} 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();
}
}
@@ -232,7 +241,7 @@ function sponsorCheck(sponsorTimes) { // Video skipping
}
function goBackToPreviousTime(UUID) {
if (sponsorTimes != undefined) {
if (sponsorTimes != null) {
//add a tiny bit of time to make sure it is not skipped again
v.currentTime = sponsorTimes[UUIDs.indexOf(UUID)][0] + 0.001;
@@ -593,6 +602,13 @@ function sponsorMessageStarted() {
}
function submitSponsorTimes() {
if(!confirm("Are you sure you want to submit this?")) return;
if (document.getElementById("submitButton").style.display == "none") {
//don't submit, not ready
return;
}
//add loading animation
document.getElementById("submitButtonImage").src = chrome.extension.getURL("icons/PlayerUploadIconSponsorBlocker256px.png");
document.getElementById("submitButton").style.animation = "rotate 1s 0s infinite";
@@ -669,5 +685,6 @@ function sendRequestToCustomServer(type, fullAddress, callback) {
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);
return (match && match[7].length == 11) ? match[7] : false;
var id = new URL(url).searchParams.get("v");
return (match && match[7].length == 11) ? id : false;
}

View File

@@ -1,7 +1,7 @@
{
"name": "SponsorBlock - YouTube Sponsorship Blocker",
"short_name": "SponsorBlock",
"version": "1.0.9",
"version": "1.0.12",
"description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
"content_scripts": [
{

View File

@@ -1,7 +1,7 @@
{
"name": "SponsorBlock - YouTube Sponsorship Blocker",
"short_name": "SponsorBlock",
"version": "1.0.9",
"version": "1.0.12",
"description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
"content_scripts": [
{

100
popup.js
View File

@@ -1,14 +1,33 @@
// References
var SB = {};
SB.sponsorStart = document.getElementById("sponsorStart");
SB.clearTimes = document.getElementById("clearTimes");
SB.submitTimes = document.getElementById("submitTimes");
SB.showNoticeAgain = document.getElementById("showNoticeAgain");
SB.hideVideoPlayerControls = document.getElementById("hideVideoPlayerControls");
SB.showVideoPlayerControls = document.getElementById("showVideoPlayerControls");
SB.disableSponsorViewTracking = document.getElementById("disableSponsorViewTracking");
SB.enableSponsorViewTracking = document.getElementById("enableSponsorViewTracking");
SB.optionsButton = document.getElementById("optionsButton");
SB.reportAnIssue = document.getElementById("reportAnIssue");
// sponsorTimesContributions
SB.sponsorTimesContributionsContainer = document.getElementById("sponsorTimesContributionsContainer");
SB.sponsorTimesContributionsDisplay = document.getElementById("sponsorTimesContributionsDisplay");
SB.sponsorTimesContributionsDisplayEndWord = document.getElementById("sponsorTimesContributionsDisplayEndWord");
//setup click listeners
document.getElementById("sponsorStart").addEventListener("click", sendSponsorStartMessage);
document.getElementById("clearTimes").addEventListener("click", clearTimes);
document.getElementById("submitTimes").addEventListener("click", submitTimes);
document.getElementById("showNoticeAgain").addEventListener("click", showNoticeAgain);
document.getElementById("hideVideoPlayerControls").addEventListener("click", hideVideoPlayerControls);
document.getElementById("showVideoPlayerControls").addEventListener("click", showVideoPlayerControls);
document.getElementById("disableSponsorViewTracking").addEventListener("click", disableSponsorViewTracking);
document.getElementById("enableSponsorViewTracking").addEventListener("click", enableSponsorViewTracking);
document.getElementById("optionsButton").addEventListener("click", openOptions);
document.getElementById("reportAnIssue").addEventListener("click", reportAnIssue);
SB.sponsorStart.addEventListener("click", sendSponsorStartMessage);
SB.clearTimes.addEventListener("click", clearTimes);
SB.submitTimes.addEventListener("click", submitTimes);
SB.showNoticeAgain.addEventListener("click", showNoticeAgain);
SB.hideVideoPlayerControls.addEventListener("click", hideVideoPlayerControls);
SB.showVideoPlayerControls.addEventListener("click", showVideoPlayerControls);
SB.disableSponsorViewTracking.addEventListener("click", disableSponsorViewTracking);
SB.enableSponsorViewTracking.addEventListener("click", enableSponsorViewTracking);
SB.optionsButton.addEventListener("click", openOptions);
SB.reportAnIssue.addEventListener("click", reportAnIssue);
//if true, the button now selects the end time
var startTimeChosen = false;
@@ -27,7 +46,7 @@ var isYouTubeTab = false;
chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) {
let dontShowNoticeAgain = result.dontShowNoticeAgain;
if (dontShowNoticeAgain != undefined && dontShowNoticeAgain) {
document.getElementById("showNoticeAgain").style.display = "unset";
SB.showNoticeAgain.style.display = "unset";
}
});
@@ -35,8 +54,8 @@ chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) {
chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) {
let hideVideoPlayerControls = result.hideVideoPlayerControls;
if (hideVideoPlayerControls != undefined && hideVideoPlayerControls) {
document.getElementById("hideVideoPlayerControls").style.display = "none";
document.getElementById("showVideoPlayerControls").style.display = "unset";
SB.hideVideoPlayerControls.style.display = "none";
SB.showVideoPlayerControls.style.display = "unset";
}
});
@@ -44,25 +63,21 @@ chrome.storage.sync.get(["hideVideoPlayerControls"], function(result) {
chrome.storage.sync.get(["trackViewCount"], function(result) {
let trackViewCount = result.trackViewCount;
if (trackViewCount != undefined && !trackViewCount) {
document.getElementById("disableSponsorViewTracking").style.display = "none";
document.getElementById("enableSponsorViewTracking").style.display = "unset";
SB.disableSponsorViewTracking.style.display = "none";
SB.enableSponsorViewTracking.style.display = "unset";
}
});
//get the amount of times this user has contributed and display it to thank them
chrome.storage.sync.get(["sponsorTimesContributed"], function(result) {
if (result.sponsorTimesContributed != undefined) {
let sponsorTimesContributionsContainer = document.getElementById("sponsorTimesContributionsContainer");
let sponsorTimesContributionsDisplay = document.getElementById("sponsorTimesContributionsDisplay");
let sponsorTimesContributionsDisplayEndWord = document.getElementById("sponsorTimesContributionsDisplayEndWord");
if (result.sponsorTimesContributed > 1) {
sponsorTimesContributionsDisplayEndWord.innerText = "sponsors."
SB.sponsorTimesContributionsDisplayEndWord.innerText = "sponsors."
} else {
sponsorTimesContributionsDisplayEndWord.innerText = "sponsor."
SB.sponsorTimesContributionsDisplayEndWord.innerText = "sponsor."
}
sponsorTimesContributionsDisplay.innerText = result.sponsorTimesContributed;
sponsorTimesContributionsContainer.style.display = "unset";
SB.sponsorTimesContributionsDisplay.innerText = result.sponsorTimesContributed;
SB.sponsorTimesContributionsContainer.style.display = "unset";
//get the userID
chrome.storage.sync.get(["userID"], function(result) {
@@ -73,19 +88,14 @@ chrome.storage.sync.get(["sponsorTimesContributed"], function(result) {
sendRequestToServer("GET", "/api/getViewsForUser?userID=" + userID, function(xmlhttp) {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
let viewCount = JSON.parse(xmlhttp.responseText).viewCount;
if (viewCount != 0) {
let sponsorTimesViewsContainer = document.getElementById("sponsorTimesViewsContainer");
let sponsorTimesViewsDisplay = document.getElementById("sponsorTimesViewsDisplay");
let sponsorTimesViewsDisplayEndWord = document.getElementById("sponsorTimesViewsDisplayEndWord");
if (viewCount > 1) {
sponsorTimesViewsDisplayEndWord.innerText = "sponsor segments."
SB.sponsorTimesViewsDisplayEndWord.innerText = "sponsor segments."
} else {
sponsorTimesViewsDisplayEndWord.innerText = "sponsor segment."
SB.sponsorTimesViewsDisplayEndWord.innerText = "sponsor segment."
}
sponsorTimesViewsDisplay.innerText = viewCount;
sponsorTimesViewsContainer.style.display = "unset";
SB.sponsorTimesViewsDisplay.innerText = viewCount;
SB.sponsorTimesViewsContainer.style.display = "unset";
}
}
});
@@ -117,7 +127,7 @@ function loadTabData(tabs) {
if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
if (sponsorTimesStorage[sponsorTimesStorage.length - 1] != undefined && sponsorTimesStorage[sponsorTimesStorage.length - 1].length < 2) {
startTimeChosen = true;
document.getElementById("sponsorStart").innerHTML = "Sponsorship Ends Now";
SB.sponsorStart.innerHTML = "Sponsorship Ends Now";
}
sponsorTimes = sponsorTimesStorage;
@@ -372,7 +382,7 @@ function showNoticeAgain() {
});
});
document.getElementById("showNoticeAgain").style.display = "none";
SB.showNoticeAgain.style.display = "none";
}
function hideVideoPlayerControls() {
@@ -388,8 +398,8 @@ function hideVideoPlayerControls() {
});
});
document.getElementById("hideVideoPlayerControls").style.display = "none";
document.getElementById("showVideoPlayerControls").style.display = "unset";
SB.hideVideoPlayerControls.style.display = "none";
SB.showVideoPlayerControls.style.display = "unset";
}
function showVideoPlayerControls() {
@@ -405,8 +415,8 @@ function showVideoPlayerControls() {
});
});
document.getElementById("hideVideoPlayerControls").style.display = "unset";
document.getElementById("showVideoPlayerControls").style.display = "none";
SB.hideVideoPlayerControls.style.display = "unset";
SB.showVideoPlayerControls.style.display = "none";
}
function disableSponsorViewTracking() {
@@ -422,8 +432,8 @@ function disableSponsorViewTracking() {
});
});
document.getElementById("disableSponsorViewTracking").style.display = "none";
document.getElementById("enableSponsorViewTracking").style.display = "unset";
SB.disableSponsorViewTracking.style.display = "none";
SB.enableSponsorViewTracking.style.display = "unset";
}
function enableSponsorViewTracking() {
@@ -439,15 +449,15 @@ function enableSponsorViewTracking() {
});
});
document.getElementById("enableSponsorViewTracking").style.display = "none";
document.getElementById("disableSponsorViewTracking").style.display = "unset";
SB.enableSponsorViewTracking.style.display = "none";
SB.disableSponsorViewTracking.style.display = "unset";
}
function updateStartTimeChosen() {
//update startTimeChosen variable
if (!startTimeChosen) {
startTimeChosen = true;
document.getElementById("sponsorStart").innerHTML = "Sponsorship Ends Now";
SB.sponsorStart.innerHTML = "Sponsorship Ends Now";
} else {
resetStartTimeChosen();
}
@@ -456,7 +466,7 @@ function updateStartTimeChosen() {
//set it to false
function resetStartTimeChosen() {
startTimeChosen = false;
document.getElementById("sponsorStart").innerHTML = "Sponsorship Starts Now";
SB.sponsorStart.innerHTML = "Sponsorship Starts Now";
}
//hides and shows the submit times button when needed
@@ -485,7 +495,7 @@ function displayNoVideo() {
function reportAnIssue() {
document.getElementById("issueReporterContainer").style.display = "unset";
document.getElementById("reportAnIssue").style.display = "none";
SB.reportAnIssue.style.display = "none";
}
function addVoteMessage(message, UUID) {