SponsorBlock categories (#634)
* SponsorBlock categories * perf * remove todo * tweak * UI is working * Lint fix * changelog * Bug fix * Restore timer * Locale * Comment * tweaks * web app * remove unsued svelte ignore * lint web app --------- Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
1 parent
0bc5ab6117
commit
fcae05a0da
34 files changed
+1039
-422
No files matched your search
@@ -11,6 +11,7 @@
|
||||
playletStateStore,
|
||||
preferencesModelStore,
|
||||
searchHistoryStore,
|
||||
sponsorBlockConfigStore,
|
||||
userPreferencesStore,
|
||||
} from "lib/Stores";
|
||||
import BottomNavigation from "lib/BottomNavigation.svelte";
|
||||
@@ -38,6 +39,10 @@
|
||||
homeLayoutFileStore.set(value);
|
||||
});
|
||||
|
||||
PlayletApi.getSponsorBlockConfigFile().then((value) => {
|
||||
sponsorBlockConfigStore.set(value);
|
||||
});
|
||||
|
||||
PlayletApi.getInvidiousVideoApiFile().then((apiDefinitions) => {
|
||||
invidiousVideoApiStore.set(apiDefinitions);
|
||||
});
|
||||
|
||||
@@ -34,6 +34,11 @@ export class PlayletApi {
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
static async getSponsorBlockConfigFile() {
|
||||
const response = await fetch(`${PlayletApi.host()}/config/sponsorblock_config.json5`);
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
static async getInvidiousVideoApiFile() {
|
||||
const response = await fetch(`${PlayletApi.host()}/config/invidious_video_api.yaml`);
|
||||
return await response.json();
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
const textSizes = ["text-2xl", "text-lg", "text-base", "text-sm", "text-xs"];
|
||||
|
||||
export let displayText: string = "";
|
||||
// svelte-ignore unused-export-let
|
||||
export let key: string = "";
|
||||
export let description: string = "";
|
||||
export let level: number = 0;
|
||||
@@ -92,7 +91,7 @@
|
||||
<div class={textSizes[level]}>{$translate(displayText)}</div>
|
||||
<div class="text-xs text-gray-500">{@html $translate(description)}</div>
|
||||
<button class="btn m-1" on:click={openHomeScreenEditor}
|
||||
>{$translate("Edit home screen")}</button
|
||||
>{$translate(displayText)}</button
|
||||
>
|
||||
</div>
|
||||
|
||||
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
sponsorBlockConfigStore,
|
||||
translate,
|
||||
userPreferencesStore,
|
||||
} from "lib/Stores";
|
||||
import { PlayletApi } from "lib/Api/PlayletApi";
|
||||
|
||||
const textSizes = ["text-2xl", "text-lg", "text-base", "text-sm", "text-xs"];
|
||||
|
||||
const optionTitles = {
|
||||
disable: "Disable",
|
||||
auto_skip: "Auto Skip",
|
||||
manual_skip: "Manual Skip",
|
||||
show_in_seekbar: "Show in Seekbar",
|
||||
};
|
||||
|
||||
export let displayText: string = "";
|
||||
export let key: string = "";
|
||||
export let description: string = "";
|
||||
export let level: number = 0;
|
||||
|
||||
let value;
|
||||
let originalValue;
|
||||
userPreferencesStore.subscribe((userPreferences) => {
|
||||
originalValue = userPreferences[key];
|
||||
});
|
||||
|
||||
let sponsorBlockConfig;
|
||||
sponsorBlockConfigStore.subscribe((config) => {
|
||||
sponsorBlockConfig = config;
|
||||
});
|
||||
|
||||
let modal;
|
||||
|
||||
async function openEditor() {
|
||||
value = JSON.parse(JSON.stringify(originalValue));
|
||||
modal.showModal();
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (key !== "" && value) {
|
||||
await PlayletApi.saveUserPreference(key, value);
|
||||
const userPreferences = await PlayletApi.getUserPreferences();
|
||||
userPreferencesStore.set(userPreferences);
|
||||
}
|
||||
}
|
||||
|
||||
export function close() {
|
||||
modal.close();
|
||||
}
|
||||
|
||||
function onClose() {
|
||||
// Reset value to original value to avoid weird animation on show
|
||||
value = JSON.parse(JSON.stringify(originalValue));
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="m-5">
|
||||
<div class={textSizes[level]}>{$translate(displayText)}</div>
|
||||
<div class="text-xs text-gray-500">{@html $translate(description)}</div>
|
||||
<button class="btn m-1" on:click={openEditor}
|
||||
>{$translate(displayText)}</button
|
||||
>
|
||||
</div>
|
||||
|
||||
<dialog bind:this={modal} class="modal" on:close={onClose}>
|
||||
<div class="modal-box bg-base-100">
|
||||
{#if value && sponsorBlockConfig}
|
||||
<table class="w-full">
|
||||
<tbody>
|
||||
{#each sponsorBlockConfig.categoryList as category}
|
||||
{#if value[category]}
|
||||
<tr>
|
||||
<td>
|
||||
<div
|
||||
style="
|
||||
width: 32px;
|
||||
height: 24px;
|
||||
border-radius: 2px;
|
||||
background: {sponsorBlockConfig.categories[category]
|
||||
.color};
|
||||
border: 1px solid #ccc;
|
||||
display: inline-block;
|
||||
"
|
||||
></div>
|
||||
</td>
|
||||
<td>
|
||||
<div>
|
||||
{$translate(sponsorBlockConfig.categories[category].title)}
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div>
|
||||
<select
|
||||
bind:value={value[category].option}
|
||||
class="select select-bordered select-sm"
|
||||
>
|
||||
{#each sponsorBlockConfig.categories[category].options as option}
|
||||
<option value={option}
|
||||
>{$translate(optionTitles[option])}</option
|
||||
>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{/if}
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
<form method="dialog" class="flex justify-center space-x-2 m-2">
|
||||
<button class="btn btn-primary" on:click={save}
|
||||
>{$translate("Save")}</button
|
||||
>
|
||||
<button class="btn btn-primary">{$translate("Close")}</button>
|
||||
</form>
|
||||
{/if}
|
||||
</div>
|
||||
<form method="dialog" class="modal-backdrop">
|
||||
<button>{$translate("Close")}</button>
|
||||
</form>
|
||||
</dialog>
|
||||
@@ -8,6 +8,7 @@
|
||||
import NumberControl from "./SettingControls/NumberControl.svelte";
|
||||
import ClearCacheControl from "./SettingControls/ClearCacheControl.svelte";
|
||||
import EditQualityControl from "./SettingControls/EditQualityControl.svelte";
|
||||
import SponsorBlockCategoriesControl from "./SettingControls/SponsorBlockCategoriesControl.svelte";
|
||||
import { translate } from "lib/Stores";
|
||||
|
||||
const textSizes = ["text-2xl", "text-lg", "text-base", "text-sm", "text-xs"];
|
||||
@@ -36,6 +37,7 @@
|
||||
EditHomeScreenControl,
|
||||
PlayletLibVersionControl,
|
||||
EditQualityControl,
|
||||
SponsorBlockCategoriesControl,
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ export const homeLayoutStore = writable([] as any);
|
||||
|
||||
export const homeLayoutFileStore = writable([] as any);
|
||||
|
||||
export const sponsorBlockConfigStore = writable({} as any);
|
||||
|
||||
export const bookmarksStore = writable([] as any);
|
||||
|
||||
export const searchHistoryStore = writable([] as any);
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
// svelte-ignore unused-export-let
|
||||
export let type: string = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let authorId: string = undefined;
|
||||
// svelte-ignore unused-export-let
|
||||
export let authorUrl: string = undefined;
|
||||
|
||||
Reference in new issue
Block a user