Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple mode #180

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 108 additions & 9 deletions src/entry-points/popup/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ along with Jump Cutter Browser Extension. If not, see <https://www.gnu.org/lice
| 'popupChartJumpPeriod'
| 'dontAttachToCrossOriginMedia'
| 'popupAlwaysShowOpenLocalFileLink'
| 'advancedMode'
| 'simpleSlider'
| 'onPlaybackRateChangeFromOtherScripts'
>
& ReturnType<Parameters<typeof createKeydownListener>[1]>
& Parameters<typeof changeAlgorithmAndMaybeRelatedSettings>[0]
Expand Down Expand Up @@ -400,6 +403,41 @@ 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(isOn: boolean) {
settingsKeysToSaveToStorage.add('advancedMode');
throttledSaveUnsavedSettingsToStorageAndTriggerCallbacks();

if (!isOn) {
updateSettingsLocalCopyAndStorage({
experimentalControllerType: ControllerKind_STRETCHING,
marginBefore: 0,
// However, it's not very nice to change this setting,
// because it can only be changed back from the options page.
silenceSpeedSpecificationMethod: 'relativeToSoundedSpeed',
})

// Set the settings according to the `simpleSlider`'s value.
onSimpleSliderInput();
}
}
function onSimpleSliderInput() {
settingsKeysToSaveToStorage.add('simpleSlider');
throttledSaveUnsavedSettingsToStorageAndTriggerCallbacks();

updateSettingsLocalCopyAndStorage({
// If you decide to change these values,
// remember to also update them in `defaultSettings.ts`.
// When adjusting the values, keep in mind that _each_ of them
// affects how much we skip, that is adjusting even just one of them
// would make the extension skip more,
// and adjusting all of them at the same time would make it skip
// even more. So, keep them within sane, moderate limits.
volumeThreshold: 0.001 + settings.simpleSlider * 0.00015,
silenceSpeedRaw: 1.5 + settings.simpleSlider * 0.020,
marginAfter: 0.03 + 0.0020 * (100 - settings.simpleSlider)
})
}
</script>

