Skip to content

Commit

Permalink
created simple mode
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSM100 committed Oct 21, 2024
1 parent 28912f7 commit 7be8b5c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 5 deletions.
53 changes: 53 additions & 0 deletions src/entry-points/popup/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ along with Jump Cutter Browser Extension. If not, see <https://www.gnu.org/lice
| 'popupChartJumpPeriod'
| 'dontAttachToCrossOriginMedia'
| 'popupAlwaysShowOpenLocalFileLink'
| 'advancedMode'
| 'simpleSlider'
>
& ReturnType<Parameters<typeof createKeydownListener>[1]>
& Parameters<typeof changeAlgorithmAndMaybeRelatedSettings>[0]
Expand Down Expand Up @@ -400,6 +402,24 @@ along with Jump Cutter Browser Extension. If not, see <https://www.gnu.org/lice
$: controllerTypeAlwaysSounded = latestTelemetryRecord?.controllerType === ControllerKind_ALWAYS_SOUNDED;
const displayNewBadgeOnExperimentalAlgorithm = new Date() < new Date('2024-09-30');
function onAdvancedModeChange() {
settingsKeysToSaveToStorage.add('advancedMode');
throttledSaveUnsavedSettingsToStorageAndTriggerCallbacks();
if (this.checked) {
settings.experimentalControllerType = ControllerKind_STRETCHING;
settings.marginBefore = 0;
}
}
function onSimpleSliderInput() {
settingsKeysToSaveToStorage.add('simpleSlider');
throttledSaveUnsavedSettingsToStorageAndTriggerCallbacks();
settings.volumeThreshold = settings.simpleSlider * 0.001;
settings.silenceSpeedRaw = settings.simpleSlider * 0.05 + 1;
settings.marginAfter = settings.simpleSlider * 0.01;
}
</script>

<svelte:window
Expand Down Expand Up @@ -437,6 +457,7 @@ along with Jump Cutter Browser Extension. If not, see <https://www.gnu.org/lice
theme: 'my-tippy',
}}
>⚙️</button>
{#if settings.advancedMode}
<div class="others__wrapper">
<!-- TODO work on accessibility for the volume indicator. https://atomiks.github.io/tippyjs/v6/accessibility. -->
<span
Expand Down Expand Up @@ -539,6 +560,7 @@ along with Jump Cutter Browser Extension. If not, see <https://www.gnu.org/lice
</div>
</button>
</div>
{/if}
<!-- TODO transitions? -->
<div
style={
Expand Down Expand Up @@ -692,6 +714,36 @@ along with Jump Cutter Browser Extension. If not, see <https://www.gnu.org/lice
{/if}
</div>
</div>

{#if !settings.advancedMode}
<div style="margin-bottom: 5px; margin-top: 5px;">
<input
type="range"
style="width: 100%;"
min="0"
max="100"
bind:value={settings.simpleSlider}
on:input={onSimpleSliderInput}
/>
<div style="display: flex; width: 100%">
<div style="width: 50%;">{getMessage("skipLess")}</div>
<div style="width: 50%; text-align: right;">{getMessage("skipMore")}</div>
</div>
</div>
{/if}

<div>
<label>
<input
type="checkbox"
bind:checked={settings.advancedMode}
on:change={onAdvancedModeChange}
/>
{getMessage("advancedMode")}
</label>
</div>

{#if settings.advancedMode}
<label
use:tippy={{
content: () => getMessage('useExperimentalAlgorithmTooltip'),
Expand Down Expand Up @@ -818,6 +870,7 @@ along with Jump Cutter Browser Extension. If not, see <https://www.gnu.org/lice
theme: tippyThemeMyTippyAndPreLine,
}}
/>
{/if}
{#if settings.popupAlwaysShowOpenLocalFileLink}
<!-- svelte-ignore a11y-missing-attribute --->
<!-- svelte-ignore a11y-no-static-element-interactions -->
Expand Down
16 changes: 11 additions & 5 deletions src/settings/defaultSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,20 @@ import { getGeckoLikelyMaxNonMutedPlaybackRate } from '@/helpers';
import { browserHasAudioDesyncBug } from '@/helpers/browserHasAudioDesyncBug';
import { isMobile } from '@/helpers/isMobile';

const simpleSliderDefault = 30;

const ElementPlaybackControllerStretchingSpecificDefaults = {
volumeThreshold: 0.005,
volumeThreshold: simpleSliderDefault * 0.001,
marginBefore: 0,
marginAfter: 0.100,
marginAfter: simpleSliderDefault * 0.01,
} as const;

export const defaultSettings: Readonly<Settings> = {
volumeThreshold: ElementPlaybackControllerStretchingSpecificDefaults.volumeThreshold,
previousVolumeThreshold: 0.005,
previousVolumeThreshold: simpleSliderDefault * 0.001,
silenceSpeedSpecificationMethod: 'relativeToSoundedSpeed',
silenceSpeedRaw: 2.5,
previousSilenceSpeedRaw: 2.5,
silenceSpeedRaw: simpleSliderDefault * 0.05 + 1,
previousSilenceSpeedRaw: simpleSliderDefault * 0.05 + 1,
// Argument for `soundedSpeed !== 1`:
// * It reminds the user that the extension is enabled, so he's not confused by media getting seeked seemingly
// randomly.
Expand Down Expand Up @@ -250,4 +252,8 @@ export const defaultSettings: Readonly<Settings> = {
enableDesyncCorrection: browserHasAudioDesyncBug,

onPlaybackRateChangeFromOtherScripts: 'updateSoundedSpeed',

advancedMode: false,

simpleSlider: simpleSliderDefault,
};
4 changes: 4 additions & 0 deletions src/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ export interface Settings {
onPlaybackRateChangeFromOtherScripts: 'prevent' | 'updateSoundedSpeed' | 'doNothing',

__lastHandledUpdateToVersion?: `${number}.${number}.${number}`,

advancedMode: boolean,

simpleSlider: number,
}

// https://developer.chrome.com/apps/storage#property-onChanged-changes
Expand Down

0 comments on commit 7be8b5c

Please sign in to comment.