Merge pull request #90 from OfficialNoob/patch-19

Removed tabs permission
This commit is contained in:
Ajay Ramachandran
2019-08-12 11:36:57 -04:00
committed by GitHub
4 changed files with 53 additions and 91 deletions

View File

@@ -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) {
if (changeInfo != undefined && changeInfo.url != undefined) {
let id = getYouTubeVideoID(changeInfo.url);
//if URL changed and is youtube video message contentScript the video id
if (changeInfo.url && id) {
videoIDChange(id, tabId);
}
}
chrome.tabs.sendMessage(tabId, {
message: 'update',
});
});
chrome.runtime.onMessage.addListener(function (request, sender, callback) {
@@ -49,6 +29,13 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
//this allows the callback to be called later
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"
});
}
});
@@ -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) {
let xmlhttp = new XMLHttpRequest();

View File

@@ -1,6 +1,6 @@
//was sponsor data found when doing SponsorsLookup
var sponsorDataFound = false;
var previousVideoID = null;
//the actual sponsorTimes if loaded and UUIDs associated with them
var sponsorTimes = null;
var UUIDs = null;
@@ -83,12 +83,12 @@ chrome.storage.sync.get(["dontShowNoticeAgain"], function(result) {
chrome.runtime.onMessage.addListener(messageListener);
function messageListener(request, sender, sendResponse) {
//message from background script
if (request.message == "ytvideoid") {
videoIDChange(request.id);
//messages from popup script
if (request.message == "update") {
if(id = getYouTubeVideoID(document.URL)) videoIDChange(id);
}
//messages from popup script
if (request.message == "sponsorStart") {
sponsorMessageStarted(sendResponse);
}
@@ -183,9 +183,31 @@ document.onkeydown = function(e){
}
function videoIDChange(id) {
//not a url change
if (sponsorVideoID == id){
return;
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

View File

@@ -36,7 +36,6 @@
"popup.html"
],
"permissions": [
"tabs",
"storage",
"notifications",
"https://sponsor.ajay.app/*"

View File

@@ -201,16 +201,20 @@ function runThePopup() {
}
});
chrome.tabs.query({
active: 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) {
//set current videoID
currentVideoID = getYouTubeVideoID(tabs[0].url);
function loadTabData(tabs, currentVideoID) {
if (!currentVideoID) {
//this isn't a YouTube video then