Merge pull request #298 from ajayyy/experimental

Options Improvements
This commit is contained in:
Ajay Ramachandran
2020-03-10 23:24:36 -04:00
committed by GitHub
6 changed files with 126 additions and 13 deletions

View File

@@ -68,11 +68,11 @@ jobs:
with:
args: builds/ChromeExtension.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Upload to release
uses: Shopify/upload-to-release@master
with:
args: builds/FirefoxExtension.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
repo-token: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -1,7 +1,7 @@
{
"name": "__MSG_fullName__",
"short_name": "__MSG_Name__",
"version": "1.2.21",
"version": "1.2.22",
"default_locale": "en",
"description": "__MSG_Description__",
"content_scripts": [{

View File

@@ -425,5 +425,20 @@
},
"mobileUpdateInfo": {
"message": "m.youtube.com is now supported"
},
"exportOptions": {
"message": "Import/Export All Options"
},
"whatExportOptions": {
"message": "This is your entire configuration in JSON. This includes your userID, so be sure to share this wisely."
},
"setOptions": {
"message": "Set Options"
},
"exportOptionsWarning": {
"message": "Warning: Changing the options is permanent and can break your install. Are you sure you would like to do this? Make sure to backup your old one just in case."
},
"incorrectlyFormattedOptions": {
"message": "This JSON is not formatted correctly. Your options have not been changed."
}
}

View File

@@ -305,6 +305,32 @@
</div>
</div>
<br/>
<br/>
<div option-type="private-text-change" sync-option="*" confirm-message="exportOptionsWarning">
<div class="option-button trigger-button">
__MSG_exportOptions__
</div>
<br/>
<div class="small-description">__MSG_whatExportOptions__</div>
<div class="option-hidden-section hidden">
<br/>
<input class="option-text-box" type="text">
<br/>
<br/>
<div class="option-button text-change-set">
__MSG_setOptions__
</div>
</div>
</div>
<br/>
<br/>

View File

@@ -45,7 +45,12 @@ var lastPreviewBarUpdate;
var durationListenerSetUp = false;
// Is the video currently being switched
var switchingVideos = false;
var switchingVideos = null;
// Used by the play and playing listeners to make sure two aren't
// called at the same time
var lastCheckTime = 0;
var lastCheckVideoTime = -1;
//the channel this video is about
var channelURL;
@@ -238,6 +243,9 @@ document.onkeydown = function(e: KeyboardEvent){
}
function resetValues() {
lastCheckTime = 0;
lastCheckVideoTime = -1;
//reset sponsor times
sponsorTimes = null;
UUIDs = [];
@@ -250,6 +258,8 @@ function resetValues() {
//reset sponsor data found check
sponsorDataFound = false;
switchingVideos = true;
}
async function videoIDChange(id) {
@@ -264,8 +274,6 @@ async function videoIDChange(id) {
//id is not valid
if (!id) return;
switchingVideos = true;
// Wait for options to be ready
await utils.wait(() => Config.config !== null, 5000, 1);
@@ -501,9 +509,24 @@ function sponsorsLookup(id: string, channelIDPromise?) {
video.addEventListener('play', () => {
switchingVideos = false;
startSponsorSchedule();
// Make sure it doesn't get double called with the playing event
if (lastCheckVideoTime !== video.currentTime && Date.now() - lastCheckTime > 2000) {
lastCheckTime = Date.now();
lastCheckVideoTime = video.currentTime;
startSponsorSchedule();
}
});
video.addEventListener('playing', () => {
// Make sure it doesn't get double called with the play event
if (lastCheckVideoTime !== video.currentTime && Date.now() - lastCheckTime > 2000) {
lastCheckTime = Date.now();
lastCheckVideoTime = video.currentTime;
startSponsorSchedule();
}
});
video.addEventListener('playing', () => startSponsorSchedule());
video.addEventListener('seeked', () => {
if (!video.paused) startSponsorSchedule();
});

View File

@@ -74,7 +74,7 @@ async function init() {
textChangeInput.value = Config.config[textChangeOption];
textChangeSetButton.addEventListener("click", () => {
textChangeSetButton.addEventListener("click", async () => {
// See if anything extra must be done
switch (textChangeOption) {
case "serverAddress":
@@ -86,6 +86,18 @@ async function init() {
return;
}
// Permission needed on Firefox
if (utils.isFirefox()) {
let permissionSuccess = await new Promise((resolve, reject) => {
chrome.permissions.request({
origins: [textChangeInput.value + "/"],
permissions: []
}, resolve);
});
if (!permissionSuccess) return;
}
break;
}
@@ -261,6 +273,8 @@ function invidiousOnClick(checkbox: HTMLInputElement, option: string) {
if (!granted) {
Config.config[option] = false;
checkbox.checked = false;
} else {
checkbox.checked = true;
}
});
} else {
@@ -347,15 +361,50 @@ function activatePrivateTextChange(element: HTMLElement) {
element.querySelector(".option-hidden-section").classList.remove("hidden");
return;
}
textBox.value = Config.config[option];
let result = Config.config[option];
// See if anything extra must be done
switch (option) {
case "*":
result = JSON.stringify(Config.localConfig);
break;
}
textBox.value = result;
let setButton = element.querySelector(".text-change-set");
setButton.addEventListener("click", () => {
let confirmMessage = element.getAttribute("confirm-message");
if (confirmMessage === null || confirm(chrome.i18n.getMessage(confirmMessage))) {
Config.config[option] = textBox.value;
// See if anything extra must be done
switch (option) {
case "*":
try {
let newConfig = JSON.parse(textBox.value);
for (const key in newConfig) {
Config.config[key] = newConfig[key];
}
init();
if (newConfig.supportInvidious) {
let checkbox = <HTMLInputElement> document.querySelector("#support-invidious > label > label > input");
checkbox.checked = true;
invidiousOnClick(checkbox, "supportInvidious");
}
} catch (e) {
alert(chrome.i18n.getMessage("incorrectlyFormattedOptions"));
}
break;
default:
Config.config[option] = textBox.value;
}
}
});
@@ -383,4 +432,4 @@ function validateServerAddress(input: string): string {
}
return input;
}
}