add firefox extension template

This commit is contained in:
2025-08-07 16:03:16 -05:00
parent 6cbb29fed1
commit 5df289ffcb
586 changed files with 13636 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
package webextension_polyfill.menus;
/**
The different contexts a menu can appear in. Specifying 'all' is equivalent to the combination of all other contexts
except for 'tab' and 'tools_menu'.
**/
typedef ContextType = String;

View File

@@ -0,0 +1,93 @@
package webextension_polyfill.menus;
typedef CreateCreatePropertiesType = {
/**
The type of menu item. Defaults to 'normal' if not specified.
Optional.
**/
@:optional
var type : ItemType;
/**
The unique ID to assign to this item. Mandatory for event pages. Cannot be the same as another ID for this extension.
Optional.
**/
@:optional
var id : String;
/**
Optional.
**/
@:optional
var icons : haxe.DynamicAccess<String>;
/**
The text to be displayed in the item; this is <em>required</em> unless <code>type</code> is 'separator'.
When the context is 'selection', you can use <code>%s</code> within the string to show the selected text. For example,
if this parameter's value is "Translate '%s' to Pig Latin" and the user selects the word "cool",
the context menu item for the selection is "Translate 'cool' to Pig Latin".
Optional.
**/
@:optional
var title : String;
/**
The initial state of a checkbox or radio item: true for selected and false for unselected.
Only one radio item can be selected at a time in a given group of radio items.
Optional.
**/
@:optional
var checked : Bool;
/**
List of contexts this menu item will appear in. Defaults to ['page'] if not specified.
Optional.
**/
@:optional
var contexts : Array<ContextType>;
/**
List of view types where the menu item will be shown. Defaults to any view, including those without a viewType.
Optional.
**/
@:optional
var viewTypes : Array<webextension_polyfill.extension.ViewType>;
/**
Whether the item is visible in the menu.
Optional.
**/
@:optional
var visible : Bool;
/**
A function that will be called back when the menu item is clicked. Event pages cannot use this; instead,
they should register a listener for $(ref:contextMenus.onClicked).
**/
@:optional
function onclick(info:OnClickData, tab:webextension_polyfill.tabs.Tab):Void;
/**
The ID of a parent menu item; this makes the item a child of a previously added item.
Optional.
**/
@:optional
var parentId : ts.AnyOf2<String, Float>;
/**
Lets you restrict the item to apply only to documents whose URL matches one of the given patterns.
(This applies to frames as well.) For details on the format of a pattern, see $(topic:match_patterns)[Match Patterns].
Optional.
**/
@:optional
var documentUrlPatterns : Array<String>;
/**
Similar to documentUrlPatterns, but lets you filter based on the src attribute of img/audio/video tags and the href of
anchor tags.
Optional.
**/
@:optional
var targetUrlPatterns : Array<String>;
/**
Whether this context menu item is enabled or disabled. Defaults to true.
Optional.
**/
@:optional
var enabled : Bool;
/**
Specifies a command to issue for the context click.
Optional.
**/
@:optional
var command : String;
};

View File

@@ -0,0 +1,6 @@
package webextension_polyfill.menus;
/**
The type of menu item.
**/
typedef ItemType = String;

View File

