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
|
|
|
|
focus(options: any): void
|
2018-11-01 15:33:50 +00:00
|
|
|
// Let's also implement the current function signature.
|
|
|
|
focus(): 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
|
|
|
|
|
|
|
// setZoom has an optional first argument of tabId. Unclear how first argument can be optional.
|
|
|
|
declare namespace browser.tabs {
|
2018-04-13 19:28:03 +01:00
|
|
|
function setZoom(zoomFactor: number): Promise<void>
|
|
|
|
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
|
|
|
|
}
|
|
|
|
type WebExtEvent<TCallback extends (...args: any[]) => any> = WebExtEventBase<
|
|
|
|
(callback: TCallback) => void,
|
|
|
|
TCallback
|
|
|
|
>
|
|
|
|
declare namespace browser.management {
|
|
|
|
/* management types */
|
|
|
|
|
|
|
|
/** Information about an icon belonging to an extension. */
|
|
|
|
interface IconInfo {
|
|
|
|
/**
|
|
|
|
* A number representing the width and height of the icon. Likely values include (but are not limited to) 128,
|
|
|
|
* 48, 24, and 16.
|
|
|
|
*/
|
|
|
|
size: number
|
|
|
|
/**
|
|
|
|
* The URL for this icon image. To display a grayscale version of the icon (to indicate that an extension is
|
|
|
|
* disabled, for example), append `?grayscale=true` to the URL.
|
|
|
|
*/
|
|
|
|
url: string
|
|
|
|
}
|
|
|
|
|
|
|
|
/** A reason the item is disabled. */
|
|
|
|
type ExtensionDisabledReason = "unknown" | "permissions_increase"
|
|
|
|
|
|
|
|
/** The type of this extension. Will always be 'extension'. */
|
|
|
|
type ExtensionType = "extension" | "theme"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How the extension was installed. One of
|
|
|
|
* `development`: The extension was loaded unpacked in developer mode,
|
|
|
|
* `normal`: The extension was installed normally via an .xpi file,
|
|
|
|
* `sideload`: The extension was installed by other software on the machine,
|
|
|
|
* `other`: The extension was installed by other means.
|
|
|
|
*/
|
|
|
|
type ExtensionInstallType = "development" | "normal" | "sideload" | "other"
|
|
|
|
|
|
|
|
/** Information about an installed extension. */
|
|
|
|
interface IExtensionInfo {
|
|
|
|
/** The extension's unique identifier. */
|
|
|
|
id: string
|
|
|
|
/** The name of this extension. */
|
|
|
|
name: string
|
|
|
|
/** A short version of the name of this extension. */
|
|
|
|
shortName?: string
|
|
|
|
/** The description of this extension. */
|
|
|
|
description: string
|
|
|
|
/** The version of this extension. */
|
|
|
|
version: string
|
|
|
|
/** The version name of this extension if the manifest specified one. */
|
|
|
|
versionName?: string
|
|
|
|
/** Whether this extension can be disabled or uninstalled by the user. */
|
|
|
|
mayDisable: boolean
|
|
|
|
/** Whether it is currently enabled or disabled. */
|
|
|
|
enabled: boolean
|
|
|
|
/** A reason the item is disabled. */
|
|
|
|
disabledReason?: ExtensionDisabledReason
|
|
|
|
/** The type of this extension. Will always return 'extension'. */
|
|
|
|
type: ExtensionType
|
|
|
|
/** The URL of the homepage of this extension. */
|
|
|
|
homepageUrl?: string
|
|
|
|
/** The update URL of this extension. */
|
|
|
|
updateUrl?: string
|
|
|
|
/** The url for the item's options page, if it has one. */
|
|
|
|
optionsUrl: string
|
|
|
|
/**
|
|
|
|
* A list of icon information. Note that this just reflects what was declared in the manifest, and the actual
|
|
|
|
* image at that url may be larger or smaller than what was declared, so you might consider using explicit
|
|
|
|
* width and height attributes on img tags referencing these images. See the manifest documentation on icons
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
icons?: IconInfo[]
|
|
|
|
/** Returns a list of API based permissions. */
|
|
|
|
permissions?: string[]
|
|
|
|
/** Returns a list of host based permissions. */
|
|
|
|
hostPermissions?: string[]
|
|
|
|
/** How the extension was installed. */
|
|
|
|
installType: ExtensionInstallType
|
|
|
|
}
|
|
|
|
|
|
|
|
/* management functions */
|
|
|
|
/** Returns a list of information about installed extensions. */
|
|
|
|
function getAll(): Promise<IExtensionInfo[] | undefined>
|
|
|
|
|
|
|
|
/* management events */
|
|
|
|
/** Fired when an addon has been disabled. */
|
|
|
|
const onDisabled: WebExtEvent<(info: IExtensionInfo) => void>
|
|
|
|
|
|
|
|
/** Fired when an addon has been enabled. */
|
|
|
|
const onEnabled: WebExtEvent<(info: IExtensionInfo) => void>
|
|
|
|
|
|
|
|
/** Fired when an addon has been installed. */
|
|
|
|
const onInstalled: WebExtEvent<(info: IExtensionInfo) => void>
|
|
|
|
|
|
|
|
/** Fired when an addon has been uninstalled. */
|
|
|
|
const onUninstalled: WebExtEvent<(info: IExtensionInfo) => void>
|
|
|
|
}
|
|
|
|
|
|
|
|
/** An interface for the additional object that's supplied in the BlockingResponse callback.
|
|
|
|
|
|
|
|
Details here:
|
|
|
|
https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/webRequest/onBeforeRequest#details
|
|
|
|
|
|
|
|
*/
|
|
|
|
declare namespace browser.webRequest {
|
|
|
|
interface IDetails {
|
|
|
|
// frameAncestors: any[]
|
|
|
|
frameId: number
|
|
|
|
method: string
|
|
|
|
originUrl: string
|
|
|
|
parentFrameId: number
|
|
|
|
proxyInfo?: any
|
|
|
|
requestBody?: any
|
|
|
|
requestId: string
|
|
|
|
tabId: number
|
|
|
|
timeStamp: number
|
|
|
|
type: ResourceType
|
|
|
|
url: string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
function search(searchProperties: {query: string, engine?: string, tabId?: number}): void
|
2020-06-18 21:57:16 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|