Added support for the on page popup.

This commit is contained in:
Ajay Ramachandran
2020-02-01 17:36:02 -05:00
parent 932cf8ecf1
commit de66e21d14
3 changed files with 30 additions and 43 deletions

View File

@@ -1,6 +1,8 @@
import Utils from "./utils";
import SB from "./SB";
import runThePopup from "./popup.js";
import PreviewBar from "./js-components/previewBar";
import SkipNotice from "./js-components/previewBar";
@@ -74,7 +76,7 @@ var popupInitialised = false;
//get messages from the background script and the popup
chrome.runtime.onMessage.addListener(messageListener);
function messageListener(request, sender, sendResponse) {
function messageListener(request: any, sender: any, sendResponse: (response: any) => void): void {
//messages from popup script
switch(request.message){
case "update":
@@ -578,7 +580,7 @@ function skipToTime(v, index, sponsorTimes, openNotice) {
//send telemetry that a this sponsor was skipped
if (SB.config.trackViewCount && !sponsorSkipped[index]) {
sendRequestToServer("POST", "/api/viewedVideoSponsorTime?UUID=" + currentUUID);
Utils.sendRequestToServer("POST", "/api/viewedVideoSponsorTime?UUID=" + currentUUID);
if (!SB.config.disableAutoSkip) {
// Count this as a skip
@@ -806,7 +808,7 @@ function openInfoMenu() {
parentNode.insertBefore(popup, parentNode.firstChild);
//run the popup init script
runThePopup();
runThePopup(messageListener);
}
});
}
@@ -1055,25 +1057,6 @@ function getFormattedTime(seconds) {
return formatted;
}
function sendRequestToServer(type: string, address: string, callback = null) {
let xmlhttp = new XMLHttpRequest();
xmlhttp.open(type, serverAddress + address, true);
if (callback !== null) {
xmlhttp.onreadystatechange = function () {
callback(xmlhttp, false);
};
xmlhttp.onerror = function(ev) {
callback(xmlhttp, true);
};
}
//submit this request
xmlhttp.send();
}
function sendRequestToCustomServer(type, fullAddress, callback) {
let xmlhttp = new XMLHttpRequest();