Skip to content

Commit

Permalink
Merge pull request #266 from ajayyy/experimental
Browse files Browse the repository at this point in the history
Options page improvements + Preview sponsors
  • Loading branch information
ajayyy authored Feb 9, 2020
2 parents 22cc517 + 00117bd commit c76d2c9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion manifest/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "__MSG_fullName__",
"short_name": "__MSG_Name__",
"version": "1.2.5",
"version": "1.2.6",
"default_locale": "en",
"description": "__MSG_Description__",
"content_scripts": [
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@
"message": "Reset"
},
"customAddressError": {
"message": "This address is not in the right form. Make sure you have http:// or https:// at the begining and no slashes or sub-folders at the end."
"message": "This address is not in the right form. Make sure you have http:// or https:// at the begining and no trailing slashes."
},
"areYouSureReset": {
"message": "Are you sure you would like to reset this?"
Expand Down
22 changes: 18 additions & 4 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,20 @@ function sponsorsLookup(id: string, channelIDPromise?) {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
sponsorDataFound = true;

sponsorTimes = JSON.parse(xmlhttp.responseText).sponsorTimes;
UUIDs = JSON.parse(xmlhttp.responseText).UUIDs;
let recievedSponsorTimes = JSON.parse(xmlhttp.responseText).sponsorTimes;
let recievedUUIDs = JSON.parse(xmlhttp.responseText).UUIDs;

// Check if any old submissions should be kept
for (let i = 0; i < UUIDs.length; i++) {
if (UUIDs[i] === null) {
// This is a user submission, keep it
recievedSponsorTimes.push(sponsorTimes[i]);
recievedUUIDs.push(UUIDs[i]);
}
}

sponsorTimes = recievedSponsorTimes;
UUIDs = recievedUUIDs;

// Remove all submissions smaller than the minimum duration
if (Config.config.minDuration !== 0) {
Expand Down Expand Up @@ -1091,10 +1103,12 @@ function sendSubmitMessage(){
Config.config.sponsorTimes.delete(currentVideoID);

//add submissions to current sponsors list
if (sponsorTimes === null) sponsorTimes = [];

sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting);
for (let i = 0; i < sponsorTimesSubmitting.length; i++) {
// Add some random IDs
UUIDs.push(utils.generateUserID());
// Add placeholder IDs
UUIDs.push(null);
}

// Empty the submitting times
Expand Down
23 changes: 16 additions & 7 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ async function init() {
switch (option) {
case "supportInvidious":
invidiousOnClick(checkbox, option);
break;
case "disableAutoSkip":
if (!checkbox.checked) {
// Enable the notice
Config.config["dontShowNotice"] = false;

let showNoticeSwitch = <HTMLInputElement> document.querySelector("[sync-option='dontShowNotice'] > label > label > input");
showNoticeSwitch.checked = true;
}

break;
}
});
Expand Down Expand Up @@ -357,14 +367,13 @@ function activatePrivateTextChange(element: HTMLElement) {
* @param input Input server address
*/
function validateServerAddress(input: string): string {
// Trim the last slash if needed
if (input.endsWith("/")) {
input = input.substring(0, input.length - 1);
}
input = input.trim();

// Trim the trailing slashes
input = input.replace(/\/+$/, "");

// Isn't HTTP protocol or has extra slashes
if ((!input.startsWith("https://") && !input.startsWith("http://"))
|| input.replace("://", "").includes("/")) {
// If it isn't HTTP protocol
if ((!input.startsWith("https://") && !input.startsWith("http://"))) {

alert(chrome.i18n.getMessage("customAddressError"));

Expand Down

0 comments on commit c76d2c9

Please sign in to comment.