Merge pull request #250 from Lartza/min-duration

Add minimum duration option
This commit is contained in:
Ajay Ramachandran 2020-02-08 19:30:36 -05:00 committed by GitHub
commit 84fbc93c8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 84 additions and 5 deletions

View file

@ -386,5 +386,14 @@
},
"invidiousInfo2": {
"message": "You MUST enable it in the options for it to work."
},
"minDuration": {
"message": "Minimum duration (seconds):"
},
"minDurationDescription": {
"message": "Sponsor segments shorter than the set value will not be skipeed or show in the player."
},
"shortCheck": {
"message": "The following submission is shorter than your minimum duration option. This could mean that this is already submitted, and just being ignored due to this option. Are you sure you would like to submit?"
}
}

View file

@ -309,4 +309,13 @@ h1,h2,h3,h4,h5,h6 {
svg {
text-decoration: none;
}
.number-container:before {
content: attr(label-name);
padding-right: 4px;
width: max-content;
font-size: 14px;
color: white;
}

View file

@ -76,7 +76,7 @@
<br/>
<br/>
<div option-type="toggle" toggle-type="reverse" sync-option="disableAutoSkip">
<label class="switch-container" label-name="__MSG_autoSkip__">
<label class="switch">
@ -93,7 +93,7 @@
<br/>
<br/>
<div option-type="keybind-change" sync-option="startSponsorKeybind">
<div class="option-button trigger-button">
__MSG_setStartSponsorShortcut__
@ -132,6 +132,20 @@
</span>
</div>
</div>
<br/>
<br/>
<div option-type="number-change" sync-option="minDuration">
<label class="number-container" label-name="__MSG_minDuration__">
<input type="number" step="0.1" min="0">
</label>
<br/>
<br/>
<div class="small-description">__MSG_minDurationDescription__</div>
</div>
<br/>
<br/>

View file

@ -19,7 +19,8 @@ interface SBConfig {
invidiousInstances: string[],
invidiousUpdateInfoShowCount: number,
autoUpvote: boolean,
supportInvidious: false
supportInvidious: false,
minDuration: number
}
interface SBObject {
@ -111,7 +112,8 @@ var Config: SBObject = {
invidiousInstances: ["invidio.us", "invidiou.sh", "invidious.snopyta.org"],
invidiousUpdateInfoShowCount: 0,
autoUpvote: true,
supportInvidious: false
supportInvidious: false,
minDuration: 0
},
localConfig: null,
config: null

View file

@ -366,6 +366,22 @@ function sponsorsLookup(id: string, channelIDPromise?) {
sponsorTimes = JSON.parse(xmlhttp.responseText).sponsorTimes;
UUIDs = JSON.parse(xmlhttp.responseText).UUIDs;
// Remove all submissions smaller than the minimum duration
if (Config.config.minDuration !== 0) {
let smallSponsors = [];
let smallUUIDs = [];
for (let i = 0; i < sponsorTimes.length; i++) {
if (sponsorTimes[i][1] - sponsorTimes[i][0] >= Config.config.minDuration) {
smallSponsors.push(sponsorTimes[i]);
smallUUIDs.push(UUIDs[i]);
}
}
sponsorTimes = smallSponsors;
UUIDs = smallUUIDs;
}
// Reset skip save
sponsorSkipped = [];
@ -1006,6 +1022,17 @@ function submitSponsorTimes() {
//update sponsorTimesSubmitting
sponsorTimesSubmitting = sponsorTimes;
// Check to see if any of the submissions are below the minimum duration set
if (Config.config.minDuration > 0) {
for (let i = 0; i < sponsorTimes.length; i++) {
if (sponsorTimes[i][1] - sponsorTimes[i][0] < Config.config.minDuration) {
let confirmShort = chrome.i18n.getMessage("shortCheck") + "\n\n" + getSponsorTimesMessage(sponsorTimes);
if(!confirm(confirmShort)) return;
}
}
}
let confirmMessage = chrome.i18n.getMessage("submitCheck") + "\n\n" + getSponsorTimesMessage(sponsorTimes)
+ "\n\n" + chrome.i18n.getMessage("confirmMSG") + "\n\n" + chrome.i18n.getMessage("guildlinesSummary");
if(!confirm(confirmMessage)) return;

View file

@ -73,6 +73,24 @@ async function init() {
break;
case "display":
updateDisplayElement(<HTMLElement> optionsElements[i])
break;
case "number-change":
let numberChangeOption = optionsElements[i].getAttribute("sync-option");
let configValue = Config.config[numberChangeOption];
let numberInput = optionsElements[i].querySelector("input");
if (isNaN(configValue) || configValue < 0) {
numberInput.value = Config.defaults[numberChangeOption];
} else {
numberInput.value = configValue;
}
numberInput.addEventListener("input", () => {
Config.config[numberChangeOption] = numberInput.value;
});
break;
}
}
@ -293,4 +311,4 @@ function activateTextChange(element: HTMLElement) {
});
element.querySelector(".option-hidden-section").classList.remove("hidden");
}
}