mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-09 04:57:09 +03:00
Added warning if you leave a page before submitting your sponsor times.
This commit is contained in:
@@ -1,25 +1,34 @@
|
|||||||
|
var previousVideoID = null
|
||||||
|
|
||||||
chrome.tabs.onUpdated.addListener( // On tab update
|
chrome.tabs.onUpdated.addListener( // On tab update
|
||||||
function(tabId, changeInfo, tab) {
|
function(tabId, changeInfo, tab) {
|
||||||
if (changeInfo != undefined && changeInfo.url != undefined) {
|
if (changeInfo != undefined && changeInfo.url != undefined) {
|
||||||
let id = getYouTubeVideoID(changeInfo.url);
|
let id = getYouTubeVideoID(changeInfo.url);
|
||||||
if (changeInfo.url && id) { // If URL changed and is youtube video message contentScript the video id
|
if (changeInfo.url && id) { // If URL changed and is youtube video message contentScript the video id
|
||||||
|
videoIDChange(id);
|
||||||
|
|
||||||
chrome.tabs.sendMessage( tabId, {
|
chrome.tabs.sendMessage( tabId, {
|
||||||
message: 'ytvideoid',
|
message: 'ytvideoid',
|
||||||
id: id
|
id: id
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
||||||
console.log(request.message)
|
|
||||||
if (request.message == "submitTimes") {
|
if (request.message == "submitTimes") {
|
||||||
submitTimes(request.videoID);
|
submitTimes(request.videoID);
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
success: true
|
success: true
|
||||||
});
|
});
|
||||||
|
} else if(request.message == "ytvideoid") {
|
||||||
|
if (previousVideoID != request.videoID) {
|
||||||
|
videoIDChange(request.videoID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -29,7 +38,7 @@ function submitTimes(videoID) {
|
|||||||
chrome.storage.local.get([sponsorTimeKey], function(result) {
|
chrome.storage.local.get([sponsorTimeKey], function(result) {
|
||||||
let videoTimes = result[sponsorTimeKey];
|
let videoTimes = result[sponsorTimeKey];
|
||||||
|
|
||||||
if (videoTimes != undefined && result.videoTimes != []) {
|
if (videoTimes != undefined && videoTimes != []) {
|
||||||
//submit these times
|
//submit these times
|
||||||
for (let i = 0; i < videoTimes.length; i++) {
|
for (let i = 0; i < videoTimes.length; i++) {
|
||||||
let xmlhttp = new XMLHttpRequest();
|
let xmlhttp = new XMLHttpRequest();
|
||||||
@@ -41,6 +50,33 @@ function submitTimes(videoID) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function videoIDChange(currentVideoID) {
|
||||||
|
//warn them if they had unsubmitted times
|
||||||
|
if (previousVideoID != null) {
|
||||||
|
//get the sponsor times from storage
|
||||||
|
let sponsorTimeKey = 'videoTimes' + previousVideoID;
|
||||||
|
chrome.storage.local.get([sponsorTimeKey], function(result) {
|
||||||
|
let videoTimes = result[sponsorTimeKey];
|
||||||
|
|
||||||
|
if (videoTimes != undefined && videoTimes.length > 0) {
|
||||||
|
//warn them that they have unsubmitted sponsor times
|
||||||
|
chrome.notifications.create("stillThere" + Math.random(), {
|
||||||
|
type: "basic",
|
||||||
|
title: "Do you want to submit the sponsor times for watch?v=" + previousVideoID + "?",
|
||||||
|
message: "You seem to have left some sponsor times unsubmitted. Go back to that page to submit them (they are not deleted).",
|
||||||
|
iconUrl: "icon.png"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//set the previous video id to the currentID
|
||||||
|
previousVideoID = currentVideoID;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log(currentVideoID)
|
||||||
|
previousVideoID = currentVideoID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getYouTubeVideoID(url) { // Return video id or false
|
function getYouTubeVideoID(url) { // Return video id or 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);
|
||||||
|
|||||||
@@ -2,6 +2,12 @@ if(id = getYouTubeVideoID(document.URL)){ // Direct Links
|
|||||||
//reset sponsor data found check
|
//reset sponsor data found check
|
||||||
sponsorDataFound = false;
|
sponsorDataFound = false;
|
||||||
sponsorsLookup(id);
|
sponsorsLookup(id);
|
||||||
|
|
||||||
|
//tell background.js about this
|
||||||
|
chrome.runtime.sendMessage({
|
||||||
|
message: "ytvideoid",
|
||||||
|
videoID: id
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//was sponsor data found when doing SponsorsLookup
|
//was sponsor data found when doing SponsorsLookup
|
||||||
|
|||||||
@@ -14,7 +14,8 @@
|
|||||||
],
|
],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"tabs",
|
"tabs",
|
||||||
"storage"
|
"storage",
|
||||||
|
"notifications"
|
||||||
],
|
],
|
||||||
"browser_action": {
|
"browser_action": {
|
||||||
"default_title": "SponsorBlock",
|
"default_title": "SponsorBlock",
|
||||||
|
|||||||
4
popup.js
4
popup.js
@@ -35,12 +35,14 @@ function loadTabData(tabs) {
|
|||||||
let videoTimeKey = "videoTimes" + currentVideoID;
|
let videoTimeKey = "videoTimes" + currentVideoID;
|
||||||
chrome.storage.local.get([videoTimeKey], function(result) {
|
chrome.storage.local.get([videoTimeKey], function(result) {
|
||||||
videoTimes = result[videoTimeKey];
|
videoTimes = result[videoTimeKey];
|
||||||
if (videoTimes != undefined && result.videoTimes != []) {
|
if (videoTimes != undefined && videoTimes != []) {
|
||||||
if (videoTimes[videoTimes.length - 1]!= undefined && videoTimes[videoTimes.length - 1].length < 2) {
|
if (videoTimes[videoTimes.length - 1]!= undefined && videoTimes[videoTimes.length - 1].length < 2) {
|
||||||
startTimeChosen = true;
|
startTimeChosen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
displayVideoTimes();
|
displayVideoTimes();
|
||||||
|
} else {
|
||||||
|
videoTimes = []
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user