diff --git a/src/completions/History.ts b/src/completions/History.ts index 5180771e..ce7a247a 100644 --- a/src/completions/History.ts +++ b/src/completions/History.ts @@ -115,7 +115,7 @@ export class HistoryCompletionSource extends Completions.CompletionSourceFuse { // Search history, dedupe and sort by frecency let history = await browserBg.history.search({ text: query, - maxResults: Number(config.get("historyresults")), + maxResults: config.get("historyresults"), startTime: 0, }) diff --git a/src/content/scrolling.ts b/src/content/scrolling.ts index 7ac6fa01..5a40705d 100644 --- a/src/content/scrolling.ts +++ b/src/content/scrolling.ts @@ -17,14 +17,14 @@ async function getSmooth() { async function getDuration() { if (opts.duration === null) opts.duration = await config.getAsync("scrollduration") - return Number.parseInt(opts.duration) + return opts.duration } browser.storage.onChanged.addListener(changes => { if ("userconfig" in changes) { if ("smoothscroll" in changes.userconfig.newValue) opts.smooth = changes.userconfig.newValue["smoothscroll"] if ("scrollduration" in changes.userconfig.newValue) - opts.duration = Number.parseInt(changes.userconfig.newValue["scrollduration"]) + opts.duration = changes.userconfig.newValue["scrollduration"] } }) @@ -65,7 +65,7 @@ class ScrollingData { if (elapsed >= this.duration || this.elem[this.pos] == this.endPos) return this.endPos - let result = (this.endPos - this.startPos) * elapsed / this.duration + let result = ((this.endPos - this.startPos) * elapsed) / this.duration if (result >= 1 || result <= -1) return this.startPos + result return this.elem[this.pos] + (this.startPos < this.endPos ? 1 : -1) } diff --git a/src/excmds.ts b/src/excmds.ts index 310fb125..87b56149 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -758,7 +758,7 @@ export function addJump(scrollEvent: UIEvent) { list.push({ x: pageX, y: pageY }) jumps.cur = jumps.list.length - 1 saveJumps(alljumps) - }, Number.parseInt(config.get("jumpdelay"))) + }, config.get("jumpdelay")) }) } diff --git a/src/lib/config.ts b/src/lib/config.ts index 56791e7b..92bfb9c6 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -63,7 +63,7 @@ class default_config { /** * Internal field to handle site-specific config priorities. Use :seturl/:unseturl to change this value. */ - priority = "0" + priority = 0 // Note to developers: When creating new maps, make sure to make the modifier uppercase (e.g. instead of ) otherwise some commands might not be able to find them (e.g. `bind `) @@ -548,7 +548,7 @@ class default_config { * * The point of this is to prevent accidental execution of normal mode binds due to people typing more than is necessary to choose a hint. */ - hintdelay = "300" + hintdelay = 300 /** * Controls whether the page can focus elements for you via js @@ -572,7 +572,7 @@ class default_config { /** * How viscous you want smooth scrolling to feel. */ - scrollduration = "100" + scrollduration = 100 /** * Where to open tabs opened with `tabopen` - to the right of the current tab, or at the end of the tabs. @@ -590,15 +590,15 @@ class default_config { /** * Controls text-to-speech volume. Has to be a number between 0 and 1. */ - ttsvolume = "1" + ttsvolume = 1 /** * Controls text-to-speech speed. Has to be a number between 0.1 and 10. */ - ttsrate = "1" + ttsrate = 1 /** * Controls text-to-speech pitch. Has to be between 0 and 2. */ - ttspitch = "1" + ttspitch = 1 /** * If nextinput, after gi brings selects the next input @@ -627,7 +627,7 @@ class default_config { /** * Milliseconds before registering a scroll in the jumplist */ - jumpdelay = "3000" + jumpdelay = 3000 /** * Logging levels. Unless you're debugging Tridactyl, it's unlikely you'll ever need to change these. @@ -713,7 +713,7 @@ class default_config { /** * Number of most recent results to ask Firefox for. We display the top 20 or so most frequently visited ones. */ - historyresults = "50" + historyresults = 50 /** * Change this to "clobber" to ruin the "Content Security Policy" of all sites a bit and make Tridactyl run a bit better on some of them, e.g. raw.github* @@ -807,8 +807,8 @@ export function getURL(url, target) { // Sort them from highest to lowest priority, default to a priority of 10 .sort( (k1, k2) => - (Number(USERCONFIG.subconfigs[k2].priority) || 10) - - (Number(USERCONFIG.subconfigs[k1].priority) || 10), + (USERCONFIG.subconfigs[k2].priority || 10) - + (USERCONFIG.subconfigs[k1].priority || 10), ) // Get the first config name that has `target` .find(k => getDeepProperty(USERCONFIG.subconfigs[k], target)) @@ -1004,6 +1004,35 @@ export async function update() { }) set("configversion", "1.3") }, + "1.3": () => { + // Updates a value both in the main config and in sub (=site specific) configs + let updateAll = (setting: any[], fn: (any) => any) => { + let val = getDeepProperty(USERCONFIG, setting) + if (val) { + set(...setting, fn(val)) + } + let subconfigs = getDeepProperty(USERCONFIG, ["subconfigs"]) + if (subconfigs) { + Object.keys(subconfigs) + .map(pattern => [pattern, getURL(pattern, setting)]) + .filter(([pattern, value]) => value) + .forEach(([pattern, value]) => + setURL(pattern, ...setting, fn(value)), + ) + } + } + ;[ + "priority", + "hintdelay", + "scrollduration", + "ttsvolume", + "ttsrate", + "ttspitch", + "jumpdelay", + "historyresults", + ].forEach(setting => updateAll([setting], parseInt)) + set("configversion", "1.4") + }, } if (!get("configversion")) set("configversion", "0.0") const updatetest = v => { diff --git a/src/lib/text_to_speech.ts b/src/lib/text_to_speech.ts index a38d3c25..f13c95c6 100644 --- a/src/lib/text_to_speech.ts +++ b/src/lib/text_to_speech.ts @@ -27,10 +27,10 @@ export function readText(text: string): void { let utterance = new SpeechSynthesisUtterance(text) - let pitch = Number.parseFloat(Config.get("ttspitch")) + let pitch = Config.get("ttspitch") let voice = Config.get("ttsvoice") - let volume = Number.parseFloat(Config.get("ttsvolume")) - let rate = Number.parseFloat(Config.get("ttsrate")) + let volume = Config.get("ttsvolume") + let rate = Config.get("ttsrate") if (pitch >= 0 && pitch < 2) utterance.pitch = pitch