mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 09:31:41 -05:00
Merge pull request #1452 from tridactyl/tslint_rules_reactivation2
TSLint: re-enable prefer-const rule
This commit is contained in:
commit
0a50f84c53
54 changed files with 496 additions and 503 deletions
|
@ -4,8 +4,6 @@ export class StringType implements Type {
|
|||
public static instance = new StringType()
|
||||
public kind = "string"
|
||||
|
||||
constructor() {}
|
||||
|
||||
public toConstructor() {
|
||||
return "StringType.instance"
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@ export class VoidType implements Type {
|
|||
public static instance = new VoidType()
|
||||
public kind = "void"
|
||||
|
||||
constructor() {}
|
||||
|
||||
public toConstructor() {
|
||||
return "VoidType.instance"
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ browser.tabs.query({ currentWindow: true, active: true }).then(t => {
|
|||
// After that, on every tab change, update the current url
|
||||
let contentLocationCount = 0
|
||||
browser.tabs.onActivated.addListener(ev => {
|
||||
let myId = contentLocationCount + 1
|
||||
const myId = contentLocationCount + 1
|
||||
contentLocationCount = myId
|
||||
browser.tabs.get(ev.tabId).then(t => {
|
||||
// Note: we're using contentLocationCount and myId in order to make sure that only the last onActivated event is used in order to set contentLocation
|
||||
|
@ -85,17 +85,17 @@ config.addChangeListener("csp", (old, cur) => {
|
|||
// }}}
|
||||
|
||||
// Prevent Tridactyl from being updated while it is running in the hope of fixing #290
|
||||
browser.runtime.onUpdateAvailable.addListener(_ => {})
|
||||
browser.runtime.onUpdateAvailable.addListener(_ => undefined)
|
||||
|
||||
browser.runtime.onStartup.addListener(_ => {
|
||||
config.getAsync("autocmds", "TriStart").then(aucmds => {
|
||||
let hosts = Object.keys(aucmds)
|
||||
const hosts = Object.keys(aucmds)
|
||||
// If there's only one rule and it's "all", no need to check the hostname
|
||||
if (hosts.length === 1 && hosts[0] === ".*") {
|
||||
BackgroundController.acceptExCmd(aucmds[hosts[0]])
|
||||
} else {
|
||||
native.run("hostname").then(hostname => {
|
||||
for (let host of hosts) {
|
||||
for (const host of hosts) {
|
||||
if (hostname.content.match(host)) {
|
||||
BackgroundController.acceptExCmd(aucmds[host])
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ config.getAsync("updatenag").then(nag => {
|
|||
// {{{ AUTOCOMMANDS
|
||||
let curTab = null
|
||||
browser.tabs.onActivated.addListener(ev => {
|
||||
let ignore = _ => _
|
||||
const ignore = _ => _
|
||||
if (curTab !== null) {
|
||||
// messaging.messageTab failing can happen when leaving privileged tabs (e.g. about:addons)
|
||||
messaging
|
||||
|
@ -133,7 +133,7 @@ browser.tabs.onActivated.addListener(ev => {
|
|||
|
||||
// {{{ AUTOCONTAINERS
|
||||
|
||||
let aucon = new AutoContain()
|
||||
const aucon = new AutoContain()
|
||||
|
||||
// Handle cancelled requests as a result of autocontain.
|
||||
browser.webRequest.onCompleted.addListener(
|
||||
|
|
|
@ -16,7 +16,7 @@ export async function source(filename = "auto") {
|
|||
}
|
||||
|
||||
export async function runRc(rc: string) {
|
||||
for (let cmd of rcFileToExCmds(rc)) {
|
||||
for (const cmd of rcFileToExCmds(rc)) {
|
||||
await Controller.acceptExCmd(cmd)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ export let last_ex_str = ""
|
|||
export async function acceptExCmd(exstr: string): Promise<any> {
|
||||
// TODO: Errors should go to CommandLine.
|
||||
try {
|
||||
let [func, args] = exmode_parser(exstr)
|
||||
const [func, args] = exmode_parser(exstr)
|
||||
// Stop the repeat excmd from recursing.
|
||||
if (func !== repeat) last_ex_str = exstr
|
||||
try {
|
||||
|
|
|
@ -48,7 +48,7 @@ export async function downloadUrl(url: string, saveAs: boolean) {
|
|||
urlToDownload = urlToSave.href
|
||||
}
|
||||
|
||||
let fileName = getDownloadFilenameForUrl(urlToSave)
|
||||
const fileName = getDownloadFilenameForUrl(urlToSave)
|
||||
|
||||
// Save location limitations:
|
||||
// - download() can't save outside the downloads dir without popping
|
||||
|
@ -57,7 +57,7 @@ export async function downloadUrl(url: string, saveAs: boolean) {
|
|||
// feed in the dirctory for next time, and FF doesn't remember it
|
||||
// itself (like it does if you right-click-save something)
|
||||
|
||||
let downloadPromise = browser.downloads.download({
|
||||
const downloadPromise = browser.downloads.download({
|
||||
url: urlToDownload,
|
||||
filename: fileName,
|
||||
saveAs,
|
||||
|
@ -92,9 +92,9 @@ export async function downloadUrlAs(url: string, saveAs: string) {
|
|||
urlToDownload = urlToSave.href
|
||||
}
|
||||
|
||||
let fileName = getDownloadFilenameForUrl(urlToSave)
|
||||
const fileName = getDownloadFilenameForUrl(urlToSave)
|
||||
|
||||
let downloadId = await browser.downloads.download({
|
||||
const downloadId = await browser.downloads.download({
|
||||
conflictAction: "uniquify",
|
||||
url: urlToDownload,
|
||||
filename: fileName,
|
||||
|
@ -102,7 +102,7 @@ export async function downloadUrlAs(url: string, saveAs: string) {
|
|||
|
||||
// We want to return a promise that will resolve once the file has been moved somewhere else
|
||||
return new Promise((resolve, reject) => {
|
||||
let onDownloadComplete = async downloadDelta => {
|
||||
const onDownloadComplete = async downloadDelta => {
|
||||
if (downloadDelta.id !== downloadId) {
|
||||
return
|
||||
}
|
||||
|
@ -113,11 +113,11 @@ export async function downloadUrlAs(url: string, saveAs: string) {
|
|||
downloadDelta.state.current !== "in_progress"
|
||||
) {
|
||||
browser.downloads.onChanged.removeListener(onDownloadComplete)
|
||||
let downloadItem = (await browser.downloads.search({
|
||||
const downloadItem = (await browser.downloads.search({
|
||||
id: downloadId,
|
||||
}))[0]
|
||||
if (downloadDelta.state.current === "complete") {
|
||||
let operation = await Native.move(
|
||||
const operation = await Native.move(
|
||||
downloadItem.filename,
|
||||
saveAs,
|
||||
)
|
||||
|
|
|
@ -16,12 +16,11 @@ export class Parser {
|
|||
let lastResult
|
||||
let consumedIndex = 0
|
||||
try {
|
||||
for (let val of input) {
|
||||
for (const val of input) {
|
||||
this.parser.feed(val)
|
||||
lastResult = this.parser.results[0]
|
||||
consumedIndex++
|
||||
}
|
||||
} catch (e) {
|
||||
} finally {
|
||||
this.reset()
|
||||
if (lastResult === undefined) {
|
||||
|
|
|
@ -51,9 +51,9 @@ const logger = new Logger("cmdline")
|
|||
/** @hidden **/
|
||||
let activeCompletions: Completions.CompletionSource[]
|
||||
/** @hidden **/
|
||||
let completionsDiv = window.document.getElementById("completions")
|
||||
const completionsDiv = window.document.getElementById("completions")
|
||||
/** @hidden **/
|
||||
let clInput = window.document.getElementById(
|
||||
const clInput = window.document.getElementById(
|
||||
"tridactyl-input",
|
||||
) as HTMLInputElement
|
||||
|
||||
|
@ -126,7 +126,7 @@ export function enableCompletions() {
|
|||
/* document.addEventListener("DOMContentLoaded", enableCompletions) */
|
||||
|
||||
/** @hidden **/
|
||||
let noblur = e => setTimeout(() => clInput.focus(), 0)
|
||||
const noblur = e => setTimeout(() => clInput.focus(), 0)
|
||||
|
||||
/** @hidden **/
|
||||
export function focus() {
|
||||
|
@ -141,7 +141,7 @@ let HISTORY_SEARCH_STRING: string
|
|||
/** @hidden
|
||||
* Command line keybindings
|
||||
**/
|
||||
let keyParser = keys => genericParser.parser("exmaps", keys)
|
||||
const keyParser = keys => genericParser.parser("exmaps", keys)
|
||||
/** @hidden **/
|
||||
let keyEvents = []
|
||||
/** @hidden **/
|
||||
|
@ -153,7 +153,7 @@ clInput.addEventListener(
|
|||
"keydown",
|
||||
function(keyevent: KeyboardEvent) {
|
||||
keyEvents.push(keyevent)
|
||||
let response = keyParser(keyEvents)
|
||||
const response = keyParser(keyEvents)
|
||||
if (response.isMatch) {
|
||||
keyevent.preventDefault()
|
||||
keyevent.stopImmediatePropagation()
|
||||
|
@ -182,9 +182,9 @@ clInput.addEventListener(
|
|||
* Insert the first command line history line that starts with the content of the command line in the command line.
|
||||
*/
|
||||
export function complete() {
|
||||
let fragment = clInput.value
|
||||
let matches = state.cmdHistory.filter(key => key.startsWith(fragment))
|
||||
let mostrecent = matches[matches.length - 1]
|
||||
const fragment = clInput.value
|
||||
const matches = state.cmdHistory.filter(key => key.startsWith(fragment))
|
||||
const mostrecent = matches[matches.length - 1]
|
||||
if (mostrecent !== undefined) clInput.value = mostrecent
|
||||
return refresh_completions(clInput.value)
|
||||
}
|
||||
|
@ -341,7 +341,7 @@ function history(n) {
|
|||
HISTORY_SEARCH_STRING = clInput.value
|
||||
}
|
||||
|
||||
let matches = state.cmdHistory.filter(key =>
|
||||
const matches = state.cmdHistory.filter(key =>
|
||||
key.startsWith(HISTORY_SEARCH_STRING),
|
||||
)
|
||||
if (cmdline_history_position === 0) {
|
||||
|
|
|
@ -41,7 +41,7 @@ export abstract class CompletionSource {
|
|||
private _prevState: OptionState
|
||||
|
||||
constructor(prefixes) {
|
||||
let commands = aliases.getCmdAliasMapping()
|
||||
const commands = aliases.getCmdAliasMapping()
|
||||
|
||||
// Now, for each prefix given as argument, add it to the completionsource's prefix list and also add any alias it has
|
||||
prefixes
|
||||
|
@ -235,13 +235,13 @@ export abstract class CompletionSourceFuse extends CompletionSource {
|
|||
|
||||
/** Rtn sorted array of {option, score} */
|
||||
scoredOptions(query: string, options = this.options): ScoredOption[] {
|
||||
let searchThis = this.options.map((elem, index) => {
|
||||
const searchThis = this.options.map((elem, index) => {
|
||||
return { index, fuseKeys: elem.fuseKeys }
|
||||
})
|
||||
this.fuse = new Fuse(searchThis, this.fuseOptions)
|
||||
return this.fuse.search(query).map(result => {
|
||||
// console.log(result, result.item, query)
|
||||
let index = toNumber(result.item)
|
||||
const index = toNumber(result.item)
|
||||
return {
|
||||
index,
|
||||
option: this.options[index],
|
||||
|
@ -256,7 +256,7 @@ export abstract class CompletionSourceFuse extends CompletionSource {
|
|||
focus the best match.
|
||||
*/
|
||||
setStateFromScore(scoredOpts: ScoredOption[], autoselect = false) {
|
||||
let matches = scoredOpts.map(res => res.index)
|
||||
const matches = scoredOpts.map(res => res.index)
|
||||
|
||||
for (const [index, option] of enumerate(this.options)) {
|
||||
if (matches.includes(index)) option.state = "normal"
|
||||
|
@ -297,12 +297,12 @@ export abstract class CompletionSourceFuse extends CompletionSource {
|
|||
|
||||
next(inc = 1) {
|
||||
if (this.state !== "hidden") {
|
||||
let visopts = this.options.filter(o => o.state !== "hidden")
|
||||
let currind = visopts.findIndex(o => o.state === "focused")
|
||||
const visopts = this.options.filter(o => o.state !== "hidden")
|
||||
const currind = visopts.findIndex(o => o.state === "focused")
|
||||
this.deselect()
|
||||
// visopts.length + 1 because we want an empty completion at the end
|
||||
let max = visopts.length + 1
|
||||
let opt = visopts[(currind + inc + max) % max]
|
||||
const max = visopts.length + 1
|
||||
const opt = visopts[(currind + inc + max) % max]
|
||||
if (opt) this.select(opt)
|
||||
return true
|
||||
} else return false
|
||||
|
|
|
@ -58,9 +58,9 @@ export class ExcmdCompletionSource extends Completions.CompletionSourceFuse {
|
|||
private async updateOptions(exstr = "") {
|
||||
this.lastExstr = exstr
|
||||
|
||||
let excmds = Metadata.everything.getFile("src/excmds.ts")
|
||||
const excmds = Metadata.everything.getFile("src/excmds.ts")
|
||||
if (!excmds) return
|
||||
let fns = excmds.getFunctions()
|
||||
const fns = excmds.getFunctions()
|
||||
|
||||
// Add all excmds that start with exstr and that tridactyl has metadata about to completions
|
||||
this.options = this.scoreOptions(
|
||||
|
@ -70,12 +70,12 @@ export class ExcmdCompletionSource extends Completions.CompletionSourceFuse {
|
|||
)
|
||||
|
||||
// Also add aliases to possible completions
|
||||
let exaliases = Object.keys(config.get("exaliases")).filter(a =>
|
||||
const exaliases = Object.keys(config.get("exaliases")).filter(a =>
|
||||
a.startsWith(exstr),
|
||||
)
|
||||
for (let alias of exaliases) {
|
||||
let cmd = aliases.expandExstr(alias)
|
||||
let fn = excmds.getFunction(cmd)
|
||||
for (const alias of exaliases) {
|
||||
const cmd = aliases.expandExstr(alias)
|
||||
const fn = excmds.getFunction(cmd)
|
||||
if (fn) {
|
||||
this.options.push(
|
||||
new ExcmdCompletionOption(
|
||||
|
|
|
@ -36,7 +36,7 @@ export class FindCompletionSource extends Completions.CompletionSourceFuse {
|
|||
}
|
||||
|
||||
async onInput(exstr) {
|
||||
let id = this.completionCount++
|
||||
const id = this.completionCount++
|
||||
// If there's already a promise being executed, wait for it to finish
|
||||
await this.prevCompletion
|
||||
// Since we might have awaited for this.prevCompletion, we don't have a guarantee we're the last completion the user asked for anymore
|
||||
|
@ -56,20 +56,20 @@ export class FindCompletionSource extends Completions.CompletionSourceFuse {
|
|||
if (!exstr) return
|
||||
|
||||
// Flag parsing because -? should reverse completions
|
||||
let tokens = exstr.split(" ")
|
||||
let flagpos = tokens.indexOf("-?")
|
||||
let reverse = flagpos >= 0
|
||||
const tokens = exstr.split(" ")
|
||||
const flagpos = tokens.indexOf("-?")
|
||||
const reverse = flagpos >= 0
|
||||
if (reverse) {
|
||||
tokens.splice(flagpos, 1)
|
||||
}
|
||||
|
||||
let query = tokens.slice(1).join(" ")
|
||||
let minincsearchlen = await config.getAsync("minincsearchlen")
|
||||
const query = tokens.slice(1).join(" ")
|
||||
const minincsearchlen = await config.getAsync("minincsearchlen")
|
||||
// No point if continuing if the user hasn't started searching yet
|
||||
if (query.length < minincsearchlen) return
|
||||
|
||||
let findresults = await config.getAsync("findresults")
|
||||
let incsearch = (await config.getAsync("incsearch")) === "true"
|
||||
const incsearch = (await config.getAsync("incsearch")) === "true"
|
||||
if (findresults === 0 && !incsearch) return
|
||||
|
||||
let incsearchonly = false
|
||||
|
@ -80,8 +80,8 @@ export class FindCompletionSource extends Completions.CompletionSourceFuse {
|
|||
|
||||
// Note: the use of activeTabId here might break completions if the user starts searching for a pattern in a really big page and then switches to another tab.
|
||||
// Getting the tabId should probably be done in the constructor but you can't have async constructors.
|
||||
let tabId = await activeTabId()
|
||||
let findings = await Messaging.messageTab(
|
||||
const tabId = await activeTabId()
|
||||
const findings = await Messaging.messageTab(
|
||||
tabId,
|
||||
"finding_content",
|
||||
"find",
|
||||
|
@ -91,8 +91,8 @@ export class FindCompletionSource extends Completions.CompletionSourceFuse {
|
|||
// If the search was successful
|
||||
if (findings.length > 0) {
|
||||
// Get match context
|
||||
let len = await config.getAsync("findcontextlen")
|
||||
let matches = await Messaging.messageTab(
|
||||
const len = await config.getAsync("findcontextlen")
|
||||
const matches = await Messaging.messageTab(
|
||||
tabId,
|
||||
"finding_content",
|
||||
"getMatches",
|
||||
|
|
|
@ -26,8 +26,8 @@ export class GuisetCompletionSource extends Completions.CompletionSourceFuse {
|
|||
|
||||
public async filter(exstr: string) {
|
||||
this.lastExstr = exstr
|
||||
let [prefix, query] = this.splitOnPrefix(exstr)
|
||||
let option = ""
|
||||
const [prefix, query] = this.splitOnPrefix(exstr)
|
||||
const option = ""
|
||||
|
||||
// Hide self and stop if prefixes don't match
|
||||
if (prefix) {
|
||||
|
@ -44,7 +44,7 @@ export class GuisetCompletionSource extends Completions.CompletionSourceFuse {
|
|||
let ruleName = ""
|
||||
let subRule = ""
|
||||
if (query) {
|
||||
let args = query.trim().split(" ")
|
||||
const args = query.trim().split(" ")
|
||||
ruleName = args[0] || ""
|
||||
subRule = args[1] || ""
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ export class HelpCompletionSource extends Completions.CompletionSourceFuse {
|
|||
public async filter(exstr: string) {
|
||||
this.lastExstr = exstr
|
||||
this.completion = undefined
|
||||
let [prefix, query] = this.splitOnPrefix(exstr)
|
||||
let options = ""
|
||||
const [prefix, query] = this.splitOnPrefix(exstr)
|
||||
const options = ""
|
||||
|
||||
// Hide self and stop if prefixes don't match
|
||||
if (prefix) {
|
||||
|
@ -45,13 +45,13 @@ export class HelpCompletionSource extends Completions.CompletionSourceFuse {
|
|||
return
|
||||
}
|
||||
|
||||
let file = Metadata.everything.getFile("src/lib/config.ts")
|
||||
let default_config = file.getClass("default_config")
|
||||
let excmds = Metadata.everything.getFile("src/excmds.ts")
|
||||
let fns = excmds.getFunctions()
|
||||
let settings = config.get()
|
||||
let exaliases = settings.exaliases
|
||||
let bindings = settings.nmaps
|
||||
const file = Metadata.everything.getFile("src/lib/config.ts")
|
||||
const default_config = file.getClass("default_config")
|
||||
const excmds = Metadata.everything.getFile("src/excmds.ts")
|
||||
const fns = excmds.getFunctions()
|
||||
const settings = config.get()
|
||||
const exaliases = settings.exaliases
|
||||
const bindings = settings.nmaps
|
||||
if (fns === undefined || exaliases === undefined || bindings === undefined) {
|
||||
return
|
||||
}
|
||||
|
@ -62,8 +62,8 @@ export class HelpCompletionSource extends Completions.CompletionSourceFuse {
|
|||
Object.keys(exaliases)
|
||||
.filter(alias => alias.startsWith(query))
|
||||
.map(alias => {
|
||||
let cmd = aliases.expandExstr(alias)
|
||||
let doc = (excmds.getFunction(cmd) || {} as any).doc || ""
|
||||
const cmd = aliases.expandExstr(alias)
|
||||
const doc = (excmds.getFunction(cmd) || {} as any).doc || ""
|
||||
return new HelpCompletionOption(
|
||||
alias,
|
||||
`Alias for \`${cmd}\`. ${doc}`,
|
||||
|
@ -107,7 +107,7 @@ export class HelpCompletionSource extends Completions.CompletionSourceFuse {
|
|||
Object.keys(settings)
|
||||
.filter(x => x.startsWith(query))
|
||||
.map(setting => {
|
||||
let member = default_config.getMember(setting)
|
||||
const member = default_config.getMember(setting)
|
||||
let doc = ""
|
||||
if (member !== undefined) {
|
||||
doc = member.doc
|
||||
|
|
|
@ -61,12 +61,12 @@ export class HistoryCompletionSource extends Completions.CompletionSourceFuse {
|
|||
// It's terrible but it's ok because it's just a stopgap until an actual commandline-parsing API is implemented
|
||||
if (prefix === "tabopen ") {
|
||||
if (query.startsWith("-c")) {
|
||||
let args = query.split(" ")
|
||||
const args = query.split(" ")
|
||||
options = args.slice(0, 2).join(" ")
|
||||
query = args.slice(2).join(" ")
|
||||
}
|
||||
if (query.startsWith("-b")) {
|
||||
let args = query.split(" ")
|
||||
const args = query.split(" ")
|
||||
options = args.slice(0, 1).join(" ")
|
||||
query = args.slice(1).join(" ")
|
||||
}
|
||||
|
|
|
@ -33,13 +33,13 @@ export class PreferenceCompletionSource extends Completions.CompletionSourceFuse
|
|||
this.state = "hidden"
|
||||
return
|
||||
}
|
||||
let pref = this.splitOnPrefix(exstr)[1]
|
||||
const pref = this.splitOnPrefix(exstr)[1]
|
||||
if (pref === undefined) {
|
||||
this.state = "hidden"
|
||||
return
|
||||
}
|
||||
this.lastExstr = exstr
|
||||
let preferences = await Native.getPrefs()
|
||||
const preferences = await Native.getPrefs()
|
||||
this.options = Object.keys(preferences)
|
||||
.filter(key => key.startsWith(pref))
|
||||
.map(key => new PreferenceCompletionOption(key, preferences[key]))
|
||||
|
|
|
@ -38,7 +38,7 @@ export class RssCompletionSource extends Completions.CompletionSourceFuse {
|
|||
|
||||
private async updateOptions(exstr = "") {
|
||||
this.lastExstr = exstr
|
||||
let [prefix] = this.splitOnPrefix(exstr)
|
||||
const [prefix] = this.splitOnPrefix(exstr)
|
||||
|
||||
// Hide self and stop if prefixes don't match
|
||||
if (prefix) {
|
||||
|
@ -57,7 +57,7 @@ export class RssCompletionSource extends Completions.CompletionSourceFuse {
|
|||
"getRssLinks",
|
||||
[],
|
||||
)).map(link => {
|
||||
let opt = new RssCompletionOption(
|
||||
const opt = new RssCompletionOption(
|
||||
link.url,
|
||||
link.title,
|
||||
link.type,
|
||||
|
|
|
@ -79,7 +79,7 @@ export class SessionsCompletionSource extends Completions.CompletionSourceFuse {
|
|||
|
||||
private async updateOptions(exstr = "") {
|
||||
this.lastExstr = exstr
|
||||
let [prefix] = this.splitOnPrefix(exstr)
|
||||
const [prefix] = this.splitOnPrefix(exstr)
|
||||
|
||||
// Hide self and stop if prefixes don't match
|
||||
if (prefix) {
|
||||
|
|
|
@ -54,16 +54,16 @@ export class SettingsCompletionSource extends Completions.CompletionSourceFuse {
|
|||
// It's terrible but it's ok because it's just a stopgap until an actual commandline-parsing API is implemented
|
||||
// copy pasting code is fun and good
|
||||
if (prefix === "seturl " || prefix === "unseturl ") {
|
||||
let args = query.split(" ")
|
||||
const args = query.split(" ")
|
||||
options = args.slice(0, 1).join(" ")
|
||||
query = args.slice(1).join(" ")
|
||||
}
|
||||
|
||||
options += options ? " " : ""
|
||||
|
||||
let file = metadata.everything.getFile("src/lib/config.ts")
|
||||
let default_config = file.getClass("default_config")
|
||||
let settings = config.get()
|
||||
const file = metadata.everything.getFile("src/lib/config.ts")
|
||||
const default_config = file.getClass("default_config")
|
||||
const settings = config.get()
|
||||
|
||||
if (default_config === undefined || settings === undefined) {
|
||||
return
|
||||
|
@ -73,7 +73,7 @@ export class SettingsCompletionSource extends Completions.CompletionSourceFuse {
|
|||
.filter(x => x.startsWith(query))
|
||||
.sort()
|
||||
.map(setting => {
|
||||
let md = default_config.getMember(setting)
|
||||
const md = default_config.getMember(setting)
|
||||
let doc = ""
|
||||
let type = ""
|
||||
if (md !== undefined) {
|
||||
|
|
|
@ -127,7 +127,7 @@ export class BufferCompletionSource extends Completions.CompletionSourceFuse {
|
|||
@Perf.measuredAsync
|
||||
private async updateOptions(exstr = "") {
|
||||
this.lastExstr = exstr
|
||||
let [prefix, query] = this.splitOnPrefix(exstr)
|
||||
const [prefix, query] = this.splitOnPrefix(exstr)
|
||||
|
||||
// Hide self and stop if prefixes don't match
|
||||
if (prefix) {
|
||||
|
|
|
@ -71,7 +71,7 @@ export class TabAllCompletionSource extends Completions.CompletionSourceFuse {
|
|||
@Perf.measuredAsync
|
||||
private async updateOptions(exstr = "") {
|
||||
this.lastExstr = exstr
|
||||
let [prefix] = this.splitOnPrefix(exstr)
|
||||
const [prefix] = this.splitOnPrefix(exstr)
|
||||
|
||||
// Hide self and stop if prefixes don't match
|
||||
if (prefix) {
|
||||
|
|
|
@ -48,7 +48,7 @@ export class WindowCompletionSource extends Completions.CompletionSourceFuse {
|
|||
|
||||
private async updateOptions(exstr = "") {
|
||||
this.lastExstr = exstr
|
||||
let [prefix] = this.splitOnPrefix(exstr)
|
||||
const [prefix] = this.splitOnPrefix(exstr)
|
||||
|
||||
// Hide self and stop if prefixes don't match
|
||||
if (prefix) {
|
||||
|
@ -63,7 +63,7 @@ export class WindowCompletionSource extends Completions.CompletionSourceFuse {
|
|||
|
||||
this.options = (await browserBg.windows.getAll({ populate: true })).map(
|
||||
win => {
|
||||
let o = new WindowCompletionOption(win)
|
||||
const o = new WindowCompletionOption(win)
|
||||
o.state = "normal"
|
||||
return o
|
||||
},
|
||||
|
|
|
@ -116,8 +116,8 @@ if (
|
|||
window.location.pathname === "/static/newtab.html"
|
||||
) {
|
||||
config.getAsync("newtab").then(newtab => {
|
||||
if (newtab === "about:blank") {
|
||||
} else if (newtab) {
|
||||
if (newtab !== "about:blank") {
|
||||
if (newtab) {
|
||||
excmds.open_quiet(newtab)
|
||||
} else {
|
||||
document.body.style.height = "100%"
|
||||
|
@ -125,6 +125,7 @@ if (
|
|||
document.body.style.overflow = "auto"
|
||||
document.title = "Tridactyl Top Tips & New Tab Page"
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -133,12 +134,12 @@ config.getAsync("modeindicator").then(mode => {
|
|||
if (mode !== "true") return
|
||||
|
||||
// Do we want container indicators?
|
||||
let containerIndicator = config.get("containerindicator")
|
||||
const containerIndicator = config.get("containerindicator")
|
||||
|
||||
// Hide indicator in print mode
|
||||
// CSS not explicitly added to the dom doesn't make it to print mode:
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1448507
|
||||
let style = document.createElement("style")
|
||||
const style = document.createElement("style")
|
||||
style.type = "text/css"
|
||||
style.innerHTML = `@media print {
|
||||
.TridactylStatusIndicator {
|
||||
|
@ -146,7 +147,7 @@ config.getAsync("modeindicator").then(mode => {
|
|||
}
|
||||
}`
|
||||
|
||||
let statusIndicator = document.createElement("span")
|
||||
const statusIndicator = document.createElement("span")
|
||||
const privateMode = browser.extension.inIncognitoContext
|
||||
? "TridactylPrivate"
|
||||
: ""
|
||||
|
@ -175,10 +176,10 @@ config.getAsync("modeindicator").then(mode => {
|
|||
|
||||
// This listener makes the modeindicator disappear when the mouse goes over it
|
||||
statusIndicator.addEventListener("mouseenter", ev => {
|
||||
let target = ev.target as any
|
||||
let rect = target.getBoundingClientRect()
|
||||
const target = ev.target as any
|
||||
const rect = target.getBoundingClientRect()
|
||||
target.classList.add("TridactylInvisible")
|
||||
let onMouseOut = ev => {
|
||||
const onMouseOut = ev => {
|
||||
// If the mouse event happened out of the mode indicator boundaries
|
||||
if (
|
||||
ev.clientX < rect.x ||
|
||||
|
@ -242,7 +243,7 @@ config.getAsync("modeindicator").then(mode => {
|
|||
} else {
|
||||
result = mode
|
||||
}
|
||||
let modeindicatorshowkeys = Config.get("modeindicatorshowkeys")
|
||||
const modeindicatorshowkeys = Config.get("modeindicatorshowkeys")
|
||||
if (modeindicatorshowkeys === "true" && suffix !== "") {
|
||||
result = mode + " " + suffix
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ const cmdline_logger = new Logger("cmdline")
|
|||
|
||||
// inject the commandline iframe into a content page
|
||||
|
||||
let cmdline_iframe = window.document.createElementNS(
|
||||
const cmdline_iframe = window.document.createElementNS(
|
||||
"http://www.w3.org/1999/xhtml",
|
||||
"iframe",
|
||||
) as HTMLIFrameElement
|
||||
|
@ -32,7 +32,7 @@ let enabled = false
|
|||
|
||||
/** Initialise the cmdline_iframe element unless the window location is included in a value of config/noiframe */
|
||||
async function init() {
|
||||
let noiframe = await config.getAsync("noiframe")
|
||||
const noiframe = await config.getAsync("noiframe")
|
||||
if (noiframe === "false" && !enabled) {
|
||||
hide()
|
||||
document.documentElement.appendChild(cmdline_iframe)
|
||||
|
|
|
@ -71,7 +71,7 @@ class KeyCanceller {
|
|||
}
|
||||
|
||||
private cancelKey(ke: KeyboardEvent, kes: KeyboardEvent[]) {
|
||||
let index = kes.findIndex(
|
||||
const index = kes.findIndex(
|
||||
ke2 =>
|
||||
ke.altKey === ke2.altKey &&
|
||||
ke.code === ke2.code &&
|
||||
|
@ -107,12 +107,12 @@ function* ParserController() {
|
|||
let keyEvents: KeyboardEvent[] = []
|
||||
try {
|
||||
while (true) {
|
||||
let keyevent: KeyboardEvent = yield
|
||||
const keyevent: KeyboardEvent = yield
|
||||
|
||||
// _just to be safe_, cache this to make the following
|
||||
// code more thread-safe.
|
||||
let currentMode = contentState.mode
|
||||
let textEditable = isTextEditable(keyevent.target as Element)
|
||||
const currentMode = contentState.mode
|
||||
const textEditable = isTextEditable(keyevent.target as Element)
|
||||
|
||||
// This code was sort of the cause of the most serious bug in Tridactyl
|
||||
// to date (March 2018).
|
||||
|
@ -140,7 +140,7 @@ function* ParserController() {
|
|||
// unbounded length.
|
||||
keyEvents.push(keyevent)
|
||||
|
||||
let response = parsers[contentState.mode](keyEvents)
|
||||
const response = parsers[contentState.mode](keyEvents)
|
||||
logger.debug(
|
||||
currentMode,
|
||||
contentState.mode,
|
||||
|
@ -175,7 +175,7 @@ function* ParserController() {
|
|||
}
|
||||
}
|
||||
|
||||
let generator = ParserController() // var rather than let stops weirdness in repl.
|
||||
const generator = ParserController() // var rather than let stops weirdness in repl.
|
||||
generator.next()
|
||||
|
||||
/** Feed keys to the ParserController */
|
||||
|
|
|
@ -18,7 +18,7 @@ export class Match {
|
|||
}
|
||||
|
||||
function isCommandLineNode(n) {
|
||||
let url = n.ownerDocument.location.href
|
||||
const url = n.ownerDocument.location.href
|
||||
return (
|
||||
url.protocol === "moz-extension:" &&
|
||||
url.pathname === "/static/commandline.html"
|
||||
|
@ -29,8 +29,8 @@ function isCommandLineNode(n) {
|
|||
TODO: cache the results. I tried to do it but since we need to invalidate the cache when nodes are added/removed from the page, the results are constantly being invalidated by the completion buffer.
|
||||
The solution is obviously to pass `document.body` to createTreeWalker instead of just `document` but then you won't get all the text nodes in the page and this is a big problem because the results returned by browser.find.find() need absolutely all nodes existing within the page, even the ones belonging the commandline. */
|
||||
function getNodes() {
|
||||
let nodes = []
|
||||
let walker = document.createTreeWalker(
|
||||
const nodes = []
|
||||
const walker = document.createTreeWalker(
|
||||
document,
|
||||
NodeFilter.SHOW_TEXT,
|
||||
null,
|
||||
|
@ -49,17 +49,17 @@ let lastMatches = []
|
|||
/** Given "findings", an array matching the one returned by find(), will compute the context for every match in findings and prune the matches than happened in Tridactyl's command line. ContextLength is how many characters from before and after the match should be included into the returned Match object.
|
||||
getMatches() will save its returned values in lastMatches. This is important for caching purposes in jumpToMatch, read its documentation to get the whole picture. */
|
||||
export function getMatches(findings, contextLength = 10): Match[] {
|
||||
let result = []
|
||||
const result = []
|
||||
|
||||
if (findings.length === 0) return result
|
||||
|
||||
// Checks if a node belongs to the command line
|
||||
let nodes = getNodes()
|
||||
const nodes = getNodes()
|
||||
|
||||
for (let i = 0; i < findings.length; ++i) {
|
||||
let range = findings[i][0]
|
||||
let firstnode = nodes[range.startTextNodePos]
|
||||
let lastnode = nodes[range.endTextNodePos]
|
||||
const range = findings[i][0]
|
||||
const firstnode = nodes[range.startTextNodePos]
|
||||
const lastnode = nodes[range.endTextNodePos]
|
||||
// We never want to match against nodes in the command line
|
||||
if (
|
||||
!firstnode ||
|
||||
|
@ -79,7 +79,7 @@ export function getMatches(findings, contextLength = 10): Match[] {
|
|||
let missingChars = contextLength - precontext.length
|
||||
let id = range.startTextNodePos - 1
|
||||
while (missingChars > 0 && nodes[id]) {
|
||||
let txt = nodes[id].textContent
|
||||
const txt = nodes[id].textContent
|
||||
precontext =
|
||||
txt.substring(txt.length - missingChars, txt.length) +
|
||||
precontext
|
||||
|
@ -127,12 +127,12 @@ let findCount = 0
|
|||
If count is different from -1 and lower than the number of matches returned by browser.find.find(), will return count results. Note that when this happens, `matchesCacheIsValid ` is set to false, which will prevent `jumpToMatch` from using cached matches. */
|
||||
export async function find(query, count = -1, reverse = false) {
|
||||
findCount += 1
|
||||
let findId = findCount
|
||||
let findcase = await config.getAsync("findcase")
|
||||
let caseSensitive =
|
||||
const findId = findCount
|
||||
const findcase = await config.getAsync("findcase")
|
||||
const caseSensitive =
|
||||
findcase === "sensitive" ||
|
||||
(findcase === "smart" && query.search(/[A-Z]/) >= 0)
|
||||
let tabId = await activeTabId()
|
||||
const tabId = await activeTabId()
|
||||
|
||||
// No point in searching for something that won't be used anyway
|
||||
await prevFind
|
||||
|
@ -164,7 +164,7 @@ export async function find(query, count = -1, reverse = false) {
|
|||
e[1].rectsAndTexts.rectList[0].top < window.pageYOffset
|
||||
}
|
||||
|
||||
let pivot = findings.indexOf(findings.find(finder))
|
||||
const pivot = findings.indexOf(findings.find(finder))
|
||||
findings = findings.slice(pivot).concat(findings.slice(0, pivot))
|
||||
|
||||
if (count !== -1 && count < findings.length) return findings.slice(0, count)
|
||||
|
@ -173,7 +173,7 @@ export async function find(query, count = -1, reverse = false) {
|
|||
}
|
||||
|
||||
function createHighlightingElement(rect) {
|
||||
let e = document.createElement("div")
|
||||
const e = document.createElement("div")
|
||||
e.className = "cleanslate TridactylSearchHighlight"
|
||||
e.setAttribute(
|
||||
"style",
|
||||
|
@ -254,8 +254,8 @@ export async function jumpToMatch(pattern, reverse, startingFrom) {
|
|||
|
||||
match = findVisibleNode(lastMatches, startingFrom, reverse ? -1 : 1)
|
||||
|
||||
for (let rect of match.rectData.rectsAndTexts.rectList) {
|
||||
let elem = createHighlightingElement(rect)
|
||||
for (const rect of match.rectData.rectsAndTexts.rectList) {
|
||||
const elem = createHighlightingElement(rect)
|
||||
highlightingElements.push(elem)
|
||||
document.body.appendChild(elem)
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ export function jumpToNextMatch(n: number) {
|
|||
}
|
||||
|
||||
browserBg.find.highlightResults()
|
||||
let match = findVisibleNode(
|
||||
const match = findVisibleNode(
|
||||
lastMatches,
|
||||
(n + lastMatch + lastMatches.length) % lastMatches.length,
|
||||
n <= 0 ? -1 : 1,
|
||||
|
@ -284,8 +284,8 @@ export function jumpToNextMatch(n: number) {
|
|||
if (match === undefined)
|
||||
throw `No matches found. The pattern looked for doesn't exist or ':find' hasn't been run yet`
|
||||
|
||||
for (let rect of match.rectData.rectsAndTexts.rectList) {
|
||||
let elem = createHighlightingElement(rect)
|
||||
for (const rect of match.rectData.rectsAndTexts.rectList) {
|
||||
const elem = createHighlightingElement(rect)
|
||||
highlightingElements.push(elem)
|
||||
document.body.appendChild(elem)
|
||||
}
|
||||
|
|
|
@ -103,8 +103,8 @@ export function hintPage(
|
|||
reject = () => {},
|
||||
rapid = false,
|
||||
) {
|
||||
let buildHints: HintBuilder = defaultHintBuilder()
|
||||
let filterHints: HintFilter = defaultHintFilter()
|
||||
const buildHints: HintBuilder = defaultHintBuilder()
|
||||
const filterHints: HintFilter = defaultHintFilter()
|
||||
contentState.mode = "hint"
|
||||
modeState = new HintState(filterHints, resolve, reject, rapid)
|
||||
|
||||
|
@ -123,15 +123,15 @@ export function hintPage(
|
|||
}
|
||||
|
||||
if (modeState.hints.length) {
|
||||
let firstTarget = modeState.hints[0].target
|
||||
let shouldSelect =
|
||||
const firstTarget = modeState.hints[0].target
|
||||
const shouldSelect =
|
||||
firstTarget instanceof HTMLAnchorElement &&
|
||||
firstTarget.href !== "" &&
|
||||
!firstTarget.href.startsWith("javascript:")
|
||||
if (shouldSelect) {
|
||||
// Try to find an element that is not a link or that doesn't point
|
||||
// to the same URL as the first hint
|
||||
let different = modeState.hints.find(h => {
|
||||
const different = modeState.hints.find(h => {
|
||||
return (
|
||||
!(h.target instanceof HTMLAnchorElement) ||
|
||||
h.target.href !== (firstTarget as HTMLAnchorElement).href
|
||||
|
@ -216,7 +216,7 @@ function* hintnames_short(
|
|||
n: number,
|
||||
hintchars = defaultHintChars(),
|
||||
): IterableIterator<string> {
|
||||
let source = hintnames_simple(hintchars)
|
||||
const source = hintnames_simple(hintchars)
|
||||
const num2skip = Math.floor(n / hintchars.length)
|
||||
yield* islice(source, num2skip, n + num2skip)
|
||||
}
|
||||
|
@ -277,10 +277,10 @@ class Hint {
|
|||
let offsetTop = 0
|
||||
let offsetLeft = 0
|
||||
if (target.ownerDocument !== document) {
|
||||
let iframe = DOM.getAllDocumentFrames().find(
|
||||
const iframe = DOM.getAllDocumentFrames().find(
|
||||
frame => frame.contentDocument === target.ownerDocument,
|
||||
)
|
||||
let rect = iframe.getClientRects()[0]
|
||||
const rect = iframe.getClientRects()[0]
|
||||
offsetTop += rect.top
|
||||
offsetLeft += rect.left
|
||||
}
|
||||
|
@ -334,8 +334,8 @@ class Hint {
|
|||
type HintBuilder = (els: Element[], onSelect: HintSelectedCallback) => void
|
||||
|
||||
function buildHintsSimple(els: Element[], onSelect: HintSelectedCallback) {
|
||||
let names = hintnames(els.length)
|
||||
for (let [el, name] of izip(els, names)) {
|
||||
const names = hintnames(els.length)
|
||||
for (const [el, name] of izip(els, names)) {
|
||||
logger.debug({ el, name })
|
||||
modeState.hintchars += name
|
||||
modeState.hints.push(new Hint(el, name, null, onSelect))
|
||||
|
@ -343,12 +343,12 @@ function buildHintsSimple(els: Element[], onSelect: HintSelectedCallback) {
|
|||
}
|
||||
|
||||
function buildHintsVimperator(els: Element[], onSelect: HintSelectedCallback) {
|
||||
let names = hintnames(els.length)
|
||||
const names = hintnames(els.length)
|
||||
// escape the hintchars string so that strange things don't happen
|
||||
// when special characters are used as hintchars (for example, ']')
|
||||
const escapedHintChars = defaultHintChars().replace(/^\^|[-\\\]]/g, "\\$&")
|
||||
const filterableTextFilter = new RegExp("[" + escapedHintChars + "]", "g")
|
||||
for (let [el, name] of izip(els, names)) {
|
||||
for (const [el, name] of izip(els, names)) {
|
||||
let ft = elementFilterableText(el)
|
||||
// strip out hintchars
|
||||
ft = ft.replace(filterableTextFilter, "")
|
||||
|
@ -380,7 +380,7 @@ type HintFilter = (string) => void
|
|||
function filterHintsSimple(fstr) {
|
||||
const active: Hint[] = []
|
||||
let foundMatch
|
||||
for (let h of modeState.hints) {
|
||||
for (const h of modeState.hints) {
|
||||
if (!h.name.startsWith(fstr)) h.hidden = true
|
||||
else {
|
||||
if (!foundMatch) {
|
||||
|
@ -577,7 +577,7 @@ export function pipe_elements(
|
|||
function selectFocusedHint(delay = false) {
|
||||
logger.debug("Selecting hint.", contentState.mode)
|
||||
const focused = modeState.focusedHint
|
||||
let selectFocusedHintInternal = () => {
|
||||
const selectFocusedHintInternal = () => {
|
||||
modeState.filter = ""
|
||||
modeState.hints.forEach(h => (h.hidden = false))
|
||||
focused.select()
|
||||
|
|
|
@ -2,7 +2,7 @@ import * as config from "@src/lib/config"
|
|||
|
||||
type scrollingDirection = "scrollLeft" | "scrollTop"
|
||||
|
||||
let opts = { smooth: null, duration: null }
|
||||
const opts = { smooth: null, duration: null }
|
||||
async function getSmooth() {
|
||||
if (opts.smooth === null)
|
||||
opts.smooth = await config.getAsync("smoothscroll")
|
||||
|
@ -48,20 +48,20 @@ class ScrollingData {
|
|||
if (this.startTime === undefined) {
|
||||
this.startTime = performance.now()
|
||||
}
|
||||
let elapsed = performance.now() - this.startTime
|
||||
const elapsed = performance.now() - this.startTime
|
||||
|
||||
// If the animation should be done, return the position the element should have
|
||||
if (elapsed >= this.duration || this.elem[this.pos] === this.endPos)
|
||||
return this.endPos
|
||||
|
||||
let result = ((this.endPos - this.startPos) * elapsed) / this.duration
|
||||
const 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)
|
||||
}
|
||||
|
||||
/** Updates the position of this.elem, returns true if the element has been scrolled, false otherwise. */
|
||||
scrollStep() {
|
||||
let val = this.elem[this.pos]
|
||||
const val = this.elem[this.pos]
|
||||
this.elem[this.pos] = this.getStep()
|
||||
return val !== this.elem[this.pos]
|
||||
}
|
||||
|
@ -94,9 +94,9 @@ class ScrollingData {
|
|||
}
|
||||
|
||||
// Stores elements that are currently being horizontally scrolled
|
||||
let horizontallyScrolling = new Map<Node, ScrollingData>()
|
||||
const horizontallyScrolling = new Map<Node, ScrollingData>()
|
||||
// Stores elements that are currently being vertically scrolled
|
||||
let verticallyScrolling = new Map<Node, ScrollingData>()
|
||||
const verticallyScrolling = new Map<Node, ScrollingData>()
|
||||
|
||||
/** Tries to scroll e by x and y pixel, make the smooth scrolling animation
|
||||
* last duration milliseconds
|
||||
|
@ -107,7 +107,7 @@ export async function scroll(
|
|||
e: Node,
|
||||
duration?: number,
|
||||
) {
|
||||
let smooth = await getSmooth()
|
||||
const smooth = await getSmooth()
|
||||
if (smooth === "false") duration = 0
|
||||
else if (duration === undefined) duration = await getDuration()
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ export const contentState = (new Proxy(
|
|||
const mode = target.mode
|
||||
target[property] = newValue
|
||||
|
||||
for (let listener of onChangedListeners) {
|
||||
for (const listener of onChangedListeners) {
|
||||
listener(property, mode, oldValue, newValue)
|
||||
}
|
||||
return true
|
||||
|
|
|
@ -20,7 +20,7 @@ function prefixTheme(name) {
|
|||
const THEMED_ELEMENTS = []
|
||||
|
||||
let insertedCSS = false
|
||||
let customCss = {
|
||||
const customCss = {
|
||||
allFrames: true,
|
||||
matchAboutBlank: true,
|
||||
code: "",
|
||||
|
@ -28,7 +28,7 @@ let customCss = {
|
|||
|
||||
export async function theme(element) {
|
||||
// Remove any old theme
|
||||
for (let theme of THEMES.map(prefixTheme)) {
|
||||
for (const theme of THEMES.map(prefixTheme)) {
|
||||
element.classList.remove(theme)
|
||||
}
|
||||
if (insertedCSS) {
|
||||
|
@ -38,7 +38,7 @@ export async function theme(element) {
|
|||
insertedCSS = false
|
||||
}
|
||||
|
||||
let newTheme = await config.getAsync("theme")
|
||||
const newTheme = await config.getAsync("theme")
|
||||
|
||||
// Add a class corresponding to config.get('theme')
|
||||
if (newTheme !== "default") {
|
||||
|
@ -82,8 +82,8 @@ config.addChangeListener("theme", retheme)
|
|||
|
||||
// Sometimes pages will overwrite class names of elements. We use a MutationObserver to make sure that the HTML element always has a TridactylTheme class
|
||||
// We can't just call theme() because it would first try to remove class names from the element, which would trigger the MutationObserver before we had a chance to add the theme class and thus cause infinite recursion
|
||||
let cb = async mutationList => {
|
||||
let theme = await config.getAsync("theme")
|
||||
const cb = async mutationList => {
|
||||
const theme = await config.getAsync("theme")
|
||||
mutationList
|
||||
.filter(m => m.target.className.search(prefixTheme("")) === -1)
|
||||
.forEach(m => m.target.classList.add(prefixTheme(theme)))
|
||||
|
|
|
@ -19,7 +19,7 @@ export function jack_in() {
|
|||
export let snow = () => rain(["❄"], "#FFF", 0.15)
|
||||
|
||||
export function rain(characters: string[], colour, darkening = 0.05) {
|
||||
let d = document.createElement("div")
|
||||
const d = document.createElement("div")
|
||||
d.style.position = "fixed"
|
||||
d.style.display = "block"
|
||||
d.style.width = "100%"
|
||||
|
@ -30,10 +30,10 @@ export function rain(characters: string[], colour, darkening = 0.05) {
|
|||
d.style.bottom = "0"
|
||||
d.style.zIndex = "1000"
|
||||
d.style.opacity = "0.5"
|
||||
let c = document.createElement("canvas")
|
||||
const c = document.createElement("canvas")
|
||||
d.appendChild(c)
|
||||
document.body.appendChild(d)
|
||||
let ctx = c.getContext("2d")
|
||||
const ctx = c.getContext("2d")
|
||||
|
||||
// making the canvas full screen
|
||||
c.height = window.innerHeight
|
||||
|
@ -41,10 +41,10 @@ export function rain(characters: string[], colour, darkening = 0.05) {
|
|||
|
||||
// converting the string into an array of single characters
|
||||
|
||||
let font_size = 10
|
||||
let columns = c.width / font_size // number of columns for the rain
|
||||
const font_size = 10
|
||||
const columns = c.width / font_size // number of columns for the rain
|
||||
// an array of drops - one per column
|
||||
let drops = []
|
||||
const drops = []
|
||||
// x below is the x coordinate
|
||||
// 1 = y co-ordinate of the drop(same for every drop initially)
|
||||
for (let x = 0; x < columns; x++) drops[x] = 1
|
||||
|
@ -61,7 +61,7 @@ export function rain(characters: string[], colour, darkening = 0.05) {
|
|||
// looping over drops
|
||||
for (let i = 0; i < drops.length; i++) {
|
||||
// a random chinese character to print
|
||||
let text = characters[Math.floor(Math.random() * characters.length)]
|
||||
const text = characters[Math.floor(Math.random() * characters.length)]
|
||||
// x = i*font_size, y = value of drops[i]*font_size
|
||||
ctx.fillText(text, i * font_size, drops[i] * font_size)
|
||||
|
||||
|
|
272
src/excmds.ts
272
src/excmds.ts
|
@ -131,7 +131,7 @@ export async function getNativeVersion(): Promise<void> {
|
|||
*/
|
||||
//#content
|
||||
export async function getRssLinks(): Promise<Array<{ type: string; url: string; title: string }>> {
|
||||
let seen = new Set<string>()
|
||||
const seen = new Set<string>()
|
||||
return Array.from(document.querySelectorAll("a, link[rel='alternate']"))
|
||||
.filter((e: any) => typeof e.href === "string")
|
||||
.reduce((acc, e: any) => {
|
||||
|
@ -165,7 +165,7 @@ export async function getRssLinks(): Promise<Array<{ type: string; url: string;
|
|||
//#content
|
||||
export async function rssexec(url: string, type?: string, ...title: string[]) {
|
||||
if (!url || url === "") {
|
||||
let links = await getRssLinks()
|
||||
const links = await getRssLinks()
|
||||
switch (links.length) {
|
||||
case 0:
|
||||
throw new Error("No rss link found on this page.")
|
||||
|
@ -233,14 +233,14 @@ export function getInputSelector() {
|
|||
/** @hidden */
|
||||
//#content
|
||||
export function addTridactylEditorClass(selector: string) {
|
||||
let elem = document.querySelector(selector)
|
||||
const elem = document.querySelector(selector)
|
||||
elem.className = elem.className + " TridactylEditing "
|
||||
}
|
||||
|
||||
/** @hidden */
|
||||
//#content
|
||||
export function removeTridactylEditorClass(selector: string) {
|
||||
let elem = document.querySelector(selector)
|
||||
const elem = document.querySelector(selector)
|
||||
elem.className = elem.className.replace(" TridactylEditing ", "")
|
||||
}
|
||||
|
||||
|
@ -266,8 +266,8 @@ export function removeTridactylEditorClass(selector: string) {
|
|||
*/
|
||||
//#content
|
||||
export async function editor() {
|
||||
let elem = DOM.getLastUsedInput()
|
||||
let selector = DOM.getSelector(elem)
|
||||
const elem = DOM.getLastUsedInput()
|
||||
const selector = DOM.getSelector(elem)
|
||||
addTridactylEditorClass(selector)
|
||||
|
||||
if (!(await Native.nativegate())) {
|
||||
|
@ -302,20 +302,20 @@ export async function guiset_quiet(rule: string, option: string) {
|
|||
|
||||
// Check for native messenger and make sure we have a plausible profile directory
|
||||
if (!(await Native.nativegate("0.1.1"))) return
|
||||
let profile_dir = await Native.getProfileDir()
|
||||
const profile_dir = await Native.getProfileDir()
|
||||
|
||||
// Make backups
|
||||
await Native.mkdir(profile_dir + "/chrome", true)
|
||||
let cssstr = (await Native.read(profile_dir + "/chrome/userChrome.css")).content
|
||||
let cssstrOrig = (await Native.read(profile_dir + "/chrome/userChrome.orig.css")).content
|
||||
const cssstrOrig = (await Native.read(profile_dir + "/chrome/userChrome.orig.css")).content
|
||||
if (cssstrOrig === "") await Native.write(profile_dir + "/chrome/userChrome.orig.css", cssstr)
|
||||
await Native.write(profile_dir + "/chrome/userChrome.css.tri.bak", cssstr)
|
||||
|
||||
// Modify and write new CSS
|
||||
if (cssstr === "") cssstr = `@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");`
|
||||
let stylesheet = CSS.parse(cssstr)
|
||||
const stylesheet = CSS.parse(cssstr)
|
||||
// Trim due to https://github.com/reworkcss/css/issues/113
|
||||
let stylesheetDone = CSS.stringify(css_util.changeCss(rule, option, stylesheet)).trim()
|
||||
const stylesheetDone = CSS.stringify(css_util.changeCss(rule, option, stylesheet)).trim()
|
||||
return Native.write(profile_dir + "/chrome/userChrome.css", stylesheetDone)
|
||||
}
|
||||
|
||||
|
@ -480,7 +480,7 @@ export async function nativeopen(...args: string[]) {
|
|||
|
||||
if (await Native.nativegate()) {
|
||||
// First compute where the tab should be
|
||||
let pos = await config.getAsync("tabopenpos")
|
||||
const pos = await config.getAsync("tabopenpos")
|
||||
let index = (await activeTab()).index + 1
|
||||
switch (pos) {
|
||||
case "last":
|
||||
|
@ -492,7 +492,7 @@ export async function nativeopen(...args: string[]) {
|
|||
}
|
||||
// Then make sure the tab is made active and moved to the right place
|
||||
// when it is opened in the current window
|
||||
let selecttab = tab => {
|
||||
const selecttab = tab => {
|
||||
browser.tabs.onCreated.removeListener(selecttab)
|
||||
tabSetActive(tab.id)
|
||||
browser.tabs.move(tab.id, { index })
|
||||
|
@ -504,7 +504,7 @@ export async function nativeopen(...args: string[]) {
|
|||
if ((await browser.windows.getCurrent()).incognito) {
|
||||
throw "nativeopen isn't supported in private mode on OSX. Consider installing Linux or Windows :)."
|
||||
}
|
||||
let osascriptArgs = ["-e 'on run argv'", "-e 'tell application \"Firefox\" to open location item 1 of argv'", "-e 'end run'"]
|
||||
const osascriptArgs = ["-e 'on run argv'", "-e 'tell application \"Firefox\" to open location item 1 of argv'", "-e 'end run'"]
|
||||
await Native.run("osascript " + osascriptArgs.join(" ") + " " + url)
|
||||
} else {
|
||||
if (firefoxArgs.length === 0) {
|
||||
|
@ -657,7 +657,7 @@ export async function restart() {
|
|||
const browsercmd = await config.get("browser")
|
||||
|
||||
if ((await browser.runtime.getPlatformInfo()).os === "win") {
|
||||
let reply = await Native.winFirefoxRestart(profiledir, browsercmd)
|
||||
const reply = await Native.winFirefoxRestart(profiledir, browsercmd)
|
||||
logger.info("[+] win_firefox_restart 'reply' = " + JSON.stringify(reply))
|
||||
if (Number(reply.code) === 0) {
|
||||
fillcmdline("#" + reply.content)
|
||||
|
@ -732,16 +732,16 @@ export async function saveJumps(jumps) {
|
|||
*/
|
||||
//#content_helper
|
||||
export async function curJumps() {
|
||||
let tabid = await activeTabId()
|
||||
const tabid = await activeTabId()
|
||||
let jumps = await browserBg.sessions.getTabValue(tabid, "jumps")
|
||||
if (!jumps) jumps = {}
|
||||
// This makes sure that `key` exists in `obj`, setting it to `def` if it doesn't
|
||||
let ensure = (obj, key, def) => {
|
||||
const ensure = (obj, key, def) => {
|
||||
if (obj[key] === null || obj[key] === undefined) obj[key] = def
|
||||
}
|
||||
let page = getJumpPageId()
|
||||
const page = getJumpPageId()
|
||||
ensure(jumps, page, {})
|
||||
let dummy = new UIEvent("scroll")
|
||||
const dummy = new UIEvent("scroll")
|
||||
ensure(jumps[page], "list", [{ x: dummy.pageX, y: dummy.pageY }])
|
||||
ensure(jumps[page], "cur", 0)
|
||||
saveJumps(jumps)
|
||||
|
@ -763,8 +763,8 @@ export function jumpnext(n = 1) {
|
|||
//#content
|
||||
export function jumpprev(n = 1) {
|
||||
curJumps().then(alljumps => {
|
||||
let jumps = alljumps[getJumpPageId()]
|
||||
let current = jumps.cur - n
|
||||
const jumps = alljumps[getJumpPageId()]
|
||||
const current = jumps.cur - n
|
||||
if (current < 0) {
|
||||
jumps.cur = 0
|
||||
saveJumps(alljumps)
|
||||
|
@ -775,7 +775,7 @@ export function jumpprev(n = 1) {
|
|||
return forward(current - jumps.list.length + 1)
|
||||
}
|
||||
jumps.cur = current
|
||||
let p = jumps.list[jumps.cur]
|
||||
const p = jumps.list[jumps.cur]
|
||||
saveJumps(alljumps)
|
||||
JUMPED = true
|
||||
window.scrollTo(p.x, p.y)
|
||||
|
@ -797,16 +797,16 @@ export function addJump(scrollEvent: UIEvent) {
|
|||
JUMPED = false
|
||||
return
|
||||
}
|
||||
let pageX = scrollEvent.pageX
|
||||
let pageY = scrollEvent.pageY
|
||||
const pageX = scrollEvent.pageX
|
||||
const pageY = scrollEvent.pageY
|
||||
// Get config for current page
|
||||
curJumps().then(alljumps => {
|
||||
let jumps = alljumps[getJumpPageId()]
|
||||
const jumps = alljumps[getJumpPageId()]
|
||||
// Prevent pending jump from being registered
|
||||
clearTimeout(jumps.timeoutid)
|
||||
// Schedule the registering of the current jump
|
||||
jumps.timeoutid = setTimeout(() => {
|
||||
let list = jumps.list
|
||||
const list = jumps.list
|
||||
// if the page hasn't moved, stop
|
||||
if (list[jumps.cur].x === pageX && list[jumps.cur].y === pageY) return
|
||||
// Store the new jump
|
||||
|
@ -856,10 +856,10 @@ export function scrollto(a: number | string, b: number | "x" | "y" = "y") {
|
|||
a = (Number(a.replace(/c$/, "")) * 100) / (2 * Math.PI)
|
||||
}
|
||||
a = Number(a)
|
||||
let elem = window.document.scrollingElement || window.document.documentElement
|
||||
let percentage = a.clamp(0, 100)
|
||||
const elem = window.document.scrollingElement || window.document.documentElement
|
||||
const percentage = a.clamp(0, 100)
|
||||
if (b === "y") {
|
||||
let top = elem.getClientRects()[0].top
|
||||
const top = elem.getClientRects()[0].top
|
||||
window.scrollTo(window.scrollX, (percentage * elem.scrollHeight) / 100)
|
||||
if (top === elem.getClientRects()[0].top && (percentage === 0 || percentage === 100)) {
|
||||
// scrollTo failed, if the user wants to go to the top/bottom of
|
||||
|
@ -867,7 +867,7 @@ export function scrollto(a: number | string, b: number | "x" | "y" = "y") {
|
|||
scrolling.recursiveScroll(window.scrollX, 1073741824 * (percentage === 0 ? -1 : 1), document.documentElement)
|
||||
}
|
||||
} else if (b === "x") {
|
||||
let left = elem.getClientRects()[0].left
|
||||
const left = elem.getClientRects()[0].left
|
||||
window.scrollTo((percentage * elem.scrollWidth) / 100, window.scrollY)
|
||||
if (left === elem.getClientRects()[0].left && (percentage === 0 || percentage === 100)) {
|
||||
scrolling.recursiveScroll(1073741824 * (percentage === 0 ? -1 : 1), window.scrollX, document.documentElement)
|
||||
|
@ -887,7 +887,7 @@ let lineHeight = null
|
|||
//#content
|
||||
export function scrollline(n = 1) {
|
||||
if (lineHeight === null) {
|
||||
let getLineHeight = elem => {
|
||||
const getLineHeight = elem => {
|
||||
// Get line height
|
||||
const cssHeight = window.getComputedStyle(elem).getPropertyValue("line-height")
|
||||
// Remove the "px" at the end
|
||||
|
@ -935,7 +935,7 @@ import * as finding from "@src/content/finding"
|
|||
//#content
|
||||
export function find(...args: string[]) {
|
||||
let flagpos = args.indexOf("-?")
|
||||
let reverse = flagpos >= 0
|
||||
const reverse = flagpos >= 0
|
||||
if (reverse) args.splice(flagpos, 1)
|
||||
|
||||
flagpos = args.indexOf("-:")
|
||||
|
@ -986,16 +986,16 @@ export function back(n = 1) {
|
|||
/** Reload the next n tabs, starting with activeTab, possibly bypassingCache */
|
||||
//#background
|
||||
export async function reload(n = 1, hard = false) {
|
||||
let tabstoreload = await getnexttabs(await activeTabId(), n)
|
||||
let reloadProperties = { bypassCache: hard }
|
||||
const tabstoreload = await getnexttabs(await activeTabId(), n)
|
||||
const reloadProperties = { bypassCache: hard }
|
||||
tabstoreload.forEach(n => browser.tabs.reload(n, reloadProperties))
|
||||
}
|
||||
|
||||
/** Reloads all tabs, bypassing the cache if hard is set to true */
|
||||
//#background
|
||||
export async function reloadall(hard = false) {
|
||||
let tabs = await browser.tabs.query({ currentWindow: true })
|
||||
let reloadprops = { bypassCache: hard }
|
||||
const tabs = await browser.tabs.query({ currentWindow: true })
|
||||
const reloadprops = { bypassCache: hard }
|
||||
tabs.forEach(tab => browser.tabs.reload(tab.id, reloadprops))
|
||||
}
|
||||
|
||||
|
@ -1003,9 +1003,9 @@ export async function reloadall(hard = false) {
|
|||
//#background
|
||||
export async function reloadallbut(hard = false) {
|
||||
let tabs = await browser.tabs.query({ currentWindow: true })
|
||||
let currId = await activeTabId()
|
||||
const currId = await activeTabId()
|
||||
tabs = tabs.filter(tab => tab.id !== currId)
|
||||
let reloadprops = { bypassCache: hard }
|
||||
const reloadprops = { bypassCache: hard }
|
||||
tabs.forEach(tab => browser.tabs.reload(tab.id, reloadprops))
|
||||
}
|
||||
|
||||
|
@ -1037,7 +1037,7 @@ export const ABOUT_WHITELIST = ["about:license", "about:logo", "about:rights", "
|
|||
*/
|
||||
//#content
|
||||
export async function open(...urlarr: string[]) {
|
||||
let url = urlarr.join(" ")
|
||||
const url = urlarr.join(" ")
|
||||
let p = Promise.resolve()
|
||||
|
||||
// Setting window.location to about:blank results in a page we can't access, tabs.update works.
|
||||
|
@ -1045,7 +1045,7 @@ export async function open(...urlarr: string[]) {
|
|||
// Open URLs that firefox won't let us by running `firefox <URL>` on the command line
|
||||
p = Messaging.message("controller_background", "acceptExCmd", ["nativeopen " + url])
|
||||
} else if (url.match(/^javascript:/)) {
|
||||
let bookmarklet = url.replace(/^javascript:/, "")
|
||||
const bookmarklet = url.replace(/^javascript:/, "")
|
||||
; (document.body as any).append(
|
||||
html`
|
||||
<script>
|
||||
|
@ -1077,7 +1077,7 @@ export async function bmarks(opt: string, ...urlarr: string[]) {
|
|||
*/
|
||||
//#content
|
||||
export async function open_quiet(...urlarr: string[]) {
|
||||
let url = urlarr.join(" ")
|
||||
const url = urlarr.join(" ")
|
||||
|
||||
if (!ABOUT_WHITELIST.includes(url) && url.match(/^(about|file):.*/)) {
|
||||
return Messaging.message("controller_background", "acceptExCmd", ["nativeopen " + url])
|
||||
|
@ -1097,26 +1097,26 @@ export async function open_quiet(...urlarr: string[]) {
|
|||
*/
|
||||
//#content
|
||||
export async function url2args() {
|
||||
let url = document.location.href
|
||||
let searchurls = await config.getAsync("searchurls")
|
||||
const url = document.location.href
|
||||
const searchurls = await config.getAsync("searchurls")
|
||||
let result = url
|
||||
|
||||
for (let engine of Object.keys(searchurls)) {
|
||||
let [beginning, end] = [...searchurls[engine].split("%s"), ""]
|
||||
for (const engine of Object.keys(searchurls)) {
|
||||
const [beginning, end] = [...searchurls[engine].split("%s"), ""]
|
||||
if (url.startsWith(beginning) && url.endsWith(end)) {
|
||||
// Get the string matching %s
|
||||
let encodedArgs = url.substring(beginning.length)
|
||||
encodedArgs = encodedArgs.substring(0, encodedArgs.length - end.length)
|
||||
// Remove any get parameters that might have been added by the search engine
|
||||
// This works because if the user's query contains an "&", it will be encoded as %26
|
||||
let amperpos = encodedArgs.search("&")
|
||||
const amperpos = encodedArgs.search("&")
|
||||
if (amperpos > 0) encodedArgs = encodedArgs.substring(0, amperpos)
|
||||
|
||||
// Do transformations depending on the search engine
|
||||
if (beginning.search("duckduckgo") > 0) encodedArgs = encodedArgs.replace(/\+/g, " ")
|
||||
else if (beginning.search("wikipedia") > 0) encodedArgs = encodedArgs.replace(/_/g, " ")
|
||||
|
||||
let args = engine + " " + decodeURIComponent(encodedArgs)
|
||||
const args = engine + " " + decodeURIComponent(encodedArgs)
|
||||
if (args.length < result.length) result = args
|
||||
}
|
||||
}
|
||||
|
@ -1152,7 +1152,7 @@ export function viewsource(url = "") {
|
|||
}
|
||||
if (!sourceElement) {
|
||||
sourceElement = CommandLineContent.executeWithoutCommandLine(() => {
|
||||
let pre = document.createElement("pre")
|
||||
const pre = document.createElement("pre")
|
||||
pre.id = "TridactylViewsourceElement"
|
||||
pre.className = "cleanslate " + config.get("theme")
|
||||
pre.innerText = document.documentElement.innerHTML
|
||||
|
@ -1177,7 +1177,7 @@ export function viewsource(url = "") {
|
|||
*/
|
||||
//#background
|
||||
export function home(all: "false" | "true" = "false") {
|
||||
let homepages = config.get("homepages")
|
||||
const homepages = config.get("homepages")
|
||||
if (homepages.length > 0) {
|
||||
if (all === "false") open(homepages[homepages.length - 1])
|
||||
else {
|
||||
|
@ -1208,9 +1208,9 @@ export async function help(...helpItems: string[]) {
|
|||
const flags = {
|
||||
// -a: look for an alias
|
||||
"-a": (settings, helpItem) => {
|
||||
let aliases = settings.exaliases
|
||||
const aliases = settings.exaliases
|
||||
// As long as helpItem is an alias, try to resolve this alias to a real helpItem
|
||||
let resolved = []
|
||||
const resolved = []
|
||||
while (aliases[helpItem]) {
|
||||
resolved.push(helpItem)
|
||||
helpItem = aliases[helpItem].split(" ")
|
||||
|
@ -1225,8 +1225,8 @@ export async function help(...helpItems: string[]) {
|
|||
},
|
||||
// -b: look for a binding
|
||||
"-b": (settings, helpItem) => {
|
||||
for (let mode of ["nmaps", "imaps", "inputmaps", "ignoremaps"]) {
|
||||
let bindings = settings[mode]
|
||||
for (const mode of ["nmaps", "imaps", "inputmaps", "ignoremaps"]) {
|
||||
const bindings = settings[mode]
|
||||
// If 'helpItem' matches a binding, replace 'helpItem' with
|
||||
// the command that would be executed when pressing the key
|
||||
// sequence referenced by 'helpItem' and don't check other
|
||||
|
@ -1244,10 +1244,10 @@ export async function help(...helpItems: string[]) {
|
|||
// -s: look for a setting
|
||||
"-s": (settings, helpItem) => {
|
||||
let subSettings = settings
|
||||
let settingNames = helpItem.split(".")
|
||||
const settingNames = helpItem.split(".")
|
||||
let settingHelpAnchor = ""
|
||||
// Try to match each piece of the path, this is done so that a correct object (e.g. followpagepatterns) with an incorrect key (e.g. nextt) will still match the parent object.
|
||||
for (let settingName of settingNames) {
|
||||
for (const settingName of settingNames) {
|
||||
if (settingName in subSettings) {
|
||||
settingHelpAnchor += settingName + "."
|
||||
subSettings = subSettings[settingName]
|
||||
|
@ -1407,7 +1407,7 @@ export function followpage(rel: "next" | "prev" = "next") {
|
|||
*/
|
||||
//#content
|
||||
export function urlincrement(count = 1) {
|
||||
let newUrl = UrlUtil.incrementUrl(window.location.href, count)
|
||||
const newUrl = UrlUtil.incrementUrl(window.location.href, count)
|
||||
|
||||
if (newUrl !== null) {
|
||||
// This might throw an error when using incrementurl on a moz-extension:// page if the page we're trying to access doesn't exist
|
||||
|
@ -1423,7 +1423,7 @@ export function urlincrement(count = 1) {
|
|||
*/
|
||||
//#content
|
||||
export function urlroot() {
|
||||
let rootUrl = UrlUtil.getUrlRoot(window.location)
|
||||
const rootUrl = UrlUtil.getUrlRoot(window.location)
|
||||
|
||||
if (rootUrl !== null) {
|
||||
window.location.href = rootUrl.href
|
||||
|
@ -1434,7 +1434,7 @@ export function urlroot() {
|
|||
*/
|
||||
//#content
|
||||
export function urlparent(count = 1) {
|
||||
let parentUrl = UrlUtil.getUrlParent(window.location, count)
|
||||
const parentUrl = UrlUtil.getUrlParent(window.location, count)
|
||||
|
||||
if (parentUrl !== null) {
|
||||
window.location.href = parentUrl.href
|
||||
|
@ -1510,7 +1510,7 @@ export function urlparent(count = 1) {
|
|||
*/
|
||||
//#content
|
||||
export function urlmodify(mode: "-t" | "-r" | "-q" | "-Q" | "-g", ...args: string[]) {
|
||||
let oldUrl = new URL(window.location.href)
|
||||
const oldUrl = new URL(window.location.href)
|
||||
let newUrl
|
||||
|
||||
switch (mode) {
|
||||
|
@ -1531,7 +1531,7 @@ export function urlmodify(mode: "-t" | "-r" | "-q" | "-Q" | "-g", ...args: strin
|
|||
throw new Error("RegExp replacement flags can only include 'g', 'i'" + ", Got '" + args[2] + "'")
|
||||
}
|
||||
|
||||
let regexp = new RegExp(args[0], args[2])
|
||||
const regexp = new RegExp(args[0], args[2])
|
||||
newUrl = oldUrl.href.replace(regexp, args[1])
|
||||
break
|
||||
|
||||
|
@ -1573,7 +1573,7 @@ export function urlmodify(mode: "-t" | "-r" | "-q" | "-Q" | "-g", ...args: strin
|
|||
*/
|
||||
//#content
|
||||
export function geturlsforlinks(reltype = "rel", rel: string) {
|
||||
let elems = document.querySelectorAll("link[" + reltype + "='" + rel + "']")
|
||||
const elems = document.querySelectorAll("link[" + reltype + "='" + rel + "']")
|
||||
if (elems) return Array.prototype.map.call(elems, x => x.href)
|
||||
return []
|
||||
}
|
||||
|
@ -1609,7 +1609,7 @@ export async function zoom(level = 0, rel = "false") {
|
|||
//#background
|
||||
export async function reader() {
|
||||
if (await firefoxVersionAtLeast(58)) {
|
||||
let aTab = await activeTab()
|
||||
const aTab = await activeTab()
|
||||
if (aTab.isArticle) {
|
||||
browser.tabs.toggleReaderMode()
|
||||
} // else {
|
||||
|
@ -1648,10 +1648,10 @@ if (fullscreenApiIsPrefixed) {
|
|||
/** @hidden */
|
||||
//#content
|
||||
export async function loadaucmds(cmdType: "DocStart" | "DocLoad" | "DocEnd" | "TabEnter" | "TabLeft" | "FullscreenEnter" | "FullscreenLeft" | "FullscreenChange") {
|
||||
let aucmds = await config.getAsync("autocmds", cmdType)
|
||||
const aucmds = await config.getAsync("autocmds", cmdType)
|
||||
const ausites = Object.keys(aucmds)
|
||||
const aukeyarr = ausites.filter(e => window.document.location.href.search(e) >= 0)
|
||||
for (let aukey of aukeyarr) {
|
||||
for (const aukey of aukeyarr) {
|
||||
Messaging.message("controller_background", "acceptExCmd", [aucmds[aukey]])
|
||||
}
|
||||
}
|
||||
|
@ -1723,7 +1723,7 @@ export function focusinput(nth: number | string) {
|
|||
}
|
||||
} else if (nth === "-n" || nth === "-N") {
|
||||
// attempt to find next/previous input
|
||||
let inputs = DOM.getElemsBySelector(INPUTTAGS_selectors, [DOM.isSubstantial]) as HTMLElement[]
|
||||
const inputs = DOM.getElemsBySelector(INPUTTAGS_selectors, [DOM.isSubstantial]) as HTMLElement[]
|
||||
if (inputs.length) {
|
||||
let index = inputs.indexOf(DOM.getLastUsedInput())
|
||||
if (DOM.getLastUsedInput()) {
|
||||
|
@ -1742,13 +1742,13 @@ export function focusinput(nth: number | string) {
|
|||
// attempt to find a password input
|
||||
fallbackToNumeric = false
|
||||
|
||||
let inputs = DOM.getElemsBySelector(INPUTPASSWORD_selectors, [DOM.isSubstantial])
|
||||
const inputs = DOM.getElemsBySelector(INPUTPASSWORD_selectors, [DOM.isSubstantial])
|
||||
|
||||
if (inputs.length) {
|
||||
inputToFocus = inputs[0] as HTMLElement
|
||||
}
|
||||
} else if (nth === "-b") {
|
||||
let inputs = DOM.getElemsBySelector(INPUTTAGS_selectors, [DOM.isSubstantial]) as HTMLElement[]
|
||||
const inputs = DOM.getElemsBySelector(INPUTTAGS_selectors, [DOM.isSubstantial]) as HTMLElement[]
|
||||
inputs.sort(DOM.compareElementArea)
|
||||
inputToFocus = inputs[inputs.length - 1]
|
||||
}
|
||||
|
@ -1756,7 +1756,7 @@ export function focusinput(nth: number | string) {
|
|||
// either a number (not special) or we failed to find a special input when
|
||||
// asked and falling back is acceptable
|
||||
if ((!inputToFocus || !document.contains(inputToFocus)) && fallbackToNumeric) {
|
||||
let index = isNaN(nth as number) ? 0 : (nth as number)
|
||||
const index = isNaN(nth as number) ? 0 : (nth as number)
|
||||
inputToFocus = DOM.getNthElement(INPUTTAGS_selectors, index, [DOM.isSubstantial])
|
||||
}
|
||||
|
||||
|
@ -1775,8 +1775,8 @@ export function focusinput(nth: number | string) {
|
|||
*/
|
||||
//#background
|
||||
export async function changelistjump(n?: number) {
|
||||
let tail = state.prevInputs[state.prevInputs.length - 1]
|
||||
let jumppos = tail.jumppos ? tail.jumppos : state.prevInputs.length - 1
|
||||
const tail = state.prevInputs[state.prevInputs.length - 1]
|
||||
const jumppos = tail.jumppos ? tail.jumppos : state.prevInputs.length - 1
|
||||
const input = state.prevInputs[jumppos]
|
||||
await browser.tabs.update(input.tab, { active: true })
|
||||
const id = input.inputId
|
||||
|
@ -1858,7 +1858,7 @@ export async function tabprev(increment = 1) {
|
|||
// Kludge until https://bugzilla.mozilla.org/show_bug.cgi?id=1504775 is fixed:
|
||||
return browser.tabs.query({ currentWindow: true, hidden: false }).then(tabs => {
|
||||
tabs.sort((t1, t2) => t1.index - t2.index)
|
||||
let prevTab = (tabs.findIndex(t => t.active) - increment + tabs.length) % tabs.length
|
||||
const prevTab = (tabs.findIndex(t => t.active) - increment + tabs.length) % tabs.length
|
||||
return browser.tabs.update(tabs[prevTab].id, { active: true })
|
||||
})
|
||||
}
|
||||
|
@ -1896,7 +1896,7 @@ export async function tabopen(...addressarr: string[]) {
|
|||
argParse(args)
|
||||
} else if (args[0] === "-c") {
|
||||
// Ignore the -c flag if incognito as containers are disabled.
|
||||
let win = await browser.windows.getCurrent()
|
||||
const win = await browser.windows.getCurrent()
|
||||
if (!win.incognito) container = await Container.fuzzyMatch(args[1])
|
||||
else logger.error("[tabopen] can't open a container in a private browsing window.")
|
||||
|
||||
|
@ -1907,15 +1907,15 @@ export async function tabopen(...addressarr: string[]) {
|
|||
return args
|
||||
}
|
||||
|
||||
let query = await argParse(addressarr)
|
||||
const query = await argParse(addressarr)
|
||||
|
||||
let address = query.join(" ")
|
||||
const address = query.join(" ")
|
||||
if (!ABOUT_WHITELIST.includes(address) && address.match(/^(about|file):.*/)) {
|
||||
return nativeopen(address)
|
||||
}
|
||||
|
||||
return activeTabContainerId().then(containerId => {
|
||||
let args = { active } as any
|
||||
const args = { active } as any
|
||||
// Ensure -c has priority.
|
||||
if (container) {
|
||||
args.cookieStoreId = container
|
||||
|
@ -2051,7 +2051,7 @@ export async function tabclosealltoright() {
|
|||
})
|
||||
|
||||
const atab = await activeTab()
|
||||
let ids = tabs.filter(tab => tab.index > atab.index).map(tab => tab.id)
|
||||
const ids = tabs.filter(tab => tab.index > atab.index).map(tab => tab.id)
|
||||
browser.tabs.remove(ids)
|
||||
}
|
||||
|
||||
|
@ -2066,7 +2066,7 @@ export async function tabclosealltoleft() {
|
|||
})
|
||||
|
||||
const atab = await activeTab()
|
||||
let ids = tabs.filter(tab => tab.index < atab.index).map(tab => tab.id)
|
||||
const ids = tabs.filter(tab => tab.index < atab.index).map(tab => tab.id)
|
||||
browser.tabs.remove(ids)
|
||||
}
|
||||
|
||||
|
@ -2204,7 +2204,7 @@ export async function tabmove(index = "$") {
|
|||
/** Pin the current tab */
|
||||
//#background
|
||||
export async function pin() {
|
||||
let aTab = await activeTab()
|
||||
const aTab = await activeTab()
|
||||
browser.tabs.update(aTab.id, { pinned: !aTab.pinned })
|
||||
}
|
||||
|
||||
|
@ -2221,7 +2221,7 @@ export async function mute(...muteArgs: string[]): Promise<void> {
|
|||
let toggle = false
|
||||
let all = false
|
||||
|
||||
let argParse = (args: string[]) => {
|
||||
const argParse = (args: string[]) => {
|
||||
if (args === null) {
|
||||
return
|
||||
}
|
||||
|
@ -2244,20 +2244,20 @@ export async function mute(...muteArgs: string[]): Promise<void> {
|
|||
|
||||
argParse(muteArgs)
|
||||
|
||||
let updateObj = { muted: false }
|
||||
const updateObj = { muted: false }
|
||||
if (mute) {
|
||||
updateObj.muted = true
|
||||
}
|
||||
if (all) {
|
||||
let tabs = await browser.tabs.query({ currentWindow: true })
|
||||
for (let tab of tabs) {
|
||||
const tabs = await browser.tabs.query({ currentWindow: true })
|
||||
for (const tab of tabs) {
|
||||
if (toggle) {
|
||||
updateObj.muted = !tab.mutedInfo.muted
|
||||
}
|
||||
browser.tabs.update(tab.id, updateObj)
|
||||
}
|
||||
} else {
|
||||
let tab = await activeTab()
|
||||
const tab = await activeTab()
|
||||
if (toggle) {
|
||||
updateObj.muted = !tab.mutedInfo.muted
|
||||
}
|
||||
|
@ -2300,7 +2300,7 @@ export async function winopen(...args: string[]) {
|
|||
}
|
||||
}
|
||||
|
||||
let address = args.join(" ")
|
||||
const address = args.join(" ")
|
||||
if (!ABOUT_WHITELIST.includes(address) && address.match(/^(about|file):.*/)) {
|
||||
return nativeopen(firefoxArgs, address)
|
||||
}
|
||||
|
@ -2328,7 +2328,7 @@ export async function winclose(...ids: string[]) {
|
|||
// We might have to do it ourselves.
|
||||
//#background
|
||||
export async function qall() {
|
||||
let windows = await browser.windows.getAll()
|
||||
const windows = await browser.windows.getAll()
|
||||
windows.forEach(window => browser.windows.remove(window.id))
|
||||
}
|
||||
|
||||
|
@ -2341,7 +2341,7 @@ export async function qall() {
|
|||
*/
|
||||
//#background
|
||||
export async function containerclose(name: string) {
|
||||
let containerId = await Container.getId(name)
|
||||
const containerId = await Container.getId(name)
|
||||
browser.tabs.query({ cookieStoreId: containerId }).then(tabs => {
|
||||
browser.tabs.remove(
|
||||
tabs.map(tab => {
|
||||
|
@ -2393,8 +2393,8 @@ export async function containerdelete(name: string) {
|
|||
//#background
|
||||
export async function containerupdate(name: string, uname: string, ucolor: string, uicon: string) {
|
||||
logger.debug("containerupdate parameters: " + name + ", " + uname + ", " + ucolor + ", " + uicon)
|
||||
let containerId = await Container.fuzzyMatch(name)
|
||||
let containerObj = Container.fromString(uname, ucolor, uicon)
|
||||
const containerId = await Container.fuzzyMatch(name)
|
||||
const containerObj = Container.fromString(uname, ucolor, uicon)
|
||||
await Container.update(containerId, containerObj)
|
||||
}
|
||||
|
||||
|
@ -2407,7 +2407,7 @@ export async function containerupdate(name: string, uname: string, ucolor: strin
|
|||
export async function viewcontainers() {
|
||||
// # and white space don't agree with FF's JSON viewer.
|
||||
// Probably other symbols too.
|
||||
let containers = await browserBg.contextualIdentities.query({}) // Can't access src/lib/containers.ts from a content script.
|
||||
const containers = await browserBg.contextualIdentities.query({}) // Can't access src/lib/containers.ts from a content script.
|
||||
window.location.href =
|
||||
"data:application/json," +
|
||||
JSON.stringify(containers)
|
||||
|
@ -2528,15 +2528,15 @@ export async function composite(...cmds: string[]) {
|
|||
.reduce(
|
||||
async (prev_pipeline, cmd) => {
|
||||
await prev_pipeline
|
||||
let cmds = cmd.split("|")
|
||||
const cmds = cmd.split("|")
|
||||
|
||||
// Compute the first piped value
|
||||
let [fn, args] = excmd_parser.parser(cmds[0])
|
||||
let first_value = fn.call({}, ...args)
|
||||
const [fn, args] = excmd_parser.parser(cmds[0])
|
||||
const first_value = fn.call({}, ...args)
|
||||
|
||||
// Exec the rest of the pipe in sequence.
|
||||
return cmds.slice(1).reduce(async (pipedValue, cmd) => {
|
||||
let [fn, args] = excmd_parser.parser(cmd)
|
||||
const [fn, args] = excmd_parser.parser(cmd)
|
||||
return fn.call({}, ...args, await pipedValue)
|
||||
}, first_value)
|
||||
},
|
||||
|
@ -2577,7 +2577,7 @@ export function hidecmdline() {
|
|||
/** Set the current value of the commandline to string *with* a trailing space */
|
||||
//#content
|
||||
export function fillcmdline(...strarr: string[]) {
|
||||
let str = strarr.join(" ")
|
||||
const str = strarr.join(" ")
|
||||
showcmdline()
|
||||
return Messaging.messageOwnTab("commandline_frame", "fillcmdline", [str])
|
||||
}
|
||||
|
@ -2585,7 +2585,7 @@ export function fillcmdline(...strarr: string[]) {
|
|||
/** Set the current value of the commandline to string *without* a trailing space */
|
||||
//#content
|
||||
export function fillcmdline_notrail(...strarr: string[]) {
|
||||
let str = strarr.join(" ")
|
||||
const str = strarr.join(" ")
|
||||
showcmdline()
|
||||
return Messaging.messageOwnTab("commandline_frame", "fillcmdline", [str, false])
|
||||
}
|
||||
|
@ -2600,7 +2600,7 @@ export function fillcmdline_nofocus(...strarr: string[]) {
|
|||
/** Shows str in the command line for ms milliseconds. Recommended duration: 3000ms. */
|
||||
//#content
|
||||
export async function fillcmdline_tmp(ms: number, ...strarr: string[]) {
|
||||
let str = strarr.join(" ")
|
||||
const str = strarr.join(" ")
|
||||
showcmdline(false)
|
||||
Messaging.messageOwnTab("commandline_frame", "fillcmdline", [strarr.join(" "), false, false])
|
||||
return new Promise(resolve =>
|
||||
|
@ -2632,14 +2632,14 @@ import * as tri_editor from "@src/lib/editor"
|
|||
|
||||
//#content_helper
|
||||
// {
|
||||
for (let editorfn of Object.keys(tri_editor)) {
|
||||
for (const editorfn of Object.keys(tri_editor)) {
|
||||
// Re-expose every editor function as a text.$fn excmd that will forward the call to $fn to the commandline frame if it is selected or apply $fn to the last used input if it isn't
|
||||
SELF["text." + editorfn] = arg => {
|
||||
if ((document.activeElement as any).src === browser.extension.getURL("static/commandline.html")) return Messaging.messageOwnTab("commandline_frame", "editor_function", [editorfn].concat(arg))
|
||||
return tri_editor[editorfn](DOM.getLastUsedInput(), arg)
|
||||
}
|
||||
}
|
||||
for (let fn of Object.keys(cmdframe_fns)) {
|
||||
for (const fn of Object.keys(cmdframe_fns)) {
|
||||
SELF["ex." + fn] = (...args) => (Messaging.messageOwnTab as any)("commandline_frame", cmdframe_fns[fn][0], cmdframe_fns[fn][1].concat(args))
|
||||
}
|
||||
|
||||
|
@ -2647,12 +2647,12 @@ for (let fn of Object.keys(cmdframe_fns)) {
|
|||
|
||||
//#background_helper
|
||||
// {
|
||||
for (let editorfn of Object.keys(tri_editor)) {
|
||||
let name = "text." + editorfn
|
||||
for (const editorfn of Object.keys(tri_editor)) {
|
||||
const name = "text." + editorfn
|
||||
cmd_params.set(name, new Map([["arr", "string[]"]]))
|
||||
BGSELF[name] = (...args) => messageActiveTab("excmd_content", name, args)
|
||||
}
|
||||
for (let fn of Object.keys(cmdframe_fns)) {
|
||||
for (const fn of Object.keys(cmdframe_fns)) {
|
||||
cmd_params.set("ex." + fn, new Map(cmdframe_fns[fn][1].map((a, i) => [`${i}`, typeof a] as [string, string])))
|
||||
BGSELF["ex." + fn] = (...args) => messageActiveTab("commandline_frame", cmdframe_fns[fn][0], cmdframe_fns[fn][1].concat(args))
|
||||
}
|
||||
|
@ -2684,8 +2684,8 @@ async function setclip(str) {
|
|||
// Functions to avoid retyping everything everywhere
|
||||
|
||||
// Note: We're using fillcmdline here because exceptions are somehow not caught. We're rethrowing because otherwise the error message will be overwritten with the "yank successful" message.
|
||||
let s = () => Native.clipboard("set", str)
|
||||
let c = () => messageActiveTab("commandline_frame", "setClipboard", [str])
|
||||
const s = () => Native.clipboard("set", str)
|
||||
const c = () => messageActiveTab("commandline_frame", "setClipboard", [str])
|
||||
|
||||
let promises = []
|
||||
switch (await config.getAsync("yankto")) {
|
||||
|
@ -2824,14 +2824,14 @@ export async function tab(index: number | "#") {
|
|||
*/
|
||||
//#background
|
||||
export async function taball(id: string) {
|
||||
let windows = (await browser.windows.getAll()).map(w => w.id).sort((a, b) => a - b)
|
||||
const windows = (await browser.windows.getAll()).map(w => w.id).sort((a, b) => a - b)
|
||||
if (id === null || id === undefined || !id.match(/\d+\.\d+/)) {
|
||||
const tab = await activeTab()
|
||||
let prevId = id
|
||||
const prevId = id
|
||||
id = windows.indexOf(tab.windowId) + "." + (tab.index + 1)
|
||||
logger.info(`taball: Bad tab id: ${prevId}, defaulting to ${id}`)
|
||||
}
|
||||
let [winindex, tabindex] = id.split(".")
|
||||
const [winindex, tabindex] = id.split(".")
|
||||
await browser.windows.update(windows[parseInt(winindex, 10) - 1], { focused: true })
|
||||
return browser.tabs.update(await idFromIndex(tabindex), { active: true })
|
||||
}
|
||||
|
@ -2901,14 +2901,14 @@ interface bind_args {
|
|||
function parse_bind_args(...args: string[]): bind_args {
|
||||
if (args.length === 0) throw new Error("Invalid bind/unbind arguments.")
|
||||
|
||||
let result = {} as bind_args
|
||||
const result = {} as bind_args
|
||||
result.mode = "normal"
|
||||
|
||||
// TODO: This mapping is copy-pasted in controller_content.ts,
|
||||
// where it constructs the list of parsers. it should be
|
||||
// centralized, possibly as part of rewrite for content-local maps
|
||||
// and similar.
|
||||
let mode2maps = new Map([["normal", "nmaps"], ["ignore", "ignoremaps"], ["insert", "imaps"], ["input", "inputmaps"], ["ex", "exmaps"]])
|
||||
const mode2maps = new Map([["normal", "nmaps"], ["ignore", "ignoremaps"], ["insert", "imaps"], ["input", "inputmaps"], ["ex", "exmaps"]])
|
||||
if (args[0].startsWith("--mode=")) {
|
||||
result.mode = args.shift().replace("--mode=", "")
|
||||
}
|
||||
|
@ -2916,7 +2916,7 @@ function parse_bind_args(...args: string[]): bind_args {
|
|||
|
||||
result.configName = mode2maps.get(result.mode)
|
||||
|
||||
let key = args.shift()
|
||||
const key = args.shift()
|
||||
// Convert key to internal representation
|
||||
result.key = mapstrToKeyseq(key)
|
||||
.map(k => k.toMapstr())
|
||||
|
@ -2962,12 +2962,12 @@ function parse_bind_args(...args: string[]): bind_args {
|
|||
*/
|
||||
//#background
|
||||
export function bind(...args: string[]) {
|
||||
let args_obj = parse_bind_args(...args)
|
||||
const args_obj = parse_bind_args(...args)
|
||||
let p = Promise.resolve()
|
||||
if (args_obj.excmd !== "") {
|
||||
for (let i = 0; i < args_obj.key.length; i++) {
|
||||
// Check if any initial subsequence of the key exists and will shadow the new binding
|
||||
let key_sub = args_obj.key.slice(0, i)
|
||||
const key_sub = args_obj.key.slice(0, i)
|
||||
if (config.get(args_obj.configName, key_sub)) {
|
||||
fillcmdline_notrail("# Warning: bind `" + key_sub + "` exists and will shadow `" + args_obj.key + "`. Try running `:unbind --mode=" + args_obj.mode + " " + key_sub + "`")
|
||||
break
|
||||
|
@ -2992,7 +2992,7 @@ export function bind(...args: string[]) {
|
|||
*/
|
||||
//#background
|
||||
export function bindurl(pattern: string, mode: string, keys: string, ...excmd: string[]) {
|
||||
let args_obj = parse_bind_args(mode, keys, ...excmd)
|
||||
const args_obj = parse_bind_args(mode, keys, ...excmd)
|
||||
let p = Promise.resolve()
|
||||
if (args_obj.excmd !== "") {
|
||||
p = config.setURL(pattern, args_obj.configName, args_obj.key, args_obj.excmd)
|
||||
|
@ -3030,9 +3030,9 @@ function validateSetArgs(key: string, values: string[]) {
|
|||
const target: any[] = key.split(".")
|
||||
|
||||
let value
|
||||
let file = Metadata.everything.getFile("src/lib/config.ts")
|
||||
let default_config = file.getClass("default_config")
|
||||
let md = default_config.getMember(target[0])
|
||||
const file = Metadata.everything.getFile("src/lib/config.ts")
|
||||
const default_config = file.getClass("default_config")
|
||||
const md = default_config.getMember(target[0])
|
||||
if (md !== undefined) {
|
||||
const strval = values.join(" ")
|
||||
// Note: the conversion will throw if strval can't be converted to the right type
|
||||
|
@ -3107,7 +3107,7 @@ export function set(key: string, ...values: string[]) {
|
|||
}
|
||||
|
||||
if (key === "noiframeon") {
|
||||
let noiframes = config.get("noiframeon")
|
||||
const noiframes = config.get("noiframeon")
|
||||
// unset previous settings
|
||||
if (noiframes) noiframes.forEach(url => seturl(url, "noiframe", "false"))
|
||||
// store new settings
|
||||
|
@ -3122,7 +3122,7 @@ export function set(key: string, ...values: string[]) {
|
|||
|
||||
/** @hidden */
|
||||
//#background_helper
|
||||
let AUCMDS = ["DocStart", "DocLoad", "DocEnd", "TriStart", "TabEnter", "TabLeft", "FullscreenChange", "FullscreenEnter", "FullscreenLeft"]
|
||||
const AUCMDS = ["DocStart", "DocLoad", "DocEnd", "TriStart", "TabEnter", "TabLeft", "FullscreenChange", "FullscreenEnter", "FullscreenLeft"]
|
||||
/** Set autocmds to run when certain events happen.
|
||||
|
||||
@param event Curently, 'TriStart', 'DocStart', 'DocLoad', 'DocEnd', 'TabEnter', 'TabLeft', 'FullscreenChange', 'FullscreenEnter', and 'FullscreenLeft' are supported
|
||||
|
@ -3203,7 +3203,7 @@ export function blacklistadd(url: string) {
|
|||
*/
|
||||
//#background
|
||||
export async function unbind(...args: string[]) {
|
||||
let args_obj = parse_bind_args(...args)
|
||||
const args_obj = parse_bind_args(...args)
|
||||
if (args_obj.excmd !== "") throw new Error("unbind syntax: `unbind key`")
|
||||
|
||||
return config.set(args_obj.configName, args_obj.key, "")
|
||||
|
@ -3224,7 +3224,7 @@ export async function unbind(...args: string[]) {
|
|||
*/
|
||||
//#background
|
||||
export async function unbindurl(pattern: string, mode: string, keys: string) {
|
||||
let args_obj = parse_bind_args(mode, keys)
|
||||
const args_obj = parse_bind_args(mode, keys)
|
||||
|
||||
return config.setURL(pattern, args_obj.configName, args_obj.key, "")
|
||||
}
|
||||
|
@ -3241,7 +3241,7 @@ export async function unbindurl(pattern: string, mode: string, keys: string) {
|
|||
*/
|
||||
//#background
|
||||
export async function reset(mode: string, key: string) {
|
||||
let args_obj = parse_bind_args(mode, key)
|
||||
const args_obj = parse_bind_args(mode, key)
|
||||
return config.unset(args_obj.configName, args_obj.key)
|
||||
}
|
||||
|
||||
|
@ -3259,7 +3259,7 @@ export async function reset(mode: string, key: string) {
|
|||
*/
|
||||
//#background
|
||||
export async function reseturl(pattern: string, mode: string, key: string) {
|
||||
let args_obj = parse_bind_args(mode, key)
|
||||
const args_obj = parse_bind_args(mode, key)
|
||||
return config.unsetURL(pattern, args_obj.configName, args_obj.key)
|
||||
}
|
||||
|
||||
|
@ -3288,12 +3288,12 @@ export async function reseturl(pattern: string, mode: string, key: string) {
|
|||
*/
|
||||
//#background
|
||||
export async function sanitise(...args: string[]) {
|
||||
let flagpos = args.indexOf("-t")
|
||||
const flagpos = args.indexOf("-t")
|
||||
let since = {}
|
||||
// If the -t flag has been given and there is an arg after it
|
||||
if (flagpos > -1) {
|
||||
if (flagpos < args.length - 1) {
|
||||
let match = args[flagpos + 1].match("^([0-9])+(m|h|d|w)$")
|
||||
const match = args[flagpos + 1].match("^([0-9])+(m|h|d|w)$")
|
||||
// If the arg of the flag matches Pentadactyl's sanitisetimespan format
|
||||
if (match !== null && match.length === 3) {
|
||||
// Compute the timespan in milliseconds and get a Date object
|
||||
|
@ -3317,7 +3317,7 @@ export async function sanitise(...args: string[]) {
|
|||
}
|
||||
}
|
||||
|
||||
let dts = {
|
||||
const dts = {
|
||||
cache: false,
|
||||
cookies: false,
|
||||
downloads: false,
|
||||
|
@ -3341,7 +3341,7 @@ export async function sanitise(...args: string[]) {
|
|||
*/
|
||||
}
|
||||
if (args.find(x => x === "all") !== undefined) {
|
||||
for (let attr in dts) dts[attr] = true
|
||||
for (const attr in dts) dts[attr] = true
|
||||
} else {
|
||||
// We bother checking if dts[x] is false because
|
||||
// browser.browsingData.remove() is very strict on the format of the
|
||||
|
@ -3378,14 +3378,14 @@ export async function quickmark(key: string, ...addressarr: string[]) {
|
|||
}
|
||||
|
||||
if (addressarr.length <= 1) {
|
||||
let address = addressarr.length === 0 ? (await activeTab()).url : addressarr[0]
|
||||
const address = addressarr.length === 0 ? (await activeTab()).url : addressarr[0]
|
||||
// Have to await these or they race!
|
||||
await bind("gn" + key, "tabopen", address)
|
||||
await bind("go" + key, "open", address)
|
||||
await bind("gw" + key, "winopen", address)
|
||||
} else {
|
||||
let compstring = addressarr.join(" | tabopen ")
|
||||
let compstringwin = addressarr.join(" | winopen ")
|
||||
const compstring = addressarr.join(" | tabopen ")
|
||||
const compstringwin = addressarr.join(" | winopen ")
|
||||
await bind("gn" + key, "composite tabopen", compstring)
|
||||
await bind("go" + key, "composite open", compstring)
|
||||
await bind("gw" + key, "composite winopen", compstringwin)
|
||||
|
@ -3559,8 +3559,8 @@ export async function hint(option?: string, selectors?: string, ...rest: string[
|
|||
}
|
||||
|
||||
let selectHints
|
||||
let hintTabOpen = async (href, active = !rapid) => {
|
||||
let containerId = await activeTabContainerId()
|
||||
const hintTabOpen = async (href, active = !rapid) => {
|
||||
const containerId = await activeTabContainerId()
|
||||
if (containerId) {
|
||||
return openInNewTab(href, {
|
||||
active,
|
||||
|
@ -3642,7 +3642,7 @@ export async function hint(option?: string, selectors?: string, ...rest: string[
|
|||
selectHints = hinting.pipe_elements(
|
||||
DOM.anchors(),
|
||||
link => {
|
||||
let anchorUrl = new URL(window.location.href)
|
||||
const anchorUrl = new URL(window.location.href)
|
||||
// ???: What purpose does selecting elements with a name attribute have? Selecting values that only have meaning in forms doesn't seem very useful.
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
|
||||
anchorUrl.hash = link.id || link.name
|
||||
|
@ -3859,7 +3859,7 @@ import * as TTS from "@src/lib/text_to_speech"
|
|||
*/
|
||||
//#content_helper
|
||||
function tssReadFromCss(selector: string): void {
|
||||
let elems = DOM.getElemsBySelector(selector, [])
|
||||
const elems = DOM.getElemsBySelector(selector, [])
|
||||
|
||||
elems.forEach(e => {
|
||||
TTS.readText(e.textContent)
|
||||
|
@ -3896,7 +3896,7 @@ export async function ttsread(mode: "-t" | "-c", ...args: string[]) {
|
|||
*/
|
||||
//#background
|
||||
export async function ttsvoices() {
|
||||
let voices = TTS.listVoices()
|
||||
const voices = TTS.listVoices()
|
||||
voices.sort()
|
||||
// need a better way to show this to the user
|
||||
fillcmdline_notrail("#", voices.join(", "))
|
||||
|
@ -3961,7 +3961,7 @@ export function buildFilterConfigs(filters: string[]): Perf.StatsFilterConfig[]
|
|||
*/
|
||||
//#background
|
||||
export async function perfdump(...filters: string[]) {
|
||||
let filterconfigs = buildFilterConfigs(filters)
|
||||
const filterconfigs = buildFilterConfigs(filters)
|
||||
const entries = window.tri.statsLogger.getEntries(...filterconfigs)
|
||||
console.log(filterconfigs)
|
||||
open("data:application/json;charset=UTF-8," + JSON.stringify(entries))
|
||||
|
@ -3977,7 +3977,7 @@ export async function perfdump(...filters: string[]) {
|
|||
*/
|
||||
//#background
|
||||
export async function perfhistogram(...filters: string[]) {
|
||||
let filterconfigs = buildFilterConfigs(filters)
|
||||
const filterconfigs = buildFilterConfigs(filters)
|
||||
filterconfigs.push({ kind: "eventType", eventType: "measure" })
|
||||
const entries = window.tri.statsLogger.getEntries(...filterconfigs)
|
||||
if (entries.length === 0) {
|
||||
|
@ -4057,7 +4057,7 @@ export async function echo(...str: string[]) {
|
|||
export async function js(...str: string[]) {
|
||||
if (str[0].startsWith("-p")) {
|
||||
/* tslint:disable:no-dead-store */
|
||||
let JS_ARG = str[str.length - 1]
|
||||
const JS_ARG = str[str.length - 1]
|
||||
return eval(str.slice(1, -1).join(" "))
|
||||
} else {
|
||||
return eval(str.join(" "))
|
||||
|
@ -4071,7 +4071,7 @@ export async function js(...str: string[]) {
|
|||
export async function jsb(...str: string[]) {
|
||||
if (str[0].startsWith("-p")) {
|
||||
/* tslint:disable:no-dead-store */
|
||||
let JS_ARG = str[str.length - 1]
|
||||
const JS_ARG = str[str.length - 1]
|
||||
return eval(str.slice(1, -1).join(" "))
|
||||
} else {
|
||||
return eval(str.join(" "))
|
||||
|
|
32
src/help.ts
32
src/help.ts
|
@ -29,7 +29,7 @@ function getCommandElements() {
|
|||
".tsd-panel.tsd-member.tsd-kind-function.tsd-parent-kind-external-module",
|
||||
),
|
||||
).reduce((all, elem) => {
|
||||
let fnName = Array.from(elem.children).find(e => e.tagName === "H3")
|
||||
const fnName = Array.from(elem.children).find(e => e.tagName === "H3")
|
||||
if (fnName) all[fnName.textContent] = elem
|
||||
return all
|
||||
}, {})
|
||||
|
@ -37,12 +37,12 @@ function getCommandElements() {
|
|||
|
||||
/** Update the doc with aliases fetched from the config */
|
||||
async function addSetting(settingName: string) {
|
||||
let commandElems = getCommandElements()
|
||||
const commandElems = getCommandElements()
|
||||
// We're ignoring composite because it combines multiple excmds
|
||||
delete (commandElems as any).composite
|
||||
|
||||
// Initialize or reset the <p> element that will contain settings in each commandElem
|
||||
let settingElems = Object.keys(commandElems).reduce(
|
||||
const settingElems = Object.keys(commandElems).reduce(
|
||||
(settingElems, cmdName) => {
|
||||
settingElems[cmdName] = initTridactylSettingElem(
|
||||
commandElems[cmdName],
|
||||
|
@ -53,9 +53,9 @@ async function addSetting(settingName: string) {
|
|||
{},
|
||||
)
|
||||
|
||||
let settings = await config.getAsync(settingName)
|
||||
const settings = await config.getAsync(settingName)
|
||||
// For each setting
|
||||
for (let setting of Object.keys(settings)) {
|
||||
for (const setting of Object.keys(settings)) {
|
||||
let excmd = settings[setting].split(" ")
|
||||
// How can we automatically detect what commands can be skipped?
|
||||
excmd = ["composite", "fillcmdline", "current_url"].includes(excmd[0])
|
||||
|
@ -71,7 +71,7 @@ async function addSetting(settingName: string) {
|
|||
|
||||
// If there is an HTML element for settings that correspond to the excmd we just found
|
||||
if (settingElems[excmd]) {
|
||||
let settingSpan = document.createElement("span")
|
||||
const settingSpan = document.createElement("span")
|
||||
settingSpan.innerText = setting
|
||||
settingSpan.title = settings[setting]
|
||||
// Add the setting to the element
|
||||
|
@ -127,8 +127,8 @@ function addSettingInputs() {
|
|||
const inputClassNameModified =
|
||||
inputClassName + " TridactylSettingInputModified "
|
||||
|
||||
let onKeyUp = async ev => {
|
||||
let input = ev.target
|
||||
const onKeyUp = async ev => {
|
||||
const input = ev.target
|
||||
if (ev.key === "Enter") {
|
||||
(window as any).tri.messaging.message(
|
||||
"controller_background",
|
||||
|
@ -147,10 +147,10 @@ function addSettingInputs() {
|
|||
return Promise.all(
|
||||
Array.from(document.querySelectorAll("a.tsd-anchor")).map(
|
||||
async (a: HTMLAnchorElement) => {
|
||||
let section = a.parentNode
|
||||
const section = a.parentNode
|
||||
|
||||
let settingName = a.name.split(".")
|
||||
let value = await config.getAsync(settingName)
|
||||
const settingName = a.name.split(".")
|
||||
const value = await config.getAsync(settingName)
|
||||
if (!value) return console.log("Failed to grab value of ", a)
|
||||
if (!["number", "boolean", "string"].includes(typeof value))
|
||||
return console.log(
|
||||
|
@ -160,14 +160,14 @@ function addSettingInputs() {
|
|||
" because not easily represented as string",
|
||||
)
|
||||
|
||||
let input = document.createElement("input")
|
||||
const input = document.createElement("input")
|
||||
input.name = a.name
|
||||
input.value = value
|
||||
input.id = "TridactylSettingInput_" + input.name
|
||||
input.className = inputClassName
|
||||
input.addEventListener("keyup", onKeyUp)
|
||||
|
||||
let div = document.createElement("div")
|
||||
const div = document.createElement("div")
|
||||
div.appendChild(document.createTextNode("Current value:"))
|
||||
div.appendChild(input)
|
||||
|
||||
|
@ -189,13 +189,13 @@ function addSettingInputs() {
|
|||
}
|
||||
|
||||
function addResetConfigButton() {
|
||||
let button = document.createElement("button")
|
||||
const button = document.createElement("button")
|
||||
button.innerText = "Reset Tridactyl config"
|
||||
button.style.margin = "auto 50%"
|
||||
button.style.minWidth = "200pt"
|
||||
button.addEventListener("click", () => {
|
||||
let sentence = "sanitise tridactylsync tridactyllocal tridactylhistory"
|
||||
let p = prompt(
|
||||
const sentence = "sanitise tridactylsync tridactyllocal tridactylhistory"
|
||||
const p = prompt(
|
||||
`Please write '${sentence}' without quotes in the following input field if you really want to reset your Tridactyl config.`,
|
||||
)
|
||||
if (p === sentence) {
|
||||
|
|
|
@ -44,11 +44,11 @@ export function expandExstr(
|
|||
export function getCmdAliasMapping(
|
||||
aliases = config.get("exaliases"),
|
||||
): { [str: string]: string[] } {
|
||||
let commands = {}
|
||||
const commands = {}
|
||||
// aliases look like this: {alias: command} but what we really need is this: {command: [alias1, alias2...]}
|
||||
// This is what this loop builds
|
||||
for (let alias of Object.keys(aliases)) {
|
||||
let cmd = expandExstr(alias, aliases).trim()
|
||||
for (const alias of Object.keys(aliases)) {
|
||||
const cmd = expandExstr(alias, aliases).trim()
|
||||
if (!commands[cmd]) commands[cmd] = []
|
||||
commands[cmd].push(alias.trim())
|
||||
}
|
||||
|
|
|
@ -72,18 +72,18 @@ export class AutoContain implements IAutoContain {
|
|||
details: IDetails,
|
||||
): Promise<browser.webRequest.BlockingResponse> => {
|
||||
// No autocontain directives, no nothing.
|
||||
let aucons = Config.get("autocontain")
|
||||
const aucons = Config.get("autocontain")
|
||||
if (Object.keys(aucons).length === 0) return { cancel: false }
|
||||
|
||||
// Do not handle private tabs or invalid tabIds.
|
||||
if (details.tabId === -1) return { cancel: false }
|
||||
let tab = await browser.tabs.get(details.tabId)
|
||||
const tab = await browser.tabs.get(details.tabId)
|
||||
if (tab.incognito) return { cancel: false }
|
||||
|
||||
// Only handle http requests.
|
||||
if (details.url.search("^https?://") < 0) return { cancel: false }
|
||||
|
||||
let cookieStoreId = await this.parseAucons(details)
|
||||
const cookieStoreId = await this.parseAucons(details)
|
||||
|
||||
// Silently return if we're already in the correct container.
|
||||
if (tab.cookieStoreId === cookieStoreId) return { cancel: false }
|
||||
|
@ -160,7 +160,7 @@ export class AutoContain implements IAutoContain {
|
|||
|
||||
// Parses autocontain directives and returns valid cookieStoreIds or errors.
|
||||
parseAucons = async (details): Promise<string> => {
|
||||
let aucons = Config.get("autocontain")
|
||||
const aucons = Config.get("autocontain")
|
||||
const ausites = Object.keys(aucons)
|
||||
const aukeyarr = ausites.filter(
|
||||
e => details.url.search("^https?://[^/]*" + e + "/") >= 0,
|
||||
|
@ -173,7 +173,7 @@ export class AutoContain implements IAutoContain {
|
|||
} else if (aukeyarr.length === 0) {
|
||||
return "firefox-default"
|
||||
} else {
|
||||
let containerExists = await Container.exists(aucons[aukeyarr[0]])
|
||||
const containerExists = await Container.exists(aucons[aukeyarr[0]])
|
||||
if (!containerExists) {
|
||||
if (Config.get("auconcreatecontainer")) {
|
||||
await Container.create(aucons[aukeyarr[0]])
|
||||
|
|
|
@ -904,7 +904,7 @@ function setDeepProperty(obj, value, target) {
|
|||
* Merges two objects and any child objects they may have
|
||||
*/
|
||||
export function mergeDeep(o1, o2) {
|
||||
let r = Array.isArray(o1) ? o1.slice() : Object.create(o1)
|
||||
const r = Array.isArray(o1) ? o1.slice() : Object.create(o1)
|
||||
Object.assign(r, o1, o2)
|
||||
if (o2 === undefined) return r
|
||||
Object.keys(o1)
|
||||
|
@ -938,7 +938,7 @@ export function getURL(url: string, target: string[]) {
|
|||
// Merge their corresponding value if they're objects, otherwise return the last value
|
||||
.reduce(
|
||||
(acc, curKey) => {
|
||||
let curVal = getDeepProperty(
|
||||
const curVal = getDeepProperty(
|
||||
USERCONFIG.subconfigs[curKey],
|
||||
target,
|
||||
)
|
||||
|
@ -1049,7 +1049,7 @@ export function unset(...target) {
|
|||
export async function save(storage: "local" | "sync" = get("storageloc")) {
|
||||
// let storageobj = storage === "local" ? browser.storage.local : browser.storage.sync
|
||||
// storageobj.set({CONFIGNAME: USERCONFIG})
|
||||
let settingsobj = o({})
|
||||
const settingsobj = o({})
|
||||
settingsobj[CONFIGNAME] = USERCONFIG
|
||||
return storage === "local"
|
||||
? browser.storage.local.set(settingsobj)
|
||||
|
@ -1068,12 +1068,12 @@ export async function save(storage: "local" | "sync" = get("storageloc")) {
|
|||
*/
|
||||
export async function update() {
|
||||
// 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)
|
||||
const updateAll = (setting: any[], fn: (any) => any) => {
|
||||
const val = getDeepProperty(USERCONFIG, setting)
|
||||
if (val) {
|
||||
set(...setting, fn(val))
|
||||
}
|
||||
let subconfigs = getDeepProperty(USERCONFIG, ["subconfigs"])
|
||||
const subconfigs = getDeepProperty(USERCONFIG, ["subconfigs"])
|
||||
if (subconfigs) {
|
||||
Object.keys(subconfigs)
|
||||
.map(pattern => [pattern, getURL(pattern, setting)])
|
||||
|
@ -1084,12 +1084,12 @@ export async function update() {
|
|||
}
|
||||
}
|
||||
|
||||
let updaters = {
|
||||
const updaters = {
|
||||
"0.0": async () => {
|
||||
try {
|
||||
// Before we had a config system, we had nmaps, and we put them in the
|
||||
// root namespace because we were young and bold.
|
||||
let legacy_nmaps = await browser.storage.sync.get("nmaps")
|
||||
const legacy_nmaps = await browser.storage.sync.get("nmaps")
|
||||
if (Object.keys(legacy_nmaps).length > 0) {
|
||||
USERCONFIG.nmaps = Object.assign(
|
||||
legacy_nmaps.nmaps,
|
||||
|
@ -1101,7 +1101,7 @@ export async function update() {
|
|||
}
|
||||
},
|
||||
"1.0": () => {
|
||||
let vimiumgi = getDeepProperty(USERCONFIG, ["vimium-gi"])
|
||||
const vimiumgi = getDeepProperty(USERCONFIG, ["vimium-gi"])
|
||||
if (vimiumgi === true || vimiumgi === "true")
|
||||
set("gimode", "nextinput")
|
||||
else if (vimiumgi === false || vimiumgi === "false")
|
||||
|
@ -1110,14 +1110,14 @@ export async function update() {
|
|||
set("configversion", "1.1")
|
||||
},
|
||||
"1.1": () => {
|
||||
let leveltostr: { [key: number]: LoggingLevel } = {
|
||||
const leveltostr: { [key: number]: LoggingLevel } = {
|
||||
0: "never",
|
||||
1: "error",
|
||||
2: "warning",
|
||||
3: "info",
|
||||
4: "debug",
|
||||
}
|
||||
let logging = getDeepProperty(USERCONFIG, ["logging"])
|
||||
const logging = getDeepProperty(USERCONFIG, ["logging"])
|
||||
// logging is not necessarily defined if the user didn't change default values
|
||||
if (logging)
|
||||
Object.keys(logging).forEach(l =>
|
||||
|
@ -1183,7 +1183,7 @@ export async function update() {
|
|||
set("configversion", "1.6")
|
||||
},
|
||||
"1.6": () => {
|
||||
let updateSetting = mapObj => {
|
||||
const updateSetting = mapObj => {
|
||||
if (!mapObj) return mapObj
|
||||
if (mapObj[" "] !== undefined) {
|
||||
mapObj["<Space>"] = mapObj[" "]
|
||||
|
@ -1202,7 +1202,7 @@ export async function update() {
|
|||
"<MS- >",
|
||||
].forEach(binding => {
|
||||
if (mapObj[binding] !== undefined) {
|
||||
let key = binding.replace(" ", "Space")
|
||||
const key = binding.replace(" ", "Space")
|
||||
mapObj[key] = mapObj[binding]
|
||||
delete mapObj[binding]
|
||||
}
|
||||
|
@ -1230,15 +1230,15 @@ export async function update() {
|
|||
@hidden
|
||||
*/
|
||||
async function init() {
|
||||
let syncConfig = await browser.storage.sync.get(CONFIGNAME)
|
||||
const syncConfig = await browser.storage.sync.get(CONFIGNAME)
|
||||
schlepp(syncConfig[CONFIGNAME])
|
||||
// Local storage overrides sync
|
||||
let localConfig = await browser.storage.local.get(CONFIGNAME)
|
||||
const localConfig = await browser.storage.local.get(CONFIGNAME)
|
||||
schlepp(localConfig[CONFIGNAME])
|
||||
|
||||
await update()
|
||||
INITIALISED = true
|
||||
for (let waiter of WAITERS) {
|
||||
for (const waiter of WAITERS) {
|
||||
waiter()
|
||||
}
|
||||
}
|
||||
|
@ -1269,9 +1269,9 @@ export function removeChangeListener<P extends keyof default_config>(
|
|||
name: P,
|
||||
listener: (old: default_config[P], neww: default_config[P]) => void,
|
||||
) {
|
||||
let arr = changeListeners.get(name)
|
||||
const arr = changeListeners.get(name)
|
||||
if (!arr) return
|
||||
let i = arr.indexOf(listener)
|
||||
const i = arr.indexOf(listener)
|
||||
if (i >= 0) arr.splice(i, 1)
|
||||
}
|
||||
|
||||
|
@ -1279,12 +1279,12 @@ export function removeChangeListener<P extends keyof default_config>(
|
|||
// TODO: BUG! Sync and local storage are merged at startup, but not by this thing.
|
||||
browser.storage.onChanged.addListener(async (changes, areaname) => {
|
||||
if (CONFIGNAME in changes) {
|
||||
let defaultConf = new default_config()
|
||||
const defaultConf = new default_config()
|
||||
|
||||
// newValue is undefined when calling browser.storage.AREANAME.clear()
|
||||
if (changes[CONFIGNAME].newValue !== undefined) {
|
||||
// A key has been :unset if it exists in USERCONFIG and doesn't in changes and if its value in USERCONFIG is different from the one it has in default_config
|
||||
let unsetKeys = Object.keys(USERCONFIG).filter(
|
||||
const unsetKeys = Object.keys(USERCONFIG).filter(
|
||||
k =>
|
||||
changes[CONFIGNAME].newValue[k] === undefined &&
|
||||
JSON.stringify(USERCONFIG[k]) !==
|
||||
|
@ -1292,7 +1292,7 @@ browser.storage.onChanged.addListener(async (changes, areaname) => {
|
|||
)
|
||||
|
||||
// A key has changed if it is defined in USERCONFIG and its value in USERCONFIG is different from the one in `changes` or if the value in defaultConf is different from the one in `changes`
|
||||
let changedKeys = Object.keys(changes[CONFIGNAME].newValue).filter(
|
||||
const changedKeys = Object.keys(changes[CONFIGNAME].newValue).filter(
|
||||
k =>
|
||||
JSON.stringify(
|
||||
USERCONFIG[k] !== undefined
|
||||
|
@ -1301,33 +1301,33 @@ browser.storage.onChanged.addListener(async (changes, areaname) => {
|
|||
) !== JSON.stringify(changes[CONFIGNAME].newValue[k]),
|
||||
)
|
||||
|
||||
let old = USERCONFIG
|
||||
const old = USERCONFIG
|
||||
USERCONFIG = changes[CONFIGNAME].newValue
|
||||
|
||||
// Trigger listeners
|
||||
unsetKeys.forEach(key => {
|
||||
let arr = changeListeners.get(key)
|
||||
const arr = changeListeners.get(key)
|
||||
if (arr) {
|
||||
arr.forEach(f => f(old[key], defaultConf[key]))
|
||||
}
|
||||
})
|
||||
|
||||
changedKeys.forEach(key => {
|
||||
let arr = changeListeners.get(key)
|
||||
const arr = changeListeners.get(key)
|
||||
if (arr) {
|
||||
let v = old[key] === undefined ? defaultConf[key] : old[key]
|
||||
const v = old[key] === undefined ? defaultConf[key] : old[key]
|
||||
arr.forEach(f => f(v, USERCONFIG[key]))
|
||||
}
|
||||
})
|
||||
} else if (areaname === (await get("storageloc"))) {
|
||||
// If newValue is undefined and AREANAME is the same value as STORAGELOC, the user wants to clean their config
|
||||
let old = USERCONFIG
|
||||
const old = USERCONFIG
|
||||
USERCONFIG = o({})
|
||||
|
||||
Object.keys(old)
|
||||
.filter(key => old[key] !== defaultConf[key])
|
||||
.forEach(key => {
|
||||
let arr = changeListeners.get(key)
|
||||
const arr = changeListeners.get(key)
|
||||
if (arr) {
|
||||
arr.forEach(f => f(old[key], defaultConf[key]))
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ export async function create(
|
|||
icon = "fingerprint",
|
||||
): Promise<string> {
|
||||
if (color === "random") color = chooseRandomColor()
|
||||
let container = fromString(name, color, icon)
|
||||
const container = fromString(name, color, icon)
|
||||
// browser.contextualIdentities.create does not accept a cookieStoreId property.
|
||||
delete container.cookieStoreId
|
||||
logger.debug(container)
|
||||
|
@ -57,7 +57,7 @@ export async function create(
|
|||
`[Container.create] container already exists, aborting.`,
|
||||
)
|
||||
} else {
|
||||
let res = await browser.contextualIdentities.create(container)
|
||||
const res = await browser.contextualIdentities.create(container)
|
||||
return res.cookieStoreId
|
||||
}
|
||||
}
|
||||
|
@ -67,8 +67,8 @@ export async function create(
|
|||
*/
|
||||
export async function remove(name: string) {
|
||||
logger.debug(name)
|
||||
let id = await getId(name)
|
||||
let res = await browser.contextualIdentities.remove(id)
|
||||
const id = await getId(name)
|
||||
const res = await browser.contextualIdentities.remove(id)
|
||||
logger.debug("[Container.remove] removed container:", res.cookieStoreId)
|
||||
}
|
||||
|
||||
|
@ -117,8 +117,8 @@ export async function getFromId(
|
|||
export async function exists(cname: string): Promise<boolean> {
|
||||
let exists = false
|
||||
try {
|
||||
let containers = await getAll()
|
||||
let res = containers.filter(c => {
|
||||
const containers = await getAll()
|
||||
const res = containers.filter(c => {
|
||||
return c.name.toLowerCase() === cname.toLowerCase()
|
||||
})
|
||||
if (res.length > 0) {
|
||||
|
@ -170,8 +170,8 @@ export async function getAll(): Promise<any[]> {
|
|||
*/
|
||||
export async function getId(name: string): Promise<string> {
|
||||
try {
|
||||
let containers = await getAll()
|
||||
let res = containers.filter(
|
||||
const containers = await getAll()
|
||||
const res = containers.filter(
|
||||
c => c.name.toLowerCase() === name.toLowerCase(),
|
||||
)
|
||||
if (res.length !== 1) {
|
||||
|
@ -191,7 +191,7 @@ export async function getId(name: string): Promise<string> {
|
|||
@param partialName The (partial) name of the container.
|
||||
*/
|
||||
export async function fuzzyMatch(partialName: string): Promise<string> {
|
||||
let fuseOptions = {
|
||||
const fuseOptions = {
|
||||
id: "cookieStoreId",
|
||||
shouldSort: true,
|
||||
threshold: 0.5,
|
||||
|
@ -201,9 +201,9 @@ export async function fuzzyMatch(partialName: string): Promise<string> {
|
|||
keys: ["name"],
|
||||
}
|
||||
|
||||
let containers = await getAll()
|
||||
let fuse = new Fuse(containers, fuseOptions)
|
||||
let res = fuse.search(partialName)
|
||||
const containers = await getAll()
|
||||
const fuse = new Fuse(containers, fuseOptions)
|
||||
const res = fuse.search(partialName)
|
||||
|
||||
if (res.length >= 1) return res[0]
|
||||
else {
|
||||
|
@ -215,8 +215,8 @@ export async function fuzzyMatch(partialName: string): Promise<string> {
|
|||
|
||||
/** Helper function for create, returns a random valid IdentityColor for use if no color is applied at creation.*/
|
||||
function chooseRandomColor(): string {
|
||||
let max = Math.floor(ContainerColor.length)
|
||||
let n = Math.floor(Math.random() * max)
|
||||
const max = Math.floor(ContainerColor.length)
|
||||
const n = Math.floor(Math.random() * max)
|
||||
return ContainerColor[n]
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ export function toBoolean(s: string) {
|
|||
}
|
||||
|
||||
export function toNumber(s: string) {
|
||||
let n = Number(s)
|
||||
const n = Number(s)
|
||||
if (isNaN(n)) throw "Not a number! " + s
|
||||
else return n
|
||||
}
|
||||
|
|
|
@ -271,7 +271,7 @@ export function changeCss(
|
|||
): CSS.Stylesheet {
|
||||
if (rulename in metaRules) {
|
||||
const metarule = metaRules[rulename][optionname]
|
||||
for (let rule of Object.keys(metarule)) {
|
||||
for (const rule of Object.keys(metarule)) {
|
||||
// have a metarule call itself for hours of fun
|
||||
sheet = changeCss(rule, metarule[rule], sheet)
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ export function elementsWithText() {
|
|||
Adapted from stackoverflow
|
||||
*/
|
||||
export function* elementsByXPath(xpath, parent?) {
|
||||
let query = document.evaluate(
|
||||
const query = document.evaluate(
|
||||
xpath,
|
||||
parent || document,
|
||||
null,
|
||||
|
@ -277,7 +277,7 @@ export function isVisible(element: Element) {
|
|||
*/
|
||||
export function getAllDocumentFrames(doc = document) {
|
||||
if (!(doc instanceof HTMLDocument)) return []
|
||||
let frames = (Array.from(doc.getElementsByTagName("iframe")) as HTMLIFrameElement[] & HTMLFrameElement[])
|
||||
const frames = (Array.from(doc.getElementsByTagName("iframe")) as HTMLIFrameElement[] & HTMLFrameElement[])
|
||||
.concat(Array.from(doc.getElementsByTagName("frame")))
|
||||
.filter(frame => !frame.src.startsWith("moz-extension://"))
|
||||
return frames.concat(
|
||||
|
@ -285,7 +285,7 @@ export function getAllDocumentFrames(doc = document) {
|
|||
// Errors could be thrown because of CSP
|
||||
let newFrames = []
|
||||
try {
|
||||
let doc = f.contentDocument || f.contentWindow.document
|
||||
const doc = f.contentDocument || f.contentWindow.document
|
||||
newFrames = getAllDocumentFrames(doc)
|
||||
} catch (e) {}
|
||||
return acc.concat(newFrames)
|
||||
|
@ -301,7 +301,7 @@ export function getSelector(e: HTMLElement) {
|
|||
// If we reached the top of the document
|
||||
if (!e.parentElement) return "HTML"
|
||||
// Compute the position of the element
|
||||
let index =
|
||||
const index =
|
||||
Array.from(e.parentElement.children)
|
||||
.filter(child => child.tagName === e.tagName)
|
||||
.indexOf(e) + 1
|
||||
|
@ -321,11 +321,11 @@ export function getSelector(e: HTMLElement) {
|
|||
*/
|
||||
export function getElemsBySelector(selector: string, filters: ElementFilter[]) {
|
||||
let elems = Array.from(document.querySelectorAll(selector))
|
||||
let frameElems = getAllDocumentFrames().reduce((acc, frame) => {
|
||||
const frameElems = getAllDocumentFrames().reduce((acc, frame) => {
|
||||
let newElems = []
|
||||
// Errors could be thrown by CSP
|
||||
try {
|
||||
let doc = frame.contentDocument || frame.contentWindow.document
|
||||
const doc = frame.contentDocument || frame.contentWindow.document
|
||||
newElems = Array.from(doc.querySelectorAll(selector))
|
||||
} catch (e) {}
|
||||
return acc.concat(newElems)
|
||||
|
@ -333,7 +333,7 @@ export function getElemsBySelector(selector: string, filters: ElementFilter[]) {
|
|||
|
||||
elems = elems.concat(frameElems)
|
||||
|
||||
for (let filter of filters) {
|
||||
for (const filter of filters) {
|
||||
elems = elems.filter(filter)
|
||||
}
|
||||
|
||||
|
@ -351,10 +351,10 @@ export function getNthElement(
|
|||
nth: number,
|
||||
filters: ElementFilter[],
|
||||
): HTMLElement {
|
||||
let inputs = getElemsBySelector(selectors, filters)
|
||||
const inputs = getElemsBySelector(selectors, filters)
|
||||
|
||||
if (inputs.length) {
|
||||
let index = Number(nth)
|
||||
const index = Number(nth)
|
||||
.clamp(-inputs.length, inputs.length - 1)
|
||||
.mod(inputs.length)
|
||||
|
||||
|
@ -436,7 +436,7 @@ export function registerEvListenerAction(
|
|||
// "mousedown" and removes "mousedown" twice, we lose track of the
|
||||
// elem even though it still has a "click" listener.
|
||||
// Fixing this might not be worth the added complexity.
|
||||
let index = hintworthy_js_elems.indexOf(elem)
|
||||
const index = hintworthy_js_elems.indexOf(elem)
|
||||
if (index >= 0) hintworthy_js_elems.splice(index, 1)
|
||||
}
|
||||
}
|
||||
|
@ -447,10 +447,10 @@ export function registerEvListenerAction(
|
|||
* same with removeEventListener.
|
||||
*/
|
||||
export function hijackPageListenerFunctions(): void {
|
||||
let exportedName = "registerEvListenerAction"
|
||||
const exportedName = "registerEvListenerAction"
|
||||
exportFunction(registerEvListenerAction, window, { defineAs: exportedName })
|
||||
|
||||
let eval_str = ["addEventListener", "removeEventListener"].reduce(
|
||||
const eval_str = ["addEventListener", "removeEventListener"].reduce(
|
||||
(acc, cur) => `${acc};
|
||||
EventTarget.prototype.${cur} = ((realFunction, register) => {
|
||||
return function (...args) {
|
||||
|
@ -514,7 +514,7 @@ function onPageFocus(elem: HTMLElement, args: any[]): boolean {
|
|||
}
|
||||
|
||||
async function setInput(el) {
|
||||
let tab = await activeTabId()
|
||||
const tab = await activeTabId()
|
||||
// store maximum of 10 elements to stop this getting bonkers huge
|
||||
const arr = state.prevInputs.concat({ tab, inputId: el.id })
|
||||
state.prevInputs = arr.slice(Math.max(arr.length - 10, 0))
|
||||
|
@ -522,10 +522,10 @@ async function setInput(el) {
|
|||
|
||||
/** Replaces the page's HTMLElement.prototype.focus with our own, onPageFocus */
|
||||
function hijackPageFocusFunction(): void {
|
||||
let exportedName = "onPageFocus"
|
||||
const exportedName = "onPageFocus"
|
||||
exportFunction(onPageFocus, window, { defineAs: exportedName })
|
||||
|
||||
let eval_str = `HTMLElement.prototype.focus = ((realFocus, ${exportedName}) => {
|
||||
const eval_str = `HTMLElement.prototype.focus = ((realFocus, ${exportedName}) => {
|
||||
return function (...args) {
|
||||
if (${exportedName}(this, args))
|
||||
return realFocus.apply(this, args)
|
||||
|
|
|
@ -38,7 +38,7 @@ type editor_function = (
|
|||
function applyToElem(e, fn) {
|
||||
let result
|
||||
if (e instanceof HTMLInputElement && e.type !== "text") {
|
||||
let t = e.type
|
||||
const t = e.type
|
||||
e.type = "text"
|
||||
result = fn(e)
|
||||
e.type = t
|
||||
|
@ -65,20 +65,20 @@ function getSimpleValues(e: any) {
|
|||
* @return [string, number, number] The content of the element, the position of the caret, the position of the end of the visual selection
|
||||
*/
|
||||
function getContentEditableValues(e: any): [string, number, number] {
|
||||
let selection = e.ownerDocument.getSelection()
|
||||
const selection = e.ownerDocument.getSelection()
|
||||
// The selection might actually not be in e so we need to make sure it is
|
||||
let n = selection.anchorNode
|
||||
while (n && n !== e) n = n.parentNode
|
||||
// The selection isn't for e, so we can't do anything
|
||||
if (!n) return [null, null, null]
|
||||
// selection might span multiple elements, might not start with the first element in e or end with the last element in e so the easiest way to compute caret position from beginning of e is to first compute distance from caret to end of e, then move beginning of selection to beginning of e and then use distance from end of selection to compute distance from beginning of selection
|
||||
let r = selection.getRangeAt(0).cloneRange()
|
||||
let selectionLength = r.toString().length
|
||||
const r = selection.getRangeAt(0).cloneRange()
|
||||
const selectionLength = r.toString().length
|
||||
r.setEnd(e, e.childNodes.length)
|
||||
let lengthFromCaretToEndOfText = r.toString().length
|
||||
const lengthFromCaretToEndOfText = r.toString().length
|
||||
r.setStart(e, 0)
|
||||
let s = r.toString()
|
||||
let caretPos = s.length - lengthFromCaretToEndOfText
|
||||
const s = r.toString()
|
||||
const caretPos = s.length - lengthFromCaretToEndOfText
|
||||
return [s, caretPos, caretPos + selectionLength]
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ function setSimpleValues(e, text, start, end) {
|
|||
function setContentEditableValues(e, text, start, end) {
|
||||
const selection = e.ownerDocument.getSelection()
|
||||
if (selection.rangeCount < 1) {
|
||||
let r = new Range()
|
||||
const r = new Range()
|
||||
r.setStart(e, 0)
|
||||
r.setEnd(e, e.childNodes.length)
|
||||
selection.addRange(r)
|
||||
|
@ -197,9 +197,9 @@ export function getWordBoundaries(
|
|||
text.length
|
||||
})`,
|
||||
)
|
||||
let pattern = new RegExp(config.get("wordpattern"), "g")
|
||||
const pattern = new RegExp(config.get("wordpattern"), "g")
|
||||
let boundary1 = position < text.length ? position : text.length - 1
|
||||
let direction = before ? -1 : 1
|
||||
const direction = before ? -1 : 1
|
||||
// if the caret is not in a word, try to find the word before or after it
|
||||
while (
|
||||
boundary1 >= 0 &&
|
||||
|
@ -268,7 +268,7 @@ export function getWordBoundaries(
|
|||
export function wordAfterPos(text: string, position: number) {
|
||||
if (position < 0)
|
||||
throw new Error(`wordAfterPos: position (${position}) is less that 0`)
|
||||
let pattern = new RegExp(config.get("wordpattern"), "g")
|
||||
const pattern = new RegExp(config.get("wordpattern"), "g")
|
||||
// move position out of the current word
|
||||
while (position < text.length && !!text[position].match(pattern))
|
||||
position += 1
|
||||
|
@ -369,8 +369,8 @@ function applyWord(
|
|||
if (selectionStart >= text.length) {
|
||||
selectionStart = text.length - 1
|
||||
}
|
||||
let boundaries = getWordBoundaries(text, selectionStart, false)
|
||||
let beginning =
|
||||
const boundaries = getWordBoundaries(text, selectionStart, false)
|
||||
const beginning =
|
||||
text.substring(0, boundaries[0]) +
|
||||
fn(text.substring(boundaries[0], boundaries[1]))
|
||||
text = beginning + text.substring(boundaries[1])
|
||||
|
@ -390,7 +390,7 @@ export const transpose_words = wrap_input(
|
|||
let firstBoundaries = getWordBoundaries(text, selectionStart, false)
|
||||
let secondBoundaries = firstBoundaries
|
||||
// If there is a word after the word the caret is in, use it for the transselectionStartition, otherwise use the word before it
|
||||
let nextWord = wordAfterPos(text, firstBoundaries[1])
|
||||
const nextWord = wordAfterPos(text, firstBoundaries[1])
|
||||
if (nextWord > -1) {
|
||||
secondBoundaries = getWordBoundaries(text, nextWord, false)
|
||||
} else {
|
||||
|
@ -400,12 +400,12 @@ export const transpose_words = wrap_input(
|
|||
true,
|
||||
)
|
||||
}
|
||||
let firstWord = text.substring(firstBoundaries[0], firstBoundaries[1])
|
||||
let secondWord = text.substring(
|
||||
const firstWord = text.substring(firstBoundaries[0], firstBoundaries[1])
|
||||
const secondWord = text.substring(
|
||||
secondBoundaries[0],
|
||||
secondBoundaries[1],
|
||||
)
|
||||
let beginning =
|
||||
const beginning =
|
||||
text.substring(0, firstBoundaries[0]) +
|
||||
secondWord +
|
||||
text.substring(firstBoundaries[1], secondBoundaries[0])
|
||||
|
@ -493,7 +493,7 @@ export const backward_kill_line = wrap_input(
|
|||
newLine = selectionStart;
|
||||
newLine > 0 && text[newLine - 1] !== "\n";
|
||||
--newLine
|
||||
) {}
|
||||
);
|
||||
// Remove everything between the newline and the caret
|
||||
return [
|
||||
text.substring(0, newLine) + text.substring(selectionStart),
|
||||
|
@ -515,13 +515,13 @@ export const kill_whole_line = wrap_input(
|
|||
firstNewLine = selectionStart;
|
||||
firstNewLine > 0 && text[firstNewLine - 1] !== "\n";
|
||||
--firstNewLine
|
||||
) {}
|
||||
);
|
||||
// Find the newline after the caret
|
||||
for (
|
||||
secondNewLine = selectionStart;
|
||||
secondNewLine < text.length && text[secondNewLine - 1] !== "\n";
|
||||
++secondNewLine
|
||||
) {}
|
||||
);
|
||||
// Remove everything between the newline and the caret
|
||||
return [
|
||||
text.substring(0, firstNewLine) + text.substring(secondNewLine),
|
||||
|
@ -536,7 +536,7 @@ export const kill_whole_line = wrap_input(
|
|||
**/
|
||||
export const kill_word = wrap_input(
|
||||
needs_text((text, selectionStart, selectionEnd) => {
|
||||
let boundaries = getWordBoundaries(text, selectionStart, false)
|
||||
const boundaries = getWordBoundaries(text, selectionStart, false)
|
||||
if (selectionStart > boundaries[0] && selectionStart < boundaries[1])
|
||||
boundaries[0] = selectionStart
|
||||
// Remove everything between the newline and the caret
|
||||
|
@ -554,7 +554,7 @@ export const kill_word = wrap_input(
|
|||
**/
|
||||
export const backward_kill_word = wrap_input(
|
||||
needs_text((text, selectionStart, selectionEnd) => {
|
||||
let boundaries = getWordBoundaries(text, selectionStart, true)
|
||||
const boundaries = getWordBoundaries(text, selectionStart, true)
|
||||
if (selectionStart > boundaries[0] && selectionStart < boundaries[1])
|
||||
boundaries[1] = selectionStart
|
||||
// Remove everything between the newline and the caret
|
||||
|
|
|
@ -2,7 +2,7 @@ import "@src/lib/number.mod"
|
|||
|
||||
export function head(iter) {
|
||||
iter = iter[Symbol.iterator]()
|
||||
let result = iter.next()
|
||||
const result = iter.next()
|
||||
if (result.done) throw RangeError("Empty iterator has no head/tail")
|
||||
else return result.value
|
||||
}
|
||||
|
@ -15,14 +15,13 @@ export function tail(iter) {
|
|||
} else {
|
||||
// Re-use error handling in head()
|
||||
let last = head(iter)
|
||||
for (last of iter) {
|
||||
}
|
||||
for (last of iter);
|
||||
return last
|
||||
}
|
||||
}
|
||||
|
||||
export function* filter(iter, predicate) {
|
||||
for (let v of iter) {
|
||||
for (const v of iter) {
|
||||
if (predicate(v)) yield v
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +50,7 @@ export function* range(length) {
|
|||
|
||||
export function* enumerate(iterable) {
|
||||
let index = 0
|
||||
for (let element of iterable) {
|
||||
for (const element of iterable) {
|
||||
yield [index, element]
|
||||
index++
|
||||
}
|
||||
|
@ -59,8 +58,8 @@ export function* enumerate(iterable) {
|
|||
|
||||
/* Zip arbitrary iterators together */
|
||||
export function* izip(...arrays) {
|
||||
let iterators = arrays.map(e => e[Symbol.iterator]())
|
||||
let box = Array(arrays.length)
|
||||
const iterators = arrays.map(e => e[Symbol.iterator]())
|
||||
const box = Array(arrays.length)
|
||||
for (let v of iterators[0]) {
|
||||
box[0] = v
|
||||
let i
|
||||
|
@ -77,7 +76,7 @@ export function* izip(...arrays) {
|
|||
|
||||
/* Test if two iterables are equal */
|
||||
export function iterEq(...arrays) {
|
||||
for (let a of zip(...arrays)) {
|
||||
for (const a of zip(...arrays)) {
|
||||
if (!a.reduce((x, y) => x === y)) return false
|
||||
}
|
||||
return true
|
||||
|
@ -104,7 +103,7 @@ export function* islice(iterable, start: number, stop?: number) {
|
|||
}
|
||||
|
||||
// Skip elements until start
|
||||
for (let _ of range(start)) {
|
||||
for (const _ of range(start)) {
|
||||
const res = iter.next()
|
||||
if (res.done) return
|
||||
}
|
||||
|
@ -132,9 +131,9 @@ export function* permutationsWithReplacement(arr, n) {
|
|||
const len = arr.length
|
||||
const counters = zeros(n)
|
||||
let index = 1
|
||||
for (let _ of range(Math.pow(len, n))) {
|
||||
for (const _ of range(Math.pow(len, n))) {
|
||||
yield counters.map(i => arr[i])
|
||||
for (let i of range(counters.length)) {
|
||||
for (const i of range(counters.length)) {
|
||||
if (index.mod(Math.pow(len, counters.length - 1 - i)) === 0)
|
||||
counters[i] = (counters[i] + 1).mod(len)
|
||||
}
|
||||
|
@ -157,8 +156,8 @@ export function unique(arr) {
|
|||
/** Yield values that are unique under hasher(value) */
|
||||
export function* uniqueBy(arr, hasher) {
|
||||
const hashes = new Set()
|
||||
for (let e of arr) {
|
||||
let hash = hasher(e)
|
||||
for (const e of arr) {
|
||||
const hash = hasher(e)
|
||||
if (!hashes.has(hash)) {
|
||||
yield e
|
||||
hashes.add(hash)
|
||||
|
@ -168,7 +167,7 @@ export function* uniqueBy(arr, hasher) {
|
|||
|
||||
export function flatten(arr) {
|
||||
let result = []
|
||||
for (let elem of arr) {
|
||||
for (const elem of arr) {
|
||||
if (elem instanceof Array) {
|
||||
result = result.concat(flatten(elem))
|
||||
} else {
|
||||
|
|
|
@ -43,7 +43,7 @@ export class MinimalKey {
|
|||
|
||||
constructor(readonly key: string, modifiers?: KeyModifiers) {
|
||||
if (modifiers !== undefined) {
|
||||
for (let mod of Object.keys(modifiers)) {
|
||||
for (const mod of Object.keys(modifiers)) {
|
||||
this[mod] = modifiers[mod]
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ export class MinimalKey {
|
|||
/** Does this key match a given MinimalKey extending object? */
|
||||
public match(keyevent) {
|
||||
// 'in' doesn't include prototypes, so it's safe for this object.
|
||||
for (let attr in this) {
|
||||
for (const attr in this) {
|
||||
// Don't check shiftKey for normal keys.
|
||||
if (attr === "shiftKey" && this.key.length === 1) continue
|
||||
if (this[attr] !== keyevent[attr]) return false
|
||||
|
@ -132,7 +132,7 @@ export function parse(keyseq: KeyEventLike[], map: KeyMap): ParserResponse {
|
|||
// Check if any of the mappings is a perfect match (this will only
|
||||
// happen if some sequences in the KeyMap are prefixes of other seqs).
|
||||
try {
|
||||
let perfect = find(
|
||||
const perfect = find(
|
||||
possibleMappings,
|
||||
([k, v]) => k.length === keyseq.length,
|
||||
)
|
||||
|
@ -339,7 +339,7 @@ export function translateKeysUsingKeyTranslateMap(
|
|||
keytranslatemap: { [inkey: string]: string },
|
||||
) {
|
||||
for (let index = 0; index < keyEvents.length; index++) {
|
||||
let keyEvent = keyEvents[index]
|
||||
const keyEvent = keyEvents[index]
|
||||
const newkey = keytranslatemap[keyEvent.key]
|
||||
|
||||
// KeyboardEvents can't have been translated, MinimalKeys may
|
||||
|
|
|
@ -30,7 +30,7 @@ export class Logger {
|
|||
* retain the call site
|
||||
*/
|
||||
private log(level: Config.LoggingLevel) {
|
||||
let configedLevel = Config.get("logging", this.logModule)
|
||||
const configedLevel = Config.get("logging", this.logModule)
|
||||
|
||||
if (LevelToNum.get(level) <= LevelToNum.get(configedLevel)) {
|
||||
// hand over to console.log, error or debug as needed
|
||||
|
|
|
@ -10,7 +10,7 @@ export function linspace(a: number, b: number, n?: number) {
|
|||
return n === 1 ? [a] : []
|
||||
}
|
||||
let i
|
||||
let ret = Array(n)
|
||||
const ret = Array(n)
|
||||
n--
|
||||
for (i = n; i >= 0; i--) {
|
||||
ret[i] = (i * b + (n - i) * a) / n
|
||||
|
|
|
@ -37,7 +37,7 @@ export function attributeCaller(obj) {
|
|||
|
||||
// Call command on obj
|
||||
try {
|
||||
let response = obj[message.command](...message.args)
|
||||
const response = obj[message.command](...message.args)
|
||||
|
||||
// Return response to sender
|
||||
if (response instanceof Promise) {
|
||||
|
@ -76,7 +76,7 @@ export async function messageActiveTab(
|
|||
}
|
||||
|
||||
export async function messageTab(tabId, type: TabMessageType, command, args?) {
|
||||
let message: Message = {
|
||||
const message: Message = {
|
||||
type,
|
||||
command,
|
||||
args,
|
||||
|
@ -99,8 +99,8 @@ export async function messageAllTabs(
|
|||
command: string,
|
||||
args?: any[],
|
||||
) {
|
||||
let responses = []
|
||||
for (let tab of await browserBg.tabs.query({})) {
|
||||
const responses = []
|
||||
for (const tab of await browserBg.tabs.query({})) {
|
||||
try {
|
||||
responses.push(await messageTab(tab.id, type, command, args))
|
||||
} catch (e) {
|
||||
|
@ -126,7 +126,7 @@ export function addListener(type: MessageType, callback: listener) {
|
|||
if (getContext() === "background") {
|
||||
// Warning: lib/webext.ts:ownTab() relies on this listener being added in order to work
|
||||
addListener("owntab_background", (message, sender, sendResponse) => {
|
||||
let x = Object.assign(Object.create(null), sender.tab)
|
||||
const x = Object.assign(Object.create(null), sender.tab)
|
||||
x.mutedInfo = Object.assign(Object.create(null), sender.tab.mutedInfo)
|
||||
x.sharingState = Object.assign(
|
||||
Object.create(null),
|
||||
|
@ -139,7 +139,7 @@ if (getContext() === "background") {
|
|||
/** Recv a message from runtime.onMessage and send to all listeners */
|
||||
function onMessage(message, sender, sendResponse) {
|
||||
if (listeners.get(message.type)) {
|
||||
for (let listener of listeners.get(message.type)) {
|
||||
for (const listener of listeners.get(message.type)) {
|
||||
listener(message, sender, sendResponse)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -155,7 +155,7 @@ export async function getBestEditor(): Promise<string> {
|
|||
cmd = await firstinpath(term_emulators)
|
||||
if (cmd !== undefined) {
|
||||
// and a text editor
|
||||
let tuicmd = await firstinpath(tui_editors)
|
||||
const tuicmd = await firstinpath(tui_editors)
|
||||
if (cmd.includes("%c")) {
|
||||
cmd = cmd.replace("%c", tuicmd)
|
||||
} else {
|
||||
|
@ -296,7 +296,7 @@ export async function winFirefoxRestart(
|
|||
profiledir: string,
|
||||
browsercmd: string,
|
||||
) {
|
||||
let required_version = "0.1.6"
|
||||
const required_version = "0.1.6"
|
||||
|
||||
if (!(await nativegate(required_version, false))) {
|
||||
throw `'restart' on Windows needs native messenger version >= ${required_version}.`
|
||||
|
@ -306,7 +306,7 @@ export async function winFirefoxRestart(
|
|||
}
|
||||
|
||||
export async function run(command: string, content = "") {
|
||||
let msg = await sendNativeMsg("run", { command, content })
|
||||
const msg = await sendNativeMsg("run", { command, content })
|
||||
logger.info(msg)
|
||||
return msg
|
||||
}
|
||||
|
@ -319,7 +319,7 @@ export async function pyeval(command: string): Promise<MessageResp> {
|
|||
}
|
||||
|
||||
export async function getenv(variable: string) {
|
||||
let required_version = "0.1.2"
|
||||
const required_version = "0.1.2"
|
||||
|
||||
if (!(await nativegate(required_version, false))) {
|
||||
throw `'getenv' needs native messenger version >= ${required_version}.`
|
||||
|
@ -343,7 +343,7 @@ export async function clipboard(
|
|||
}
|
||||
|
||||
if (action === "get") {
|
||||
let result = await run(clipcmd + " -o")
|
||||
const result = await run(clipcmd + " -o")
|
||||
if (result.code !== 0) {
|
||||
throw new Error(
|
||||
`External command failed with code ${result.code}: ${clipcmd}`,
|
||||
|
@ -351,9 +351,9 @@ export async function clipboard(
|
|||
}
|
||||
return result.content
|
||||
} else if (action === "set") {
|
||||
let required_version = "0.1.7"
|
||||
const required_version = "0.1.7"
|
||||
if (await nativegate(required_version, false)) {
|
||||
let result = await run(`${clipcmd} -i`, str)
|
||||
const result = await run(`${clipcmd} -i`, str)
|
||||
if (result.code !== 0)
|
||||
throw new Error(
|
||||
`External command failed with code ${
|
||||
|
@ -390,7 +390,7 @@ export async function ff_cmdline(): Promise<string[]> {
|
|||
if ((await browserBg.runtime.getPlatformInfo()).os === "win") {
|
||||
throw `Error: "ff_cmdline() is currently broken on Windows and should be avoided."`
|
||||
} else {
|
||||
let output = await pyeval(
|
||||
const output = await pyeval(
|
||||
'handleMessage({"cmd": "run", ' +
|
||||
'"command": "ps -p " + str(os.getppid()) + " -oargs="})["content"]',
|
||||
)
|
||||
|
@ -399,10 +399,10 @@ export async function ff_cmdline(): Promise<string[]> {
|
|||
}
|
||||
|
||||
export function parseProfilesIni(content: string, basePath: string) {
|
||||
let lines = content.split("\n")
|
||||
const lines = content.split("\n")
|
||||
let current = "General"
|
||||
let result = {}
|
||||
for (let line of lines) {
|
||||
const result = {}
|
||||
for (const line of lines) {
|
||||
let match = line.match(/^\[([^\]]+)\]$/)
|
||||
if (match !== null) {
|
||||
current = match[1]
|
||||
|
@ -414,8 +414,8 @@ export function parseProfilesIni(content: string, basePath: string) {
|
|||
}
|
||||
}
|
||||
}
|
||||
for (let profileName of Object.keys(result)) {
|
||||
let profile = result[profileName]
|
||||
for (const profileName of Object.keys(result)) {
|
||||
const profile = result[profileName]
|
||||
// profile.IsRelative can be 0, 1 or undefined
|
||||
if (profile.IsRelative === 1) {
|
||||
profile.relativePath = profile.Path
|
||||
|
@ -460,8 +460,8 @@ export async function getProfile() {
|
|||
|
||||
// First, try to see if the 'profiledir' setting matches a profile in profile.ini
|
||||
if (curProfileDir !== "auto") {
|
||||
for (let profileName of Object.keys(iniObject)) {
|
||||
let profile = iniObject[profileName]
|
||||
for (const profileName of Object.keys(iniObject)) {
|
||||
const profile = iniObject[profileName]
|
||||
if (profile.absolutePath === curProfileDir) {
|
||||
return profile
|
||||
}
|
||||
|
@ -476,8 +476,8 @@ export async function getProfile() {
|
|||
const profile = cmdline.indexOf("--profile")
|
||||
if (profile >= 0 && profile < cmdline.length - 1) {
|
||||
const profilePath = cmdline[profile + 1]
|
||||
for (let profileName of Object.keys(iniObject)) {
|
||||
let profile = iniObject[profileName]
|
||||
for (const profileName of Object.keys(iniObject)) {
|
||||
const profile = iniObject[profileName]
|
||||
if (profile.absolutePath === profilePath) {
|
||||
return profile
|
||||
}
|
||||
|
@ -492,8 +492,8 @@ export async function getProfile() {
|
|||
if (p === -1) p = cmdline.indexOf("-P")
|
||||
if (p >= 0 && p < cmdline.length - 1) {
|
||||
const pName = cmdline[p + 1]
|
||||
for (let profileName of Object.keys(iniObject)) {
|
||||
let profile = iniObject[profileName]
|
||||
for (const profileName of Object.keys(iniObject)) {
|
||||
const profile = iniObject[profileName]
|
||||
if (profile.Name === pName) {
|
||||
return profile
|
||||
}
|
||||
|
@ -509,7 +509,7 @@ export async function getProfile() {
|
|||
let hacky_profile_finder = `find "${ffDir}" -maxdepth 2 -name lock`
|
||||
if ((await browserBg.runtime.getPlatformInfo()).os === "mac")
|
||||
hacky_profile_finder = `find "${ffDir}" -maxdepth 2 -name .parentlock`
|
||||
let profilecmd = await run(hacky_profile_finder)
|
||||
const profilecmd = await run(hacky_profile_finder)
|
||||
if (profilecmd.code === 0 && profilecmd.content.length !== 0) {
|
||||
// Remove trailing newline
|
||||
profilecmd.content = profilecmd.content.trim()
|
||||
|
@ -519,8 +519,8 @@ export async function getProfile() {
|
|||
.split("/")
|
||||
.slice(0, -1)
|
||||
.join("/")
|
||||
for (let profileName of Object.keys(iniObject)) {
|
||||
let profile = iniObject[profileName]
|
||||
for (const profileName of Object.keys(iniObject)) {
|
||||
const profile = iniObject[profileName]
|
||||
if (profile.absolutePath === path) {
|
||||
return profile
|
||||
}
|
||||
|
@ -532,8 +532,8 @@ export async function getProfile() {
|
|||
}
|
||||
|
||||
// Multiple profiles used but no -p or --profile, this means that we're using the default profile
|
||||
for (let profileName of Object.keys(iniObject)) {
|
||||
let profile = iniObject[profileName]
|
||||
for (const profileName of Object.keys(iniObject)) {
|
||||
const profile = iniObject[profileName]
|
||||
if (profile.Default === 1) {
|
||||
return profile
|
||||
}
|
||||
|
@ -549,7 +549,7 @@ export function getProfileName() {
|
|||
}
|
||||
|
||||
export async function getProfileDir() {
|
||||
let profiledir = config.get("profiledir")
|
||||
const profiledir = config.get("profiledir")
|
||||
if (profiledir !== "auto") return Promise.resolve(profiledir)
|
||||
return getProfile().then(p => p.absolutePath)
|
||||
}
|
||||
|
@ -563,7 +563,7 @@ export async function parsePrefs(prefFileContent: string) {
|
|||
)
|
||||
// Fragile parsing
|
||||
return prefFileContent.split("\n").reduce((prefs, line) => {
|
||||
let matches = line.match(regex)
|
||||
const matches = line.match(regex)
|
||||
if (!matches) {
|
||||
return prefs
|
||||
}
|
||||
|
@ -620,10 +620,10 @@ export async function getPrefs(): Promise<{ [key: string]: string }> {
|
|||
profile + "prefs.js",
|
||||
profile + "user.js",
|
||||
]
|
||||
let promises = []
|
||||
const promises = []
|
||||
// Starting all promises before awaiting because we want the calls to be
|
||||
// made in parallel
|
||||
for (let file of prefFiles) {
|
||||
for (const file of prefFiles) {
|
||||
promises.push(loadPrefs(file))
|
||||
}
|
||||
cached_prefs = promises.reduce(async (a, b) =>
|
||||
|
@ -664,7 +664,7 @@ export async function getConfElsePrefElseDefault(
|
|||
prefName: string,
|
||||
def: any,
|
||||
): Promise<any> {
|
||||
let option = await getConfElsePref(confName, prefName)
|
||||
const option = await getConfElsePref(confName, prefName)
|
||||
if (option === undefined) return def
|
||||
return option
|
||||
}
|
||||
|
@ -677,12 +677,12 @@ export async function writePref(name: string, value: any) {
|
|||
// No need to check the return code because read returns "" when failing to
|
||||
// read a file
|
||||
const text = (await read(file)).content
|
||||
let prefPos = text.indexOf(`pref("${name}",`)
|
||||
const prefPos = text.indexOf(`pref("${name}",`)
|
||||
if (prefPos < 0) {
|
||||
write(file, `${text}\nuser_pref("${name}", ${value});\n`)
|
||||
} else {
|
||||
let substr = text.substring(prefPos)
|
||||
let prefEnd = substr.indexOf(";\n")
|
||||
const prefEnd = substr.indexOf(";\n")
|
||||
substr = text.substring(prefPos, prefPos + prefEnd)
|
||||
write(file, text.replace(substr, `pref("${name}", ${value})`))
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ export function my_mod(dividend, divisor) {
|
|||
Equivalent to % when dividend is +ve
|
||||
*/
|
||||
export function euclid_mod(dividend, divisor) {
|
||||
let abs_divisor = Math.abs(divisor)
|
||||
let quotient = Math.floor(dividend / abs_divisor)
|
||||
const abs_divisor = Math.abs(divisor)
|
||||
const quotient = Math.floor(dividend / abs_divisor)
|
||||
return dividend - abs_divisor * quotient
|
||||
}
|
||||
|
||||
|
|
|
@ -14,11 +14,11 @@ function wrapPrimitives(testcases) {
|
|||
*/
|
||||
export function testAll(toTest, testcases) {
|
||||
testcases = testcases.map(wrapPrimitives)
|
||||
for (let [args, ans] of testcases) {
|
||||
for (const [args, ans] of testcases) {
|
||||
test(`${toTest.name}(${args}) == ${JSON.stringify(ans)}`, () =>
|
||||
expect(
|
||||
(() => {
|
||||
let result = toTest(...args)
|
||||
const result = toTest(...args)
|
||||
if (result instanceof Array) return result
|
||||
else return [result]
|
||||
})(),
|
||||
|
@ -35,11 +35,11 @@ export function testAll(toTest, testcases) {
|
|||
*/
|
||||
export function testAllCustom(toTest, testcases, expectAttr, expectArg) {
|
||||
testcases = testcases.map(wrapPrimitives)
|
||||
for (let [args, ans] of testcases) {
|
||||
for (const [args, ans] of testcases) {
|
||||
test(`${toTest.name}(${args}) == ${JSON.stringify(ans)}`, () =>
|
||||
expect(
|
||||
(() => {
|
||||
let result = toTest(...args)
|
||||
const result = toTest(...args)
|
||||
if (result instanceof Array) return result
|
||||
else return [result]
|
||||
})(),
|
||||
|
@ -49,7 +49,7 @@ export function testAllCustom(toTest, testcases, expectAttr, expectArg) {
|
|||
|
||||
/** Call function with each testcase and check it doesn't throw */
|
||||
export function testAllNoError(toTest, testcases) {
|
||||
for (let args of wrapPrimitives(testcases)) {
|
||||
for (const args of wrapPrimitives(testcases)) {
|
||||
test(`try: ${toTest.name}(${args})`, () =>
|
||||
expect(() => toTest(...args)).not.toThrow())
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import * as Config from "@src/lib/config"
|
|||
* @return voice from the TTS API, or undefined
|
||||
*/
|
||||
function getVoiceFromName(name: string | "default"): SpeechSynthesisVoice {
|
||||
let voices = window.speechSynthesis.getVoices()
|
||||
const voices = window.speechSynthesis.getVoices()
|
||||
|
||||
return voices.find(voice => voice.name === name)
|
||||
}
|
||||
|
@ -25,12 +25,12 @@ export function readText(text: string): void {
|
|||
throw new Error("No voice found: cannot use Text-To-Speech API")
|
||||
}
|
||||
|
||||
let utterance = new SpeechSynthesisUtterance(text)
|
||||
const utterance = new SpeechSynthesisUtterance(text)
|
||||
|
||||
let pitch = Config.get("ttspitch")
|
||||
let voice = Config.get("ttsvoice")
|
||||
let volume = Config.get("ttsvolume")
|
||||
let rate = Config.get("ttsrate")
|
||||
const pitch = Config.get("ttspitch")
|
||||
const voice = Config.get("ttsvoice")
|
||||
const volume = Config.get("ttsvolume")
|
||||
const rate = Config.get("ttsrate")
|
||||
|
||||
if (pitch >= 0 && pitch < 2) utterance.pitch = pitch
|
||||
|
||||
|
@ -38,7 +38,7 @@ export function readText(text: string): void {
|
|||
|
||||
if (rate >= 0.1 && rate <= 10) utterance.rate = rate
|
||||
|
||||
let voiceObj = getVoiceFromName(voice)
|
||||
const voiceObj = getVoiceFromName(voice)
|
||||
if (voiceObj) {
|
||||
utterance.voice = voiceObj
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ export type Action = "stop" | "play" | "pause" | "playpause"
|
|||
* to be very useful right now
|
||||
*/
|
||||
export function doAction(action: Action): void {
|
||||
let synth = window.speechSynthesis
|
||||
const synth = window.speechSynthesis
|
||||
|
||||
switch (action) {
|
||||
case "play":
|
||||
|
@ -83,7 +83,7 @@ export function doAction(action: Action): void {
|
|||
* @return list of voice names
|
||||
*/
|
||||
export function listVoices(): string[] {
|
||||
let voices = window.speechSynthesis.getVoices()
|
||||
const voices = window.speechSynthesis.getVoices()
|
||||
|
||||
return voices.map(voice => voice.name)
|
||||
}
|
||||
|
|
|
@ -12,15 +12,15 @@
|
|||
*/
|
||||
export function incrementUrl(url, count) {
|
||||
// Find the final number in a URL
|
||||
let matches = url.match(/(.*?)(\d+)(\D*)$/)
|
||||
const matches = url.match(/(.*?)(\d+)(\D*)$/)
|
||||
|
||||
// no number in URL - nothing to do here
|
||||
if (matches === null) {
|
||||
return null
|
||||
}
|
||||
|
||||
let [, pre, number, post] = matches
|
||||
let newNumber = parseInt(number, 10) + count
|
||||
const [, pre, number, post] = matches
|
||||
const newNumber = parseInt(number, 10) + count
|
||||
let newNumberStr = String(newNumber > 0 ? newNumber : 0)
|
||||
|
||||
// Re-pad numbers that were zero-padded to be the same length:
|
||||
|
@ -86,7 +86,7 @@ export function getUrlParent(url, count = 1) {
|
|||
|
||||
// strip off the first subdomain if there is one
|
||||
{
|
||||
let domains = parent.host.split(".")
|
||||
const domains = parent.host.split(".")
|
||||
|
||||
// more than domain + TLD
|
||||
if (domains.length > 2) {
|
||||
|
@ -105,7 +105,7 @@ export function getUrlParent(url, count = 1) {
|
|||
return null
|
||||
}
|
||||
|
||||
let parent = new URL(url)
|
||||
const parent = new URL(url)
|
||||
return gup(parent, count)
|
||||
}
|
||||
|
||||
|
@ -186,7 +186,7 @@ export function getDownloadFilenameForUrl(url: URL): string {
|
|||
|
||||
// if there's a useful path, use that directly
|
||||
if (url.pathname !== "/") {
|
||||
let paths = url.pathname.split("/").slice(1)
|
||||
const paths = url.pathname.split("/").slice(1)
|
||||
|
||||
// pop off empty pat bh tails
|
||||
// e.g. https://www.mozilla.org/en-GB/firefox/new/
|
||||
|
@ -244,11 +244,11 @@ function setUrlQueries(url: URL, qys: string[]) {
|
|||
* @return the modified URL
|
||||
*/
|
||||
export function deleteQuery(url: URL, matchQuery: string): URL {
|
||||
let newUrl = new URL(url.href)
|
||||
const newUrl = new URL(url.href)
|
||||
|
||||
let qys = getUrlQueries(url)
|
||||
const qys = getUrlQueries(url)
|
||||
|
||||
let new_qys = qys.filter(q => {
|
||||
const new_qys = qys.filter(q => {
|
||||
return q.split("=")[0] !== matchQuery
|
||||
})
|
||||
|
||||
|
@ -269,13 +269,13 @@ export function replaceQueryValue(
|
|||
matchQuery: string,
|
||||
newVal: string,
|
||||
): URL {
|
||||
let newUrl = new URL(url.href)
|
||||
const newUrl = new URL(url.href)
|
||||
|
||||
// get each query separately, leave the "?" off
|
||||
let qys = getUrlQueries(url)
|
||||
const qys = getUrlQueries(url)
|
||||
|
||||
let new_qys = qys.map(q => {
|
||||
let [key] = q.split("=")
|
||||
const new_qys = qys.map(q => {
|
||||
const [key] = q.split("=")
|
||||
|
||||
// found a matching query key
|
||||
if (q.split("=")[0] === matchQuery) {
|
||||
|
@ -309,10 +309,10 @@ export function replaceQueryValue(
|
|||
* <0: start at the current path and count left
|
||||
*/
|
||||
export function graftUrlPath(url: URL, newTail: string, level: number) {
|
||||
let newUrl = new URL(url.href)
|
||||
const newUrl = new URL(url.href)
|
||||
|
||||
// path parts, ignore first /
|
||||
let pathParts = url.pathname.split("/").splice(1)
|
||||
const pathParts = url.pathname.split("/").splice(1)
|
||||
|
||||
// more levels than we can handle
|
||||
// (remember, if level <0, we start at -1)
|
||||
|
@ -323,7 +323,7 @@ export function graftUrlPath(url: URL, newTail: string, level: number) {
|
|||
return null
|
||||
}
|
||||
|
||||
let graftPoint = level >= 0 ? level : pathParts.length + level + 1
|
||||
const graftPoint = level >= 0 ? level : pathParts.length + level + 1
|
||||
|
||||
// lop off parts after the graft point
|
||||
pathParts.splice(graftPoint, pathParts.length - graftPoint)
|
||||
|
@ -368,7 +368,7 @@ export function interpolateSearchItem(urlPattern: URL, query: string): URL {
|
|||
|
||||
// replace or append as needed
|
||||
if (hasInterpolationPoint) {
|
||||
let resultingURL = new URL(
|
||||
const resultingURL = new URL(
|
||||
urlPattern.href.replace(/%s\d+/g, function(x) {
|
||||
const index = parseInt(x.slice(2), 10) - 1
|
||||
if (index >= queryWords.length) {
|
||||
|
|
|
@ -69,7 +69,7 @@ export async function ownTabContainer() {
|
|||
}
|
||||
|
||||
export async function activeTabContainer() {
|
||||
let containerId = await activeTabContainerId()
|
||||
const containerId = await activeTabContainerId()
|
||||
if (containerId !== "firefox-default")
|
||||
return browserBg.contextualIdentities.get(containerId)
|
||||
else
|
||||
|
@ -181,7 +181,7 @@ export async function openInTab(tab, opts = {}, strarr: string[]) {
|
|||
const rest = address.substr(firstWord.length + 1)
|
||||
const searchurls = config.get("searchurls")
|
||||
if (searchurls[firstWord]) {
|
||||
let url = UrlUtil.interpolateSearchItem(
|
||||
const url = UrlUtil.interpolateSearchItem(
|
||||
new URL(searchurls[firstWord]),
|
||||
rest,
|
||||
)
|
||||
|
@ -224,11 +224,11 @@ export async function openInTab(tab, opts = {}, strarr: string[]) {
|
|||
queryString = rest
|
||||
}
|
||||
|
||||
let enginename = config.get("searchengine")
|
||||
const enginename = config.get("searchengine")
|
||||
// firstWord is neither a searchurl nor a search engine, let's see if a search engine has been defined in Tridactyl
|
||||
if (enginename) {
|
||||
if (searchurls[enginename]) {
|
||||
let url = UrlUtil.interpolateSearchItem(
|
||||
const url = UrlUtil.interpolateSearchItem(
|
||||
new URL(searchurls[enginename]),
|
||||
queryString,
|
||||
)
|
||||
|
|
|
@ -8,7 +8,7 @@ export function parser(conf, keys): keyseq.ParserResponse {
|
|||
|
||||
// If so configured, translate keys using the key translation map
|
||||
if (config.get("keytranslatemodes")[conf] === "true") {
|
||||
let translationmap = config.get("keytranslatemap")
|
||||
const translationmap = config.get("keytranslatemap")
|
||||
keyseq.translateKeysUsingKeyTranslateMap(keys, translationmap)
|
||||
}
|
||||
|
||||
|
|
|
@ -197,8 +197,6 @@ export class StatsLogger {
|
|||
private buffersize: number = 10000
|
||||
private lastError: number = 0
|
||||
|
||||
constructor() {}
|
||||
|
||||
/**
|
||||
* Target for receiving stats entries from other threads - there
|
||||
* was some issue with encoding that I couldn't figure out so I
|
||||
|
@ -242,7 +240,7 @@ export class StatsLogger {
|
|||
// issue - it's not like we need these to be in order or
|
||||
// otherwise coherent, we're just trying to store a big pile
|
||||
// of recent-ish samples.
|
||||
let perfsamples = Number(config.get("perfsamples"))
|
||||
const perfsamples = Number(config.get("perfsamples"))
|
||||
// Check for NaN or non-integer
|
||||
if (Number.isInteger(perfsamples)) {
|
||||
this.buffersize = perfsamples
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
"no-commented-code": false,
|
||||
"no-console": false,
|
||||
"no-duplicate-string": false,
|
||||
"no-empty": false,
|
||||
"no-empty": [true, "allow-empty-catch", "allow-empty-functions"],
|
||||
"no-eval": false,
|
||||
"no-extra-semicolon": false,
|
||||
"no-identical-functions": false,
|
||||
|
@ -31,7 +31,7 @@
|
|||
"object-literal-sort-keys": false,
|
||||
"only-arrow-functions": false,
|
||||
"ordered-imports": false,
|
||||
"prefer-const": false,
|
||||
"prefer-const": [true, {"destructuring": "all"}],
|
||||
"semicolon": false,
|
||||
"trailing-comma": false,
|
||||
"triple-equals": false,
|
||||
|
|
Loading…
Add table
Reference in a new issue