@@ -0,0 +1,110 @@
package webextension_polyfill.menus;
/**
Information sent when a context menu item is clicked.
**/
typedef OnClickData = {
/**
The ID of the menu item that was clicked.
**/
var menuItemId : ts.AnyOf2<String, Float>;
/**
The parent ID, if any, for the item clicked.
Optional.
**/
@:optional
var parentMenuItemId : ts.AnyOf2<String, Float>;
/**
The type of view where the menu is clicked. May be unset if the menu is not associated with a view.
Optional.
**/
@:optional
var viewType : webextension_polyfill.extension.ViewType;
/**
One of 'image', 'video', or 'audio' if the context menu was activated on one of these types of elements.
Optional.
**/
@:optional
var mediaType : String;
/**
If the element is a link, the text of that link.
Optional.
**/
@:optional
var linkText : String;
/**
If the element is a link, the URL it points to.
Optional.
**/
@:optional
var linkUrl : String;
/**
Will be present for elements with a 'src' URL.
Optional.
**/
@:optional
var srcUrl : String;
/**
The URL of the page where the menu item was clicked. This property is not set if the click occured in a context where
there is no current page, such as in a launcher context menu.
Optional.
**/
@:optional
var pageUrl : String;
/**
The id of the frame of the element where the context menu was clicked.
Optional.
**/
@:optional
var frameId : Float;
/**
The URL of the frame of the element where the context menu was clicked, if it was in a frame.
Optional.
**/
@:optional
var frameUrl : String;
/**
The text for the context selection, if any.
Optional.
**/
@:optional
var selectionText : String;
/**
A flag indicating whether the element is editable (text input, textarea, etc.).
**/
var editable : Bool;
/**
A flag indicating the state of a checkbox or radio item before it was clicked.
Optional.
**/
@:optional
var wasChecked : Bool;
/**
A flag indicating the state of a checkbox or radio item after it is clicked.
Optional.
**/
@:optional
var checked : Bool;
/**
The id of the bookmark where the context menu was clicked, if it was on a bookmark.
Optional.
**/
@:optional
var bookmarkId : String;
/**
An array of keyboard modifiers that were held while the menu item was clicked.
**/
var modifiers : Array<webextension_polyfill.action.OnClickDataModifiersItemEnum>;
/**
An integer value of button by which menu item was clicked.
Optional.
**/
@:optional
var button : Float;
/**
An identifier of the clicked element, if any. Use menus.getTargetElement in the page to find the corresponding element.
Optional.
**/
@:optional
var targetElementId : Float;
};

View File

@@ -0,0 +1,3 @@
package webextension_polyfill.menus;
typedef OnClickDataModifiersItemEnum = webextension_polyfill.action.OnClickDataModifiersItemEnum;

View File

@@ -0,0 +1,63 @@
package webextension_polyfill.menus;
/**
Information about the context of the menu action and the created menu items. For more information about each property,
see OnClickData. The following properties are only set if the extension has host permissions for the given context:
linkUrl, linkText, srcUrl, pageUrl, frameUrl, selectionText.
**/
typedef OnShownInfoType = {
/**
A list of IDs of the menu items that were shown.
**/
var menuIds : Array<ts.AnyOf2<String, Float>>;
/**
A list of all contexts that apply to the menu.
**/
var contexts : Array<ContextType>;
/**
Optional.
**/
@:optional
var viewType : webextension_polyfill.extension.ViewType;
var editable : Bool;
/**
Optional.
**/
@:optional
var mediaType : String;
/**
Optional.
**/
@:optional
var linkUrl : String;
/**
Optional.
**/
@:optional
var linkText : String;
/**
Optional.
**/
@:optional
var srcUrl : String;
/**
Optional.
**/
@:optional
var pageUrl : String;
/**
Optional.
**/
@:optional
var frameUrl : String;
/**
Optional.
**/
@:optional
var selectionText : String;
/**
Optional.
**/
@:optional
var targetElementId : Float;
};

View File

@@ -0,0 +1,29 @@
package webextension_polyfill.menus;
typedef OverrideContextContextOptionsType = {
/**
Whether to also include default menu items in the menu.
Optional.
**/
@:optional
var showDefaults : Bool;
/**
ContextType to override, to allow menu items from other extensions in the menu. Currently only 'bookmark' and 'tab' are
supported. showDefaults cannot be used with this option.
Optional.
**/
@:optional
var context : OverrideContextContextOptionsTypeContextEnum;
/**
Required when context is 'bookmark'. Requires 'bookmark' permission.
Optional.
**/
@:optional
var bookmarkId : String;
/**
Required when context is 'tab'. Requires 'tabs' permission.
Optional.
**/
@:optional
var tabId : Float;
};

