-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split the script into different files
- Loading branch information
Showing
31 changed files
with
789 additions
and
761 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './update'; | ||
export * from './save'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const save = (cfg: DeepReadonly<ScriptCfg>) => { | ||
const cfgCopy = { ...cfg }; | ||
const channelsCfgCopy = { ...cfg.channels }; | ||
outer: for (const key in channelsCfgCopy) { | ||
const channelCfg = channelsCfgCopy[key]; | ||
if (channelCfg.subtitles) continue; | ||
for (const cfgKey in channelCfg) if (cfgKey !== 'subtitles') continue outer; | ||
delete channelsCfgCopy[key]; | ||
} | ||
cfgCopy.channels = channelsCfgCopy; | ||
|
||
localStorage[STORAGE_NAME] = JSON.stringify(cfgCopy); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* @returns if the cfg was updated | ||
*/ | ||
export const update = (cfg: ScriptCfg) => { | ||
const doUpdate = cfg._v !== STORAGE_VERSION; | ||
if (doUpdate) { | ||
switch (cfg._v) { | ||
case 2: | ||
cfg.flags.standardMusicSpeed = false; | ||
cfg._v = 3; | ||
case 3: | ||
cfg.global.quality = (cfg.global as any).qualityMax; | ||
delete (cfg.global as any).qualityMax; | ||
for (const key in cfg.channels) { | ||
const currCfg = cfg.channels[key]; | ||
currCfg.quality = (currCfg as any).qualityMax; | ||
delete (currCfg as any).qualityMax; | ||
} | ||
cfg._v = STORAGE_VERSION; | ||
} | ||
} | ||
return doUpdate; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
declare const STORAGE_NAME: 'YTDefaulter', | ||
STORAGE_VERSION: 4, | ||
SECTION_GLOBAL: 'global', | ||
SECTION_LOCAL: 'thisChannel', | ||
PREFIX: 'YTDef-', | ||
MENU_ID: 'YTDef-menu', | ||
BTN_ID: 'YTDef-btn', | ||
SETTING_HINT_CLASS: 'YTDef-setting-hint', | ||
SUBTITLES: 'subtitles', | ||
SPEED: 'speed', | ||
CUSTOM_SPEED: 'customSpeed', | ||
QUALITY: 'quality', | ||
VOLUME: 'volume'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { getElCreator } from './utils/getElCreator'; | ||
|
||
export const div = getElCreator('div'); | ||
export const input = getElCreator('input'); | ||
export const checkbox = <T extends Props<HTMLInputElement>>( | ||
props?: DeepReadonly<T> | ||
) => input({ type: 'checkbox', ...props }); | ||
export const option = getElCreator('option'); | ||
const _label = getElCreator('label'); | ||
export const labelEl = <T extends Props<HTMLLabelElement>>( | ||
forId: string, | ||
props?: DeepReadonly<T> | ||
) => { | ||
const elem = _label(props); | ||
elem.setAttribute('for', forId); | ||
return elem; | ||
}; | ||
export const selectEl = getElCreator('select'); | ||
export const btnClass = 'yt-spec-button-shape-next'; | ||
const btnClassFocused = btnClass + '--focused'; | ||
const _button = getElCreator('button'); | ||
export const button = <T extends Props<HTMLButtonElement>>( | ||
textContent: string, | ||
props?: DeepReadonly<T> | ||
) => | ||
_button({ | ||
textContent, | ||
className: `${btnClass} ${btnClass}--tonal ${btnClass}--mono ${btnClass}--size-m`, | ||
onfocus(this: HTMLButtonElement) { | ||
this.classList.add(btnClassFocused); | ||
}, | ||
onblur(this: HTMLButtonElement) { | ||
this.classList.remove(btnClassFocused); | ||
}, | ||
...props, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { div } from './elements-creators'; | ||
|
||
export class Hint { | ||
constructor(prefix: string, props?: DeepReadonly<Props<HTMLDivElement>>) { | ||
this.element = div(props); | ||
this.element.className ||= SETTING_HINT_CLASS; | ||
this.prefix = prefix; | ||
this.hide(); | ||
} | ||
hide(): void { | ||
this.element.style.display = 'none'; | ||
} | ||
show(msg?: string): void { | ||
this.element.style.display = 'block'; | ||
if (msg) this.element.textContent = this.prefix + msg; | ||
} | ||
private prefix: string; | ||
element: HTMLDivElement; | ||
} |
Oops, something went wrong.