mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-12 14:37:23 +03:00
Merge pull request #90 from OfficialNoob/patch-19
Removed tabs permission
This commit is contained in:
@@ -1,27 +1,7 @@
|
|||||||
//when a new tab is highlighted
|
|
||||||
chrome.tabs.onActivated.addListener(
|
|
||||||
function(activeInfo) {
|
|
||||||
chrome.tabs.get(activeInfo.tabId, function(tab) {
|
|
||||||
let id = getYouTubeVideoID(tab.url);
|
|
||||||
|
|
||||||
//if this even is a YouTube tab
|
|
||||||
if (id) {
|
|
||||||
videoIDChange(id, activeInfo.tabId);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
//when a tab changes URLs
|
|
||||||
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
|
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
|
||||||
if (changeInfo != undefined && changeInfo.url != undefined) {
|
chrome.tabs.sendMessage(tabId, {
|
||||||
let id = getYouTubeVideoID(changeInfo.url);
|
message: 'update',
|
||||||
|
});
|
||||||
//if URL changed and is youtube video message contentScript the video id
|
|
||||||
if (changeInfo.url && id) {
|
|
||||||
videoIDChange(id, tabId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
||||||
@@ -49,7 +29,14 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
|||||||
|
|
||||||
//this allows the callback to be called later
|
//this allows the callback to be called later
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (request.message == "alertPrevious") {
|
||||||
|
chrome.notifications.create("stillThere" + Math.random(), {
|
||||||
|
type: "basic",
|
||||||
|
title: "Do you want to submit the sponsor times for video id " + request.previousVideoID + "?",
|
||||||
|
message: "You seem to have left some sponsor times unsubmitted. Go back to that page to submit them (they are not deleted).",
|
||||||
|
iconUrl: "./icons/LogoSponsorBlocker256px.png"
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//add help page on install
|
//add help page on install
|
||||||
@@ -193,56 +180,6 @@ function submitTimes(videoID, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function videoIDChange(currentVideoID, tabId) {
|
|
||||||
//send a message to the content script
|
|
||||||
chrome.tabs.sendMessage(tabId, {
|
|
||||||
message: 'ytvideoid',
|
|
||||||
id: currentVideoID
|
|
||||||
});
|
|
||||||
|
|
||||||
chrome.storage.sync.get(["sponsorVideoID", "previousVideoID"], function(result) {
|
|
||||||
const sponsorVideoID = result.sponsorVideoID;
|
|
||||||
const previousVideoID = result.previousVideoID;
|
|
||||||
|
|
||||||
//not a url change
|
|
||||||
if (sponsorVideoID == currentVideoID){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
chrome.storage.sync.set({
|
|
||||||
"sponsorVideoID": currentVideoID
|
|
||||||
});
|
|
||||||
|
|
||||||
//warn them if they had unsubmitted times
|
|
||||||
if (previousVideoID != null) {
|
|
||||||
//get the sponsor times from storage
|
|
||||||
let sponsorTimeKey = 'sponsorTimes' + previousVideoID;
|
|
||||||
chrome.storage.sync.get([sponsorTimeKey], function(result) {
|
|
||||||
let sponsorTimes = result[sponsorTimeKey];
|
|
||||||
|
|
||||||
if (sponsorTimes != undefined && sponsorTimes.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: "./icons/LogoSponsorBlocker256px.png"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//set the previous video id to the currentID
|
|
||||||
chrome.storage.sync.set({
|
|
||||||
"previousVideoID": currentVideoID
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
chrome.storage.sync.set({
|
|
||||||
"previousVideoID": currentVideoID
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function sendRequestToServer(type, address, callback) {
|
function sendRequestToServer(type, address, callback) {
|
||||||
let xmlhttp = new XMLHttpRequest();
|
let xmlhttp = new XMLHttpRequest();
|
||||||
|
|
||||||
|
|||||||
44
content.js
44
content.js
@@ -1,6 +1,6 @@
|
|||||||
//was sponsor data found when doing SponsorsLookup
|
//was sponsor data found when doing SponsorsLookup
|
||||||
var sponsorDataFound = false;
|
var sponsorDataFound = false;
|
||||||
|
var previousVideoID = null;
|
||||||
//the actual sponsorTimes if loaded and UUIDs associated with them
|
//the actual sponsorTimes if loaded and UUIDs associated with them
|
||||||
var sponsorTimes = null;
|
var sponsorTimes = null;
|
||||||
var UUIDs = null;
|
var UUIDs = null;
|
||||||
@@ -81,14 +81,14 @@ chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) {
|
|||||||
|
|
||||||
//get messages from the background script and the popup
|
//get messages from the background script and the popup
|
||||||
chrome.runtime.onMessage.addListener(messageListener);
|
chrome.runtime.onMessage.addListener(messageListener);
|
||||||
|
|
||||||
function messageListener(request, sender, sendResponse) {
|
function messageListener(request, sender, sendResponse) {
|
||||||
//message from background script
|
|
||||||
if (request.message == "ytvideoid") {
|
|
||||||
videoIDChange(request.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
//messages from popup script
|
//messages from popup script
|
||||||
|
|
||||||
|
if (request.message == "update") {
|
||||||
|
if(id = getYouTubeVideoID(document.URL)) videoIDChange(id);
|
||||||
|
}
|
||||||
|
|
||||||
if (request.message == "sponsorStart") {
|
if (request.message == "sponsorStart") {
|
||||||
sponsorMessageStarted(sendResponse);
|
sponsorMessageStarted(sendResponse);
|
||||||
}
|
}
|
||||||
@@ -183,11 +183,33 @@ document.onkeydown = function(e){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function videoIDChange(id) {
|
function videoIDChange(id) {
|
||||||
//not a url change
|
|
||||||
if (sponsorVideoID == id){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//not a url change
|
||||||
|
if (sponsorVideoID == id) return;
|
||||||
|
|
||||||
|
//warn them if they had unsubmitted times
|
||||||
|
if (previousVideoID != null) {
|
||||||
|
//get the sponsor times from storage
|
||||||
|
let sponsorTimeKey = 'sponsorTimes' + previousVideoID;
|
||||||
|
chrome.storage.sync.get([sponsorTimeKey], function(result) {
|
||||||
|
let sponsorTimes = result[sponsorTimeKey];
|
||||||
|
|
||||||
|
if (sponsorTimes != undefined && sponsorTimes.length > 0) {
|
||||||
|
//warn them that they have unsubmitted sponsor times
|
||||||
|
chrome.runtime.sendMessage({
|
||||||
|
message: "alertPrevious",
|
||||||
|
previousVideoID: previousVideoID
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
//set the previous video id to the currentID
|
||||||
|
previousVideoID = id;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
//set the previous id now, don't wait for chrome.storage.get
|
||||||
|
previousVideoID = id;
|
||||||
|
}
|
||||||
|
|
||||||
//close popup
|
//close popup
|
||||||
closeInfoMenu();
|
closeInfoMenu();
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,6 @@
|
|||||||
"popup.html"
|
"popup.html"
|
||||||
],
|
],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"tabs",
|
|
||||||
"storage",
|
"storage",
|
||||||
"notifications",
|
"notifications",
|
||||||
"https://sponsor.ajay.app/*"
|
"https://sponsor.ajay.app/*"
|
||||||
|
|||||||
14
popup.js
14
popup.js
@@ -201,16 +201,20 @@ function runThePopup() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
chrome.tabs.query({
|
chrome.tabs.query({
|
||||||
active: true,
|
active: true,
|
||||||
currentWindow: true
|
currentWindow: true
|
||||||
}, loadTabData);
|
}, onTabs);
|
||||||
|
|
||||||
|
function onTabs(tabs) {
|
||||||
|
chrome.tabs.sendMessage(tabs[0].id, {message: 'getVideoID'}, function(result) {
|
||||||
|
if (result.videoID) {
|
||||||
|
loadTabData(tabs, result.videoid);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function loadTabData(tabs) {
|
function loadTabData(tabs, currentVideoID) {
|
||||||
//set current videoID
|
|
||||||
currentVideoID = getYouTubeVideoID(tabs[0].url);
|
|
||||||
|
|
||||||
if (!currentVideoID) {
|
if (!currentVideoID) {
|
||||||
//this isn't a YouTube video then
|
//this isn't a YouTube video then
|
||||||
|
|||||||
Reference in New Issue
Block a user