2017-09-25 04:44:56 +01:00
|
|
|
// Interfaces common to the tridactyl project.
|
|
|
|
|
|
|
|
// For some obscure reason, tsc doesn't like .d.ts files to share a name with
|
|
|
|
// .ts files. So don't do that.
|
|
|
|
|
2017-10-28 05:11:10 +01:00
|
|
|
// Ill-advised monkeypatching
|
2017-10-02 00:59:51 +01:00
|
|
|
interface Number {
|
|
|
|
mod(n: number): number
|
2017-10-06 19:22:19 -07:00
|
|
|
clamp(lo: number, hi: number): number
|
2017-10-02 00:59:51 +01:00
|
|
|
}
|
|
|
|
|
2017-09-28 22:39:26 +01:00
|
|
|
// Firefox-specific dom properties
|
2017-09-27 21:10:52 -07:00
|
|
|
interface Window {
|
|
|
|
scrollByLines(n: number): void
|
2017-12-30 07:51:08 +01:00
|
|
|
scrollByPages(n: number): void
|
|
|
|
eval(str: string): any
|
2017-11-16 18:12:18 +00:00
|
|
|
}
|
|
|
|
|
2018-09-03 03:13:42 -07:00
|
|
|
// Record that we've added a property with convenience objects to the
|
|
|
|
// window object:
|
|
|
|
interface Window {
|
|
|
|
tri: any
|
|
|
|
}
|
|
|
|
|
2018-06-24 13:36:06 +02:00
|
|
|
// This isn't an actual firefox type but it's nice to have one for this kind of object
|
|
|
|
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/find/find
|
|
|
|
interface findResult {
|
|
|
|
count: number
|
2020-06-18 21:57:16 +01:00
|
|
|
rangeData: Array<{
|
2018-06-24 13:36:06 +02:00
|
|
|
framePos: number
|
|
|
|
startTextNodePos: number
|
|
|
|
endTextNodePos: number
|
|
|
|
startOffset: number
|
|
|
|
endOffset: number
|
|
|
|
text: string
|
2020-06-18 21:57:16 +01:00
|
|
|
}>
|
2018-06-24 13:36:06 +02:00
|
|
|
rectData: {
|
2020-06-18 21:57:16 +01:00
|
|
|
rectsAndTexts: Array<{
|
2018-06-24 13:36:06 +02:00
|
|
|
top: number
|
|
|
|
left: number
|
|
|
|
bottom: number
|
|
|
|
right: number
|
2020-06-18 21:57:16 +01:00
|
|
|
}>
|
2018-06-24 13:36:06 +02:00
|
|
|
textList: string[]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-03 20:56:54 +01:00
|
|
|
interface HTMLElement {
|
|
|
|
// Let's be future proof:
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus
|
2020-06-19 13:11:03 +01:00
|
|
|
focus(options?: any): void
|
2018-03-03 20:56:54 +01:00
|
|
|
}
|
|
|
|
|
2020-06-18 21:55:04 +01:00
|
|
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
|
|
// these functions really can be anything, ditto for the objects
|
2018-04-13 19:28:03 +01:00
|
|
|
declare function exportFunction(
|
|
|
|
func: Function,
|
|
|
|
targetScope: object,
|
|
|
|
options?: { defineAs?: string; allowCrossOriginArguments?: boolean },
|
|
|
|
): Function
|
2020-06-18 21:55:04 +01:00
|
|
|
/* eslint-enable @typescript-eslint/ban-types */
|
2017-12-30 07:51:08 +01:00
|
|
|
|
2017-10-16 14:42:12 +01:00
|
|
|
// Web extension types not in web-ext-types yet
|
2017-10-15 23:05:41 +01:00
|
|
|
declare namespace browser.find {
|
|
|
|
function find(query, object): any
|
|
|
|
}
|
2017-11-15 12:40:26 +00:00
|
|
|
|
|
|
|
declare namespace browser.tabs {
|
2018-04-13 19:28:03 +01:00
|
|
|
function setZoom(zoomFactor: number): Promise<void>
|
2020-06-19 13:11:03 +01:00
|
|
|
// setZoom has an optional first argument of tabId: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/setZoom#Parameters
|
|
|
|
// eslint-disable-next-line @typescript-eslint/unified-signatures
|
2018-04-13 19:28:03 +01:00
|
|
|
function setZoom(tabId: number, zoomFactor: number): Promise<void>
|
|
|
|
function toggleReaderMode(tabId?: number): Promise<void>
|
2017-11-15 12:40:26 +00:00
|
|
|
}
|
2017-11-16 18:12:18 +00:00
|
|
|
|
Teach autocontainers to coexist with other container-management exts
This has a few moving parts.
First, we need a bit of code for keeping track of what other
extensions are installed and enabled. This isn't completely trivial
because we need to listen for "on {en,dis}abled" and "on
{,un}installed" events. This requires a new permission, `management`,
which is _annoying_, but not having this permission would require
extension detection to be done using kludgy messaging hacks that would
be on the critical path for essentially every navigation operation.
Second, we need to write code to talk to the other addons and ask them
if they're handling things. Thankfully they do provide public APIs and
and we can use their sample code to do exactly what we need to do.
Third, it turns out some important chunks of the firefox webext API
aren't handled by the web-ext-browser ts declaration we're
using. They *are* handled by a PR on @types/firefox-webext-browser,
though, so we can copy and paste that to make TS happy.
Fourth, and finally, we need to add some code to the autocontainer
logic to use the compatibility code. This is pretty easy, but
autocontainer logic starts taking a noticeable amount of time becuase
of all the sequences awaits we're doing, so I also have to tweak
things to do all of the async stuff in parallel.
2018-08-27 03:27:02 -07:00
|
|
|
// web-ext-browser barely declares a third of the management
|
|
|
|
// interface, and we can't switch to @types/firefox-webext-browser yet
|
|
|
|
// because their enums are all messed up (see
|
|
|
|
// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/28369)
|
|
|
|
// Instead, we'll copy-paste as much as we need from the fixed branch:
|
|
|
|
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/d1180e5218a7bf69e6f0da5ac2e2584bd57a1cdf/types/firefox-webext-browser/index.d.ts
|
|
|
|
interface WebExtEventBase<
|
|
|
|
TAddListener extends (...args: any[]) => any,
|
|
|
|
TCallback
|
|
|
|
> {
|
|
|
|
addListener: TAddListener
|
|
|
|
|
|
|
|
removeListener(cb: TCallback): void
|
|
|
|
|
|
|
|
hasListener(cb: TCallback): boolean
|
|
|
|
}
|
|
|
|
|
2017-11-16 18:12:18 +00:00
|
|
|
// html-tagged-template.js
|
2018-04-13 19:28:03 +01:00
|
|
|
declare function html(
|
|
|
|
strings: TemplateStringsArray,
|
|
|
|
...values: any[]
|
|
|
|
): HTMLElement
|
2017-11-21 13:59:57 +00:00
|
|
|
|
2019-10-26 20:05:11 +02:00
|
|
|
declare namespace browser.search {
|
2020-07-01 18:01:38 +01:00
|
|
|
function search(searchProperties: {
|
|
|
|
query: string
|
|
|
|
engine?: string
|
|
|
|
tabId?: number
|
|
|
|
}): void
|
|
|
|
function get(): Promise<
|
|
|
|
Array<{
|
|
|
|
name: string
|
|
|
|
isDefault: boolean
|
|
|
|
alias?: string
|
|
|
|
faviconURL?: string
|
|
|
|
}>
|
|
|
|
>
|
2019-10-26 20:05:11 +02:00
|
|
|
}
|
2019-01-27 13:04:51 +01:00
|
|
|
|
2018-05-21 01:22:04 +01:00
|
|
|
// Stop typedoc complaining about toBeAll.
|
|
|
|
declare namespace jest {
|
|
|
|
interface Matchers<R> {
|
|
|
|
toBeAll: any
|
|
|
|
}
|
|
|
|
}
|
2020-07-05 21:56:44 +01:00
|
|
|
|
|
|
|
// jest-webextension-mock doesn't know about this Firefox specific API
|
|
|
|
declare namespace browser.commands {
|
|
|
|
function update(details)
|
|
|
|
}
|