mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 09:07:45 +01:00
Remove legacy editing code from popup
This commit is contained in:
parent
0253016871
commit
06d600c6d0
1 changed files with 0 additions and 276 deletions
276
src/popup.ts
276
src/popup.ts
|
@ -475,282 +475,6 @@ async function runThePopup(messageListener?: MessageListener) {
|
|||
return sponsorTimesMessage;
|
||||
}
|
||||
|
||||
//get the message that visually displays the video times
|
||||
//this version is a div that contains each with delete buttons
|
||||
function getSponsorTimesMessageDiv(sponsorTimes) {
|
||||
// let sponsorTimesMessage = "";
|
||||
let sponsorTimesContainer = document.createElement("div");
|
||||
sponsorTimesContainer.id = "sponsorTimesContainer";
|
||||
|
||||
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||
let currentSponsorTimeContainer = document.createElement("div");
|
||||
currentSponsorTimeContainer.id = "sponsorTimeContainer" + i;
|
||||
currentSponsorTimeContainer.className = "sponsorTime popupElement";
|
||||
let currentSponsorTimeMessage = "";
|
||||
|
||||
let deleteButton = document.createElement("span");
|
||||
deleteButton.id = "sponsorTimeDeleteButton" + i;
|
||||
deleteButton.innerText = "Delete";
|
||||
deleteButton.className = "mediumLink popupElement";
|
||||
let index = i;
|
||||
deleteButton.addEventListener("click", () => deleteSponsorTime(index));
|
||||
|
||||
let previewButton = document.createElement("span");
|
||||
previewButton.id = "sponsorTimePreviewButton" + i;
|
||||
previewButton.innerText = "Preview";
|
||||
previewButton.className = "mediumLink popupElement";
|
||||
previewButton.addEventListener("click", () => previewSponsorTime(index));
|
||||
|
||||
let editButton = document.createElement("span");
|
||||
editButton.id = "sponsorTimeEditButton" + i;
|
||||
editButton.innerText = "Edit";
|
||||
editButton.className = "mediumLink popupElement";
|
||||
editButton.addEventListener("click", () => editSponsorTime(index));
|
||||
|
||||
for (let s = 0; s < sponsorTimes[i].length; s++) {
|
||||
let timeMessage = getFormattedTime(sponsorTimes[i][s]);
|
||||
//if this is an end time
|
||||
if (s == 1) {
|
||||
timeMessage = " " + chrome.i18n.getMessage("to") + " " + timeMessage;
|
||||
} else if (i > 0) {
|
||||
//add commas if necessary
|
||||
timeMessage = timeMessage;
|
||||
}
|
||||
|
||||
currentSponsorTimeMessage += timeMessage;
|
||||
}
|
||||
|
||||
currentSponsorTimeContainer.innerText = currentSponsorTimeMessage;
|
||||
|
||||
sponsorTimesContainer.appendChild(currentSponsorTimeContainer);
|
||||
sponsorTimesContainer.appendChild(deleteButton);
|
||||
|
||||
//only if it is a complete sponsor time
|
||||
if (sponsorTimes[i].length > 1) {
|
||||
sponsorTimesContainer.appendChild(previewButton);
|
||||
sponsorTimesContainer.appendChild(editButton);
|
||||
|
||||
currentSponsorTimeContainer.addEventListener("click", () => editSponsorTime(index));
|
||||
}
|
||||
}
|
||||
|
||||
return sponsorTimesContainer;
|
||||
}
|
||||
|
||||
function previewSponsorTime(index) {
|
||||
let skipTime = sponsorTimes[index].segment[0];
|
||||
|
||||
if (document.getElementById("startTimeMinutes" + index) != null) {
|
||||
//edit is currently open, use that time
|
||||
|
||||
skipTime = getSponsorTimeEditTimes("startTime", index);
|
||||
|
||||
//save the edit
|
||||
saveSponsorTimeEdit(index, false);
|
||||
}
|
||||
|
||||
messageHandler.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
}, tabs => {
|
||||
messageHandler.sendMessage(
|
||||
tabs[0].id, {
|
||||
message: "skipToTime",
|
||||
time: skipTime - 2
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function editSponsorTime(index) {
|
||||
if (document.getElementById("startTimeMinutes" + index) != null) {
|
||||
//already open
|
||||
return;
|
||||
}
|
||||
|
||||
//hide submit button
|
||||
document.getElementById("submitTimesContainer").style.display = "none";
|
||||
|
||||
let sponsorTimeContainer = document.getElementById("sponsorTimeContainer" + index);
|
||||
|
||||
//the button to set the current time
|
||||
let startTimeNowButton = document.createElement("span");
|
||||
startTimeNowButton.id = "startTimeNowButton" + index;
|
||||
startTimeNowButton.innerText = "(Now)";
|
||||
startTimeNowButton.className = "tinyLink popupElement";
|
||||
startTimeNowButton.addEventListener("click", () => setEditTimeToCurrentTime("startTime", index));
|
||||
|
||||
//get sponsor time minutes and seconds boxes
|
||||
let startTimeMinutes = document.createElement("input");
|
||||
startTimeMinutes.id = "startTimeMinutes" + index;
|
||||
startTimeMinutes.className = "sponsorTime popupElement";
|
||||
startTimeMinutes.type = "text";
|
||||
startTimeMinutes.value = String(getTimeInMinutes(sponsorTimes[index].segment[0]));
|
||||
startTimeMinutes.style.width = "45px";
|
||||
|
||||
let startTimeSeconds = document.createElement("input");
|
||||
startTimeSeconds.id = "startTimeSeconds" + index;
|
||||
startTimeSeconds.className = "sponsorTime popupElement";
|
||||
startTimeSeconds.type = "text";
|
||||
startTimeSeconds.value = getTimeInFormattedSeconds(sponsorTimes[index].segment[0]);
|
||||
startTimeSeconds.style.width = "60px";
|
||||
|
||||
let endTimeMinutes = document.createElement("input");
|
||||
endTimeMinutes.id = "endTimeMinutes" + index;
|
||||
endTimeMinutes.className = "sponsorTime popupElement";
|
||||
endTimeMinutes.type = "text";
|
||||
endTimeMinutes.value = String(getTimeInMinutes(sponsorTimes[index].segment[1]));
|
||||
endTimeMinutes.style.width = "45px";
|
||||
|
||||
let endTimeSeconds = document.createElement("input");
|
||||
endTimeSeconds.id = "endTimeSeconds" + index;
|
||||
endTimeSeconds.className = "sponsorTime popupElement";
|
||||
endTimeSeconds.type = "text";
|
||||
endTimeSeconds.value = getTimeInFormattedSeconds(sponsorTimes[index].segment[1]);
|
||||
endTimeSeconds.style.width = "60px";
|
||||
|
||||
//the button to set the current time
|
||||
let endTimeNowButton = document.createElement("span");
|
||||
endTimeNowButton.id = "endTimeNowButton" + index;
|
||||
endTimeNowButton.innerText = "(Now)";
|
||||
endTimeNowButton.className = "tinyLink popupElement";
|
||||
endTimeNowButton.addEventListener("click", () => setEditTimeToCurrentTime("endTime", index));
|
||||
|
||||
let colonText = document.createElement("span");
|
||||
colonText.innerText = ":";
|
||||
|
||||
let toText = document.createElement("span");
|
||||
toText.innerText = " " + chrome.i18n.getMessage("to") + " ";
|
||||
|
||||
//remove all children to replace
|
||||
while (sponsorTimeContainer.firstChild) {
|
||||
sponsorTimeContainer.removeChild(sponsorTimeContainer.firstChild);
|
||||
}
|
||||
|
||||
sponsorTimeContainer.appendChild(startTimeNowButton);
|
||||
sponsorTimeContainer.appendChild(startTimeMinutes);
|
||||
sponsorTimeContainer.appendChild(colonText);
|
||||
sponsorTimeContainer.appendChild(startTimeSeconds);
|
||||
sponsorTimeContainer.appendChild(toText);
|
||||
sponsorTimeContainer.appendChild(endTimeMinutes);
|
||||
sponsorTimeContainer.appendChild(colonText);
|
||||
sponsorTimeContainer.appendChild(endTimeSeconds);
|
||||
sponsorTimeContainer.appendChild(endTimeNowButton);
|
||||
|
||||
//add save button and remove edit button
|
||||
let saveButton = document.createElement("span");
|
||||
saveButton.id = "sponsorTimeSaveButton" + index;
|
||||
saveButton.innerText = "Save";
|
||||
saveButton.className = "mediumLink popupElement";
|
||||
saveButton.addEventListener("click", () => saveSponsorTimeEdit(index));
|
||||
|
||||
let editButton = document.getElementById("sponsorTimeEditButton" + index);
|
||||
let sponsorTimesContainer = document.getElementById("sponsorTimesContainer");
|
||||
|
||||
sponsorTimesContainer.replaceChild(saveButton, editButton);
|
||||
}
|
||||
|
||||
function setEditTimeToCurrentTime(idStartName, index) {
|
||||
messageHandler.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
}, tabs => {
|
||||
messageHandler.sendMessage(
|
||||
tabs[0].id,
|
||||
{message: "getCurrentTime"},
|
||||
function (response) {
|
||||
let minutes = <HTMLInputElement> <unknown> document.getElementById(idStartName + "Minutes" + index);
|
||||
let seconds = <HTMLInputElement> <unknown> document.getElementById(idStartName + "Seconds" + index);
|
||||
|
||||
minutes.value = String(getTimeInMinutes(response.currentTime));
|
||||
seconds.value = getTimeInFormattedSeconds(response.currentTime);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//id start name is whether it is the startTime or endTime
|
||||
//gives back the time in seconds
|
||||
function getSponsorTimeEditTimes(idStartName, index): number {
|
||||
let minutes = <HTMLInputElement> <unknown> document.getElementById(idStartName + "Minutes" + index);
|
||||
let seconds = <HTMLInputElement> <unknown> document.getElementById(idStartName + "Seconds" + index);
|
||||
|
||||
return parseInt(minutes.value) * 60 + parseFloat(seconds.value);
|
||||
}
|
||||
|
||||
function saveSponsorTimeEdit(index, closeEditMode = true) {
|
||||
sponsorTimes[index].segment[0] = getSponsorTimeEditTimes("startTime", index);
|
||||
sponsorTimes[index].segment[1] = getSponsorTimeEditTimes("endTime", index);
|
||||
|
||||
//save this
|
||||
Config.config.segmentTimes.set(currentVideoID, sponsorTimes);
|
||||
|
||||
messageHandler.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
}, tabs => {
|
||||
messageHandler.sendMessage(
|
||||
tabs[0].id,
|
||||
{message: "sponsorDataChanged"}
|
||||
);
|
||||
});
|
||||
|
||||
if (closeEditMode) {
|
||||
showSubmitTimesIfNecessary();
|
||||
}
|
||||
}
|
||||
|
||||
//deletes the sponsor time submitted at an index
|
||||
function deleteSponsorTime(index) {
|
||||
//if it is not a complete sponsor time
|
||||
if (sponsorTimes[index].segment.length < 2) {
|
||||
messageHandler.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
}, function(tabs) {
|
||||
messageHandler.sendMessage(tabs[0].id, {
|
||||
message: "changeStartSponsorButton",
|
||||
showStartSponsor: true,
|
||||
uploadButtonVisible: false
|
||||
});
|
||||
});
|
||||
|
||||
resetStartTimeChosen();
|
||||
}
|
||||
|
||||
sponsorTimes.splice(index, 1);
|
||||
|
||||
//save this
|
||||
Config.config.segmentTimes.set(currentVideoID, sponsorTimes);
|
||||
|
||||
//if they are all removed
|
||||
if (sponsorTimes.length == 0) {
|
||||
//update chrome tab
|
||||
messageHandler.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
}, function(tabs) {
|
||||
messageHandler.sendMessage(tabs[0].id, {
|
||||
message: "changeStartSponsorButton",
|
||||
showStartSponsor: true,
|
||||
uploadButtonVisible: false
|
||||
});
|
||||
});
|
||||
|
||||
//hide submission section
|
||||
document.getElementById("submissionSection").style.display = "none";
|
||||
}
|
||||
|
||||
messageHandler.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
}, tabs => {
|
||||
messageHandler.sendMessage(
|
||||
tabs[0].id,
|
||||
{message: "sponsorDataChanged"}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function submitTimes() {
|
||||
if (sponsorTimes.length > 0) {
|
||||
messageHandler.query({
|
||||
|
|
Loading…
Reference in a new issue