<svelte:window
Expand Down Expand Up @@ -438,6 +476,7 @@ along with Jump Cutter Browser Extension. If not, see <https://www.gnu.org/lice
}}
>⚙️</button>
<div class="others__wrapper">
{#if settings.advancedMode}
<!-- TODO work on accessibility for the volume indicator. https://atomiks.github.io/tippyjs/v6/accessibility. -->
<span
class="others__item"
Expand Down Expand Up @@ -465,6 +504,10 @@ along with Jump Cutter Browser Extension. If not, see <https://www.gnu.org/lice
style="width: 6rem;"
></meter>
</span>
{:else}
<div style="flex-grow: 1"></div>
{/if}
<!-- TODO in "simple mode" the toolip's content is cut clipped. -->
<!-- Why button? So the tooltip can be accessed with no pointer device. Any better ideas? -->
<button
type="button"
Expand Down Expand Up @@ -692,6 +735,30 @@ along with Jump Cutter Browser Extension. If not, see <https://www.gnu.org/lice
{/if}
</div>
</div>

{#if !settings.advancedMode}
<label
style="
margin-top: 1rem;
display: flex;
flex-direction: column;
"
>
<div style="display: flex; justify-content: space-between;">
<div>{getMessage("skipLess")}</div>
<div>{getMessage("skipMore")}</div>
</div>
<input
type="range"
min="0"
max="100"
bind:value={settings.simpleSlider}
on:input={onSimpleSliderInput}
/>
</label>
{/if}

{#if settings.advancedMode}
<label
use:tippy={{
content: () => getMessage('useExperimentalAlgorithmTooltip'),
Expand Down Expand Up @@ -761,6 +828,11 @@ along with Jump Cutter Browser Extension. If not, see <https://www.gnu.org/lice
theme: tippyThemeMyTippyAndPreLine,
}}
/>
{/if}
{#if (
settings.advancedMode
|| settings.onPlaybackRateChangeFromOtherScripts !== 'updateSoundedSpeed'
)}
<datalist id="sounded-speed-datalist">
<option>1</option>
</datalist>
Expand All @@ -776,6 +848,8 @@ along with Jump Cutter Browser Extension. If not, see <https://www.gnu.org/lice
theme: tippyThemeMyTippyAndPreLine,
}}
/>
{/if}
{#if settings.advancedMode}
<RangeSlider
label="⏩ {getMessage('silenceSpeed')} ({silenceSpeedLabelClarification})"
fractionalDigits={2}
Expand Down Expand Up @@ -818,16 +892,41 @@ along with Jump Cutter Browser Extension. If not, see <https://www.gnu.org/lice
theme: tippyThemeMyTippyAndPreLine,
}}
/>
{#if settings.popupAlwaysShowOpenLocalFileLink}
<!-- svelte-ignore a11y-missing-attribute --->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<a
class="capitalize-first-letter"
{...openLocalFileLinkProps}
on:click={onClickOpenLocalFileLink}
style="display: inline-block; margin-top: 1rem;"
>📂 {getMessage('openLocalFile')}</a>
{/if}
<div
style="
display: flex;
align-items: flex-end;
justify-content: space-between;
flex-wrap: wrap;
"
>
{#if settings.popupAlwaysShowOpenLocalFileLink}
<!-- svelte-ignore a11y-missing-attribute --->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<a
class="capitalize-first-letter"
{...openLocalFileLinkProps}
on:click={onClickOpenLocalFileLink}
style="margin-top: 1rem;"
>📂 {getMessage('openLocalFile')}</a>
{/if}
<label
style="
display: inline-flex;
align-items: center;
margin-top: 1rem;
"
>
<input
type="checkbox"
style="margin: 0px 0.5rem 0px 0px;"
bind:checked={settings.advancedMode}
on:change={e => onAdvancedModeChange(e.currentTarget.checked)}
/>
{getMessage("popupAdvancedMode")}
</label>
</div>
{/await}

<style>
Expand Down
23 changes: 18 additions & 5 deletions src/settings/defaultSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,28 @@ import { getGeckoLikelyMaxNonMutedPlaybackRate } from '@/helpers';
import { browserHasAudioDesyncBug } from '@/helpers/browserHasAudioDesyncBug';
import { isMobile } from '@/helpers/isMobile';

// Start with a below-middle value to let the user get a feel
// for how the extension behaves without being too disruptive,
// and then let them crank it up if they feel like it.
// The value of 50 should be optimal for most users (based on my feeling).
const simpleSliderDefaultVal = 33;

const ElementPlaybackControllerStretchingSpecificDefaults = {
volumeThreshold: 0.005,
// If you decide to change these values,
// remember to also update them in `popup/App.svelte`.
volumeThreshold: 0.001 + simpleSliderDefaultVal * 0.00015,
marginBefore: 0,
marginAfter: 0.100,
marginAfter: 0.03 + 0.0020 * (100 - simpleSliderDefaultVal),
} as const;

export const defaultSettings: Readonly<Settings> = {
volumeThreshold: ElementPlaybackControllerStretchingSpecificDefaults.volumeThreshold,
previousVolumeThreshold: 0.005,
previousVolumeThreshold: ElementPlaybackControllerStretchingSpecificDefaults.volumeThreshold,
silenceSpeedSpecificationMethod: 'relativeToSoundedSpeed',
silenceSpeedRaw: 2.5,
previousSilenceSpeedRaw: 2.5,
// If you decide to change these values,
// remember to also update them in `popup/App.svelte`.
silenceSpeedRaw: 1.5 + simpleSliderDefaultVal * 0.020,
previousSilenceSpeedRaw: 1.5 + simpleSliderDefaultVal * 0.020,
// 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 +260,7 @@ export const defaultSettings: Readonly<Settings> = {
enableDesyncCorrection: browserHasAudioDesyncBug,

onPlaybackRateChangeFromOtherScripts: 'updateSoundedSpeed',

advancedMode: false,
simpleSlider: simpleSliderDefaultVal,
};
3 changes: 3 additions & 0 deletions src/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ 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