View File

@@ -0,0 +1,7 @@
package webextension_polyfill.menus;
/**
ContextType to override, to allow menu items from other extensions in the menu. Currently only 'bookmark' and 'tab' are
supported. showDefaults cannot be used with this option.
**/
typedef OverrideContextContextOptionsTypeContextEnum = String;

View File

@@ -0,0 +1,54 @@
package webextension_polyfill.menus;
typedef Static = {
/**
Creates a new context menu item. Note that if an error occurs during creation, you may not find out until the creation
callback fires (the details will be in $(ref:runtime.lastError)).
**/
function create(createProperties:CreateCreatePropertiesType, ?callback:() -> Void):ts.AnyOf2<String, Float>;
/**
Updates a previously created context menu item.
**/
function update(id:ts.AnyOf2<String, Float>, updateProperties:UpdateUpdatePropertiesType):js.lib.Promise<ts.Undefined>;
/**
Removes a context menu item.
**/
function remove(menuItemId:ts.AnyOf2<String, Float>):js.lib.Promise<ts.Undefined>;
/**
Removes all context menu items added by this extension.
**/
function removeAll():js.lib.Promise<ts.Undefined>;
/**
Show the matching menu items from this extension instead of the default menu. This should be called during a
'contextmenu' DOM event handler, and only applies to the menu that opens after this event.
**/
function overrideContext(contextOptions:OverrideContextContextOptionsType):Void;
/**
Updates the extension items in the shown menu, including changes that have been made since the menu was shown.
Has no effect if the menu is hidden. Rebuilding a shown menu is an expensive operation,
only invoke this method when necessary.
**/
function refresh():js.lib.Promise<ts.Undefined>;
/**
Retrieve the element that was associated with a recent contextmenu event.
**/
function getTargetElement(targetElementId:Float):js.html.DOMElement;
/**
Fired when a context menu item is clicked.
**/
var onClicked : webextension_polyfill.events.Event<(info:OnClickData, tab:Null<webextension_polyfill.tabs.Tab>) -> Void>;
/**
Fired when a menu is shown. The extension can add, modify or remove menu items and call menus.refresh()
to update the menu.
**/
var onShown : webextension_polyfill.events.Event<(info:OnShownInfoType, tab:webextension_polyfill.tabs.Tab) -> Void>;
/**
Fired when a menu is hidden. This event is only fired if onShown has fired before.
**/
var onHidden : webextension_polyfill.events.Event<() -> Void>;
/**
The maximum number of top level extension items that can be added to an extension action context menu.
Any items beyond this limit will be ignored.
**/
var ACTION_MENU_TOP_LEVEL_LIMIT : Int;
};

View File

@@ -0,0 +1,66 @@
package webextension_polyfill.menus;
/**
The properties to update. Accepts the same values as the create function.
**/
typedef UpdateUpdatePropertiesType = {
/**
Optional.
**/
@:optional
var type : ItemType;
/**
Optional.
**/
@:optional
var icons : haxe.DynamicAccess<String>;
/**
Optional.
**/
@:optional
var title : String;
/**
Optional.
**/
@:optional
var checked : Bool;
/**
Optional.
**/
@:optional
var contexts : Array<ContextType>;
/**
Optional.
**/
@:optional
var viewTypes : Array<webextension_polyfill.extension.ViewType>;
/**
Whether the item is visible in the menu.
Optional.
**/
@:optional
var visible : Bool;
@:optional
function onclick(info:OnClickData, tab:webextension_polyfill.tabs.Tab):Void;
/**
Note: You cannot change an item to be a child of one of its own descendants.
Optional.
**/
@:optional
var parentId : ts.AnyOf2<String, Float>;
/**
Optional.
**/
@:optional
var documentUrlPatterns : Array<String>;
/**
Optional.
**/
@:optional
var targetUrlPatterns : Array<String>;
/**
Optional.
**/
@:optional
var enabled : Bool;
};