mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-23 04:47:24 +08:00
Merge pull request #5802 from luukd/master
Added Safari extension API definitions
This commit is contained in:
64
safari-extension/safari-extension-content-tests.ts
Normal file
64
safari-extension/safari-extension-content-tests.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
/// <reference path="safari-extension-content.d.ts" />
|
||||
|
||||
// https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/AddingExtensionToolbars/AddingExtensionToolbars.html#//apple_ref/doc/uid/TP40009977-CH5-SW7
|
||||
var theBody = document.body;
|
||||
// create a para and insert it at the top of the body
|
||||
var element = document.createElement("p");
|
||||
element.id = "status";
|
||||
element.style.cssText = "float:right; color:red";
|
||||
element.textContent = "Waiting...";
|
||||
theBody.insertBefore(element, theBody.firstChild);
|
||||
|
||||
function replyToMessage(aMessageEvent: SafariExtensionMessageEvent) {
|
||||
if (aMessageEvent.name === "hey") {
|
||||
document.getElementById("status").textContent="Message received.";
|
||||
safari.self.tab.dispatchMessage("gotIt","Message acknowledged.");
|
||||
}
|
||||
}
|
||||
// register for message events
|
||||
safari.self.addEventListener("message", replyToMessage, false);
|
||||
|
||||
// https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/AddingContextualMenuItems/AddingContextualMenuItems.html#//apple_ref/doc/uid/TP40009977-CH4-SW15
|
||||
document.addEventListener("contextmenu", handleContextMenu, false);
|
||||
|
||||
function handleContextMenu(event: MouseEvent) {
|
||||
safari.self.tab.setContextMenuEventUserInfo(event, (<Node>event.target).nodeName);
|
||||
}
|
||||
|
||||
// https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/AddingContextualMenuItems/AddingContextualMenuItems.html#//apple_ref/doc/uid/TP40009977-CH4-SW16
|
||||
document.addEventListener("contextmenu", handleContextMenu2, false);
|
||||
|
||||
function handleContextMenu2(event: MouseEvent) {
|
||||
if ((<Node>event.target).nodeName == "VIDEO") {
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
// https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/MessagesandProxies/MessagesandProxies.html#//apple_ref/doc/uid/TP40009977-CH14-SW2
|
||||
var initialVal=1;
|
||||
var calculatedVal=0 ;
|
||||
|
||||
function doBigCalc(theData: number) {
|
||||
safari.self.tab.dispatchMessage("calcThis",theData);
|
||||
}
|
||||
|
||||
function getAnswer(theMessageEvent: SafariExtensionMessageEvent) {
|
||||
if (theMessageEvent.name === "theAnswer") {
|
||||
calculatedVal=theMessageEvent.message;
|
||||
console.log(calculatedVal);
|
||||
}
|
||||
}
|
||||
safari.self.addEventListener("message", getAnswer, false);
|
||||
|
||||
doBigCalc(initialVal);
|
||||
|
||||
//https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/MessagesandProxies/MessagesandProxies.html#//apple_ref/doc/uid/TP40009977-CH14-SW9
|
||||
function isItOkay(event: BeforeLoadEvent) {
|
||||
var myMessageData = event.url;
|
||||
var theAnswer = safari.self.tab.canLoad(event, myMessageData);
|
||||
if (theAnswer == "block") {
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("beforeload", isItOkay, true);
|
||||
110
safari-extension/safari-extension-content.d.ts
vendored
Normal file
110
safari-extension/safari-extension-content.d.ts
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
// Type definitions for Safari extension development (content-scripts)
|
||||
// Project: https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/InjectingScripts/InjectingScripts.html#//apple_ref/doc/uid/TP40009977-CH6-SW1
|
||||
// Definitions by: Luuk <https://github.com/luukd>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
interface Window {
|
||||
safari: typeof safari;
|
||||
}
|
||||
|
||||
declare module safari {
|
||||
export var extension: SafariContentExtension;
|
||||
export var self: SafariContentWebPage;
|
||||
}
|
||||
|
||||
interface SafariEvent {
|
||||
/**
|
||||
* The type of the event.
|
||||
* The string used to identify a particular type of event is documented in the reference for that class.
|
||||
*/
|
||||
type: string;
|
||||
|
||||
/**
|
||||
* The target of the event.
|
||||
* This attribute stays the same as the event moves through the event-dispatch hierarchy. Its value is the same as the object that the event is sent to during the targeting phase.
|
||||
*/
|
||||
target: SafariEventTarget;
|
||||
|
||||
/**
|
||||
* The object that the event is currently being sent to.
|
||||
* This attribute varies as the event progresses through the phases, changing as the event moves through the event-dispatch hierarchy.
|
||||
*/
|
||||
currentTarget: SafariEventTarget;
|
||||
|
||||
/**
|
||||
* The time and date that the event was created.
|
||||
*/
|
||||
timestamp: number;
|
||||
|
||||
/**
|
||||
* The event-handling phase that the event is in.
|
||||
* The values for this property are the same as the values used by Webkit to identify the event-handling phases.
|
||||
*/
|
||||
eventPhase: number;
|
||||
|
||||
/**
|
||||
* A Boolean value that indicates whether the event goes through the bubbling phase.
|
||||
*/
|
||||
bubbles: boolean;
|
||||
|
||||
/**
|
||||
* A Boolean value that indicates whether the event can be canceled.
|
||||
*/
|
||||
cancelable: boolean;
|
||||
|
||||
/**
|
||||
* A Boolean value that indicates whether the event’s default action has been prevented.
|
||||
*/
|
||||
defaultPrevented: boolean;
|
||||
|
||||
/**
|
||||
* Prevents the event from any further propagation.
|
||||
* Propagation can be stopped only fon cancelable events. After propagation is stopped, the event is not sent to any other targets.
|
||||
*/
|
||||
stopPropagation() : void;
|
||||
|
||||
/**
|
||||
* Prevents the browser from performing the default action for an event.
|
||||
* Use this method to indicate that your extension has already fully handled the event; you don’t want the browser to do anything. Note that preventing the default action does not stop an event from propagating.
|
||||
*/
|
||||
preventDefault(): void;
|
||||
}
|
||||
|
||||
interface SafariExtensionMessageEvent extends SafariEvent {
|
||||
/**
|
||||
* The name of the message.
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* The message data.
|
||||
*/
|
||||
message: any;
|
||||
}
|
||||
|
||||
interface SafariEventListener extends Function {
|
||||
(event: SafariEvent): any;
|
||||
}
|
||||
|
||||
interface SafariEventTarget {
|
||||
addEventListener(type: string, listener: SafariEventListener, useCapture?: boolean): void;
|
||||
removeEventListener(type: string, listener: SafariEventListener, useCapture?: boolean): void;
|
||||
}
|
||||
|
||||
interface SafariContentExtension {
|
||||
baseURI: string;
|
||||
}
|
||||
|
||||
interface SafariContentWebPage extends SafariEventTarget {
|
||||
tab: SafariContentBrowserTabProxy;
|
||||
}
|
||||
|
||||
interface SafariContentBrowserTabProxy {
|
||||
canLoad(event: any, message: any): any;
|
||||
dispatchMessage(name: string, message?: any): void;
|
||||
setContextMenuEventUserInfo(event: MouseEvent, userInfo: any): void;
|
||||
}
|
||||
|
||||
interface BeforeLoadEvent extends Event {
|
||||
url: string;
|
||||
}
|
||||
159
safari-extension/safari-extension-tests.ts
Normal file
159
safari-extension/safari-extension-tests.ts
Normal file
@@ -0,0 +1,159 @@
|
||||
/// <reference path="safari-extension.d.ts" />
|
||||
|
||||
// https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/AccessingResourcesWithinYourExtensionFolder/AccessingResourcesWithinYourExtensionFolder.html#//apple_ref/doc/uid/TP40009977-CH18-SW2
|
||||
var img = document.createElement("img");
|
||||
img.src = safari.extension.baseURI + 'Images/myImage.png'
|
||||
|
||||
// https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/AddingExtensionToolbars/AddingExtensionToolbars.html#//apple_ref/doc/uid/TP40009977-CH5-SW2
|
||||
const bars = safari.extension.bars;
|
||||
const activeBrowserWindow = safari.application.activeBrowserWindow;
|
||||
for (var i = 0; i < bars.length; ++i) {
|
||||
var bar = bars[i];
|
||||
if (bar.browserWindow === activeBrowserWindow && bar.identifier === "Audio Controls") {
|
||||
/* Do something. */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var server = "http://developer.apple.com/";
|
||||
var reflib = "safari/library/documentation/AppleApplications/Reference/"
|
||||
function openInTab(source: string) {
|
||||
var newTab = (<SafariExtensionBar>safari.self).browserWindow.openTab();
|
||||
newTab.url = source;
|
||||
}
|
||||
|
||||
function sendMessage() {
|
||||
document.getElementById("textField").innerHTML = "Sending message...";
|
||||
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("hey", "there");
|
||||
}
|
||||
|
||||
function respondToMessage(messageEvent: SafariExtensionMessageEvent) {
|
||||
if (messageEvent.name === "gotIt")
|
||||
document.getElementById("textField").innerHTML = messageEvent.message;
|
||||
}
|
||||
|
||||
(<SafariExtensionBar>safari.self).browserWindow.addEventListener("message", respondToMessage, false);
|
||||
|
||||
const myBars = safari.extension.bars;
|
||||
function updateAllBars() {
|
||||
for (var i = 0; i < myBars.length; ++i) {
|
||||
var barWindow = <any>myBars[i].contentWindow;
|
||||
barWindow.doSomething();
|
||||
var myWindow = safari.application.activeBrowserWindow;
|
||||
if (myBars[i].browserWindow == myWindow) {
|
||||
barWindow.doSomethingSpecial();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/AddingaGlobalHTMLPage/AddingaGlobalHTMLPage.html#//apple_ref/doc/uid/TP40009977-CH16-SW2
|
||||
const myGlobal: any = safari.extension.globalPage.contentWindow;
|
||||
|
||||
function doButton() {
|
||||
myGlobal.calcThis(myGlobal.theAnswer);
|
||||
var mButton = <HTMLButtonElement>document.getElementById("myButton");
|
||||
mButton.value = ("Increment " + myGlobal.theAnswer);
|
||||
}
|
||||
|
||||
// https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/AddingButtonstotheMainSafariToolbar/AddingButtonstotheMainSafariToolbar.html#//apple_ref/doc/uid/TP40009977-CH3-SW12
|
||||
var itemArray = safari.extension.toolbarItems;
|
||||
for (var i = 0; i < itemArray.length; ++i) {
|
||||
var item = itemArray[i];
|
||||
if (item.identifier == "my lovely button") {
|
||||
/* Do something. */
|
||||
}
|
||||
}
|
||||
|
||||
// https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/AddingButtonstotheMainSafariToolbar/AddingButtonstotheMainSafariToolbar.html#//apple_ref/doc/uid/TP40009977-CH3-SW8
|
||||
function performCommand(event: SafariCommandEvent) {
|
||||
if (event.command === "reload-page") {
|
||||
var currentURL = (<SafariExtensionToolbarItem>event.target).browserWindow.activeTab.url;
|
||||
if (currentURL)
|
||||
(<SafariExtensionToolbarItem>event.target).browserWindow.activeTab.url = currentURL;
|
||||
}
|
||||
}
|
||||
|
||||
function validateCommand(event: SafariValidateEvent) {
|
||||
if (event.command === "reload-page") {
|
||||
// Disable the button if there is no URL loaded in the tab.
|
||||
(<SafariExtensionToolbarItem>event.target).disabled = !(<SafariExtensionToolbarItem>event.target).browserWindow.activeTab.url;
|
||||
}
|
||||
}
|
||||
|
||||
// if event handlers are in the global HTML page,
|
||||
// register with application:
|
||||
safari.application.addEventListener("command", performCommand, false);
|
||||
safari.application.addEventListener("validate", validateCommand, false);
|
||||
// if event handlers are in an extension bar,
|
||||
// register with parent window:
|
||||
(<SafariExtensionBar>safari.self).browserWindow.addEventListener("command", performCommand, false);
|
||||
(<SafariExtensionBar>safari.self).browserWindow.addEventListener("validate", validateCommand, false);
|
||||
|
||||
// https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/AddingExtensionMenus/AddingExtensionMenus.html#//apple_ref/doc/uid/TP40009977-CH20-SW8
|
||||
var myMenu = safari.extension.createMenu("menuId");
|
||||
safari.extension.removeMenu("menuId");
|
||||
myMenu.removeMenuItem(0);
|
||||
myMenu.appendMenuItem("identifier", "title");
|
||||
myMenu.insertMenuItem(1, "identifier", "title");
|
||||
myMenu.appendSeparator("identifier");
|
||||
myMenu.insertSeparator(1, "identifier");
|
||||
|
||||
// https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/AddingPopovers/AddingPopovers.html#//apple_ref/doc/uid/TP40009977-CH21-SW7
|
||||
var validateHandler = (event: SafariValidateEvent) => {
|
||||
if ((<SafariExtensionPopover>event.target).identifier !== "myToolbarItemID") return;
|
||||
};
|
||||
var popoverHandler = (event: SafariEvent) => {
|
||||
if ((<SafariExtensionPopover>event.target).identifier !== "myToolbarItemID") return;
|
||||
};
|
||||
safari.application.addEventListener("validate", validateHandler, true);
|
||||
safari.application.addEventListener("popover", popoverHandler, true);
|
||||
|
||||
// https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/AddingPopovers/AddingPopovers.html#//apple_ref/doc/uid/TP40009977-CH21-SW8
|
||||
var width = 400;
|
||||
var height = 400;
|
||||
var myPop = safari.extension.createPopover("myPopoverID", safari.extension.baseURI + "myFile.html", width, height);
|
||||
|
||||
var myToolbarItem = safari.extension.toolbarItems[0];
|
||||
myToolbarItem.popover = myPop;
|
||||
myToolbarItem.popover = null;
|
||||
safari.extension.removePopover("myPopoverID");
|
||||
|
||||
// https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/AddingContextualMenuItems/AddingContextualMenuItems.html#//apple_ref/doc/uid/TP40009977-CH4-SW17
|
||||
safari.application.addEventListener("contextmenu", handleContextMenu, false);
|
||||
|
||||
function handleContextMenu(event: SafariExtensionContextMenuEvent) {
|
||||
if (event.userInfo === "IMG") {
|
||||
event.contextMenu.appendContextMenuItem("enlarge", "Enlarge Item");
|
||||
}
|
||||
}
|
||||
|
||||
// https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/MessagesandProxies/MessagesandProxies.html#//apple_ref/doc/uid/TP40009977-CH14-SW2
|
||||
function bigCalc(startVal: number, event: SafariExtensionMessageEvent) {
|
||||
// imagine hundreds of lines of code here...
|
||||
var endVal = startVal + 2;
|
||||
// return to sender
|
||||
(<SafariBrowserTab>event.target).page.dispatchMessage("theAnswer", endVal);
|
||||
}
|
||||
|
||||
function respondToMessage2(theMessageEvent: SafariExtensionMessageEvent) {
|
||||
if (theMessageEvent.name === "calcThis") {
|
||||
var startVal = theMessageEvent.message;
|
||||
bigCalc(startVal, theMessageEvent);
|
||||
}
|
||||
}
|
||||
|
||||
safari.application.addEventListener("message", respondToMessage2, false);
|
||||
|
||||
// https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/ExtensionSettings/ExtensionSettings.html#//apple_ref/doc/uid/TP40009977-CH11-SW13
|
||||
var myVolume: number;
|
||||
function volumeChanged(event: SafariExtensionSettingsChangeEvent) {
|
||||
if (event.key == "volume") {
|
||||
myVolume = event.newValue;
|
||||
}
|
||||
}
|
||||
|
||||
safari.extension.settings.addEventListener("change", volumeChanged, false);
|
||||
safari.extension.settings["volume"] = myVolume;
|
||||
safari.extension.settings.setItem("volume", myVolume);
|
||||
safari.extension.secureSettings["volume"] = myVolume;
|
||||
safari.extension.secureSettings.setItem("volume", myVolume);
|
||||
457
safari-extension/safari-extension.d.ts
vendored
Normal file
457
safari-extension/safari-extension.d.ts
vendored
Normal file
@@ -0,0 +1,457 @@
|
||||
// Type definitions for Safari extension development
|
||||
// Project: https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40009977-CH1-SW1
|
||||
// Definitions by: Luuk <https://github.com/luukd>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
interface Window {
|
||||
safari: typeof safari;
|
||||
}
|
||||
|
||||
declare module safari {
|
||||
export var application: SafariApplication;
|
||||
export var extension: SafariExtension;
|
||||
export var self: SafariExtensionGlobalPage | SafariExtensionBar;
|
||||
}
|
||||
|
||||
interface SafariEvent {
|
||||
/**
|
||||
* The type of the event.
|
||||
* The string used to identify a particular type of event is documented in the reference for that class.
|
||||
*/
|
||||
type: string;
|
||||
|
||||
/**
|
||||
* The target of the event.
|
||||
* This attribute stays the same as the event moves through the event-dispatch hierarchy. Its value is the same as the object that the event is sent to during the targeting phase.
|
||||
*/
|
||||
target: SafariEventTarget;
|
||||
|
||||
/**
|
||||
* The object that the event is currently being sent to.
|
||||
* This attribute varies as the event progresses through the phases, changing as the event moves through the event-dispatch hierarchy.
|
||||
*/
|
||||
currentTarget: SafariEventTarget;
|
||||
|
||||
/**
|
||||
* The time and date that the event was created.
|
||||
*/
|
||||
timestamp: number;
|
||||
|
||||
/**
|
||||
* The event-handling phase that the event is in.
|
||||
* The values for this property are the same as the values used by Webkit to identify the event-handling phases.
|
||||
*/
|
||||
eventPhase: number;
|
||||
|
||||
/**
|
||||
* A Boolean value that indicates whether the event goes through the bubbling phase.
|
||||
*/
|
||||
bubbles: boolean;
|
||||
|
||||
/**
|
||||
* A Boolean value that indicates whether the event can be canceled.
|
||||
*/
|
||||
cancelable: boolean;
|
||||
|
||||
/**
|
||||
* A Boolean value that indicates whether the event’s default action has been prevented.
|
||||
*/
|
||||
defaultPrevented: boolean;
|
||||
|
||||
/**
|
||||
* Prevents the event from any further propagation.
|
||||
* Propagation can be stopped only fon cancelable events. After propagation is stopped, the event is not sent to any other targets.
|
||||
*/
|
||||
stopPropagation() : void;
|
||||
|
||||
/**
|
||||
* Prevents the browser from performing the default action for an event.
|
||||
* Use this method to indicate that your extension has already fully handled the event; you don’t want the browser to do anything. Note that preventing the default action does not stop an event from propagating.
|
||||
*/
|
||||
preventDefault(): void;
|
||||
}
|
||||
|
||||
interface SafariEventListener extends Function {
|
||||
(event: SafariEvent): any;
|
||||
}
|
||||
|
||||
interface SafariEventTarget {
|
||||
addEventListener(type: string, listener: SafariEventListener, useCapture?: boolean): void;
|
||||
removeEventListener(type: string, listener: SafariEventListener, useCapture?: boolean): void;
|
||||
}
|
||||
|
||||
interface SafariBrowserWindow extends SafariEventTarget {
|
||||
tabs: Array<SafariBrowserTab>;
|
||||
visible: boolean;
|
||||
activeTab: SafariBrowserTab;
|
||||
|
||||
activate(): void;
|
||||
close(): void;
|
||||
|
||||
/**
|
||||
* Opens a new tab in the window.
|
||||
* Available in Safari 5.0 and later.
|
||||
* @param visibility Either foreground if the tab should be opened in the foreground, or background if it should be opened in the background.
|
||||
* @param index The desired location of the new tab.
|
||||
* @returns A new tab.
|
||||
*/
|
||||
openTab (visibility?: string, index?: number): SafariBrowserTab;
|
||||
insertTab(tab: SafariBrowserTab, index: number): SafariBrowserTab;
|
||||
}
|
||||
|
||||
interface SafariBrowserTab extends SafariEventTarget {
|
||||
browserWindow: SafariBrowserWindow;
|
||||
reader: SafariReader;
|
||||
|
||||
/**
|
||||
* The tab’s current title.
|
||||
* The tab’s title is the same as the title of the webpage in most cases. For example, the title of the webpage may be truncated for display, but the value of this property is not truncated.
|
||||
* Available in Safari 5.0 and later.
|
||||
*/
|
||||
title: string;
|
||||
page: SafariWebPageProxy;
|
||||
|
||||
/**
|
||||
* The URL loaded in this tab.
|
||||
* Setting this attribute to a new value loads the page at the new URL in the tab.
|
||||
* Available in Safari 5.0 and later.
|
||||
*/
|
||||
url: string;
|
||||
|
||||
visibleContentsAsDataURL(): string;
|
||||
activate(): void;
|
||||
close(): void;
|
||||
}
|
||||
|
||||
interface SafariReader extends SafariEventTarget {
|
||||
available: boolean;
|
||||
tab: SafariBrowserTab;
|
||||
visible: boolean;
|
||||
|
||||
enter(): void;
|
||||
exit(): void;
|
||||
dispatchMessage (name: string, message?: any): void;
|
||||
}
|
||||
|
||||
interface SafariWebPageProxy {
|
||||
dispatchMessage (name: string, message?: any): void;
|
||||
}
|
||||
|
||||
interface SafariExtensionGlobalPage {
|
||||
contentWindow: Window;
|
||||
}
|
||||
|
||||
interface SafariExtensionPopover extends SafariEventTarget {
|
||||
identifier: string;
|
||||
visible: boolean;
|
||||
|
||||
contentWindow: Window;
|
||||
height: number;
|
||||
width: number;
|
||||
|
||||
hide(): void;
|
||||
}
|
||||
|
||||
interface SafariExtensionMenu {
|
||||
identifier: string;
|
||||
menuItems: Array<SafariExtensionMenuItem>;
|
||||
visible: boolean;
|
||||
|
||||
appendMenuItem (identifier: string, title: string, command?: string): SafariExtensionMenuItem;
|
||||
appendSeparator (identifier: string): SafariExtensionMenuItem;
|
||||
insertMenuItem (index: number, identifier: string, title: string, command?: string): SafariExtensionMenuItem;
|
||||
insertSeparator (index: number, identifier: string): SafariExtensionMenuItem;
|
||||
removeMenuItem (index: number): void;
|
||||
}
|
||||
|
||||
interface SafariExtensionMenuItem extends SafariEventTarget {
|
||||
command: string;
|
||||
identifier: string;
|
||||
separator: boolean;
|
||||
title: string;
|
||||
image: string;
|
||||
submenu: SafariExtensionMenu;
|
||||
|
||||
visible: boolean;
|
||||
disabled: boolean;
|
||||
checkedState: number;
|
||||
}
|
||||
|
||||
interface SafariExtensionSettings extends SafariEventTarget {
|
||||
[index: string]: any;
|
||||
[index: number]: any;
|
||||
getItem(key: string): any;
|
||||
setItem(key: string, value: any): void;
|
||||
removeItem(key: string): void;
|
||||
clear(): void;
|
||||
}
|
||||
|
||||
interface SafariExtensionSecureSettings extends SafariEventTarget {
|
||||
[index: string]: any;
|
||||
getItem(key: string): any;
|
||||
setItem(key: string, value: any): void;
|
||||
removeItem(key: string): void;
|
||||
clear(): void;
|
||||
}
|
||||
|
||||
interface SafariExtensionBar extends SafariEventTarget {
|
||||
identifier: string;
|
||||
label: string;
|
||||
visible: boolean;
|
||||
browserWindow: SafariBrowserWindow;
|
||||
contentWindow: Window;
|
||||
|
||||
hide(doNotRemember?: boolean): void;
|
||||
show(doNotRemember?: boolean): void;
|
||||
}
|
||||
|
||||
interface SafariExtensionToolbarItem extends SafariEventTarget {
|
||||
|
||||
/**
|
||||
* The current badge number.
|
||||
*/
|
||||
badge: number;
|
||||
|
||||
/**
|
||||
* The URL of the current image.
|
||||
*/
|
||||
image: string;
|
||||
|
||||
/**
|
||||
* The label of the toolbar item, as shown in the toolbar’s overflow menu.
|
||||
*/
|
||||
label: string;
|
||||
|
||||
/**
|
||||
* The label of the toolbar item, as shown in the Customize palette.
|
||||
* This attribute is optional; its value defaults to the value of label.
|
||||
*/
|
||||
paletteLabel: string;
|
||||
|
||||
/**
|
||||
* The tooltip (help tag) of the toolbar item.
|
||||
* This attribute is optional; its value defaults to the value of label.
|
||||
*/
|
||||
toolTip: string;
|
||||
menu: SafariExtensionMenu;
|
||||
popover: SafariExtensionPopover;
|
||||
browserWindow: SafariBrowserWindow;
|
||||
command: string;
|
||||
disabled: boolean;
|
||||
identifier: string;
|
||||
|
||||
showMenu(): void;
|
||||
showPopover(): void;
|
||||
validate(): void;
|
||||
}
|
||||
|
||||
interface SafariPrivateBrowsing {
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
interface SafariExtension {
|
||||
bars: Array<SafariExtensionBar>;
|
||||
baseURI: string;
|
||||
globalPage: SafariExtensionGlobalPage;
|
||||
toolbarItems: Array<SafariExtensionToolbarItem>;
|
||||
|
||||
displayVersion: string;
|
||||
bundleVersion: string;
|
||||
|
||||
menus: Array<SafariExtensionMenu>;
|
||||
createMenu (identifier: string): SafariExtensionMenu;
|
||||
removeMenu (identifier: string): void;
|
||||
|
||||
popovers: Array<SafariExtensionPopover>;
|
||||
createPopover(identifier: string, url: string, width?: number, height?: number): SafariExtensionPopover;
|
||||
removePopover(identifier: string): void;
|
||||
|
||||
addContentScript (source: string, whitelist: Array<string>, blacklist: Array<string>, runAtEnd: boolean): string;
|
||||
addContentScriptFromURL (url: string, whitelist: Array<string>, blacklist: Array<string>, runAtEnd: boolean): string;
|
||||
addContentStyleSheet (source: string, whitelist: Array<string>, blacklist: Array<string>): string;
|
||||
addContentStyleSheetFromURL (url: string, whitelist: Array<string>, blacklist: Array<string>): string;
|
||||
removeContentScript(url: string): void;
|
||||
removeContentScripts(): void;
|
||||
removeContentStyleSheet(url: string): void;
|
||||
removeContentStyleSheets(): void;
|
||||
|
||||
settings: SafariExtensionSettings;
|
||||
secureSettings: SafariExtensionSecureSettings;
|
||||
}
|
||||
|
||||
interface SafariApplication extends SafariEventTarget {
|
||||
activeBrowserWindow: SafariBrowserWindow;
|
||||
browserWindows: Array<SafariBrowserWindow>;
|
||||
privateBrowsing: SafariPrivateBrowsing;
|
||||
openBrowserWindow(): SafariBrowserWindow;
|
||||
}
|
||||
|
||||
interface SafariExtensionContextMenuEvent extends SafariEvent {
|
||||
/**
|
||||
* The target of the event.
|
||||
* This attribute stays the same as the event moves through the event-dispatch hierarchy. Its value is the same as the object that the event is sent to during the targeting phase.
|
||||
*/
|
||||
target: SafariExtensionContextMenuItem;
|
||||
|
||||
/**
|
||||
* The object that the event is currently being sent to.
|
||||
* This attribute varies as the event progresses through the phases, changing as the event moves through the event-dispatch hierarchy.
|
||||
*/
|
||||
currentTarget: SafariExtensionContextMenuItem;
|
||||
|
||||
/**
|
||||
* Information about the current context menu event.
|
||||
*/
|
||||
userInfo: any;
|
||||
|
||||
/**
|
||||
* The context menu being built up.
|
||||
*/
|
||||
contextMenu: SafariExtensionContextMenu;
|
||||
}
|
||||
|
||||
interface SafariExtensionContextMenu {
|
||||
/**
|
||||
* Returns a list of the context menu items from this extension.
|
||||
* Only menu items from your extension are returned.
|
||||
*/
|
||||
contextMenuItems: any[];
|
||||
|
||||
/**
|
||||
* Appends a menu item to the contextual menu.
|
||||
* If another menu item with the same identifier already exists, it is removed before appending the menu item. If command is not supplied, identifier is used as the command identifier.
|
||||
* @param identifier The unique identifier of the menu item.
|
||||
* @param title The title of the menu item.
|
||||
* @param command The command identifier that the context menu item sends when activated.
|
||||
* @returns The context menu item that was appended.
|
||||
*/
|
||||
appendContextMenuItem (identifier: string, title: string, command?: string) : SafariExtensionContextMenuItem;
|
||||
|
||||
/**
|
||||
* Inserts a menu item at a specific index in the contextual menu.
|
||||
* If another menu item with the same identifier already exists, it is removed before appending the menu item. If command is not supplied, identifier is used as the command identifier.
|
||||
* @param index The index where the menu item is being inserted.
|
||||
* @param identifier The unique identifier of the menu item.
|
||||
* @param title The title of the menu item.
|
||||
* @param command The command identifier that the context menu item sends when activated.
|
||||
* @returns The context menu item that was inserted.
|
||||
*/
|
||||
insertContextMenuItem (index: number, identifier: string, title: string, command?: string): SafariExtensionContextMenuItem;
|
||||
}
|
||||
|
||||
interface SafariExtensionContextMenuItem extends SafariEventTarget {
|
||||
/**
|
||||
* The command identifier that the context menu item sends when activated.
|
||||
* Setting an empty string, null, or undefined has no effect.
|
||||
*/
|
||||
command: string;
|
||||
|
||||
/**
|
||||
* A Boolean value that indicates whether a context menu item is disabled.
|
||||
* Disabled menu items are not displayed in the context menu.
|
||||
*/
|
||||
disabled: boolean;
|
||||
|
||||
/**
|
||||
* The unique identifier of the context menu item.
|
||||
*/
|
||||
identifier: string;
|
||||
|
||||
/**
|
||||
* The title displayed in the context menu.
|
||||
*/
|
||||
title: string;
|
||||
}
|
||||
|
||||
interface SafariValidateEvent extends SafariEvent {
|
||||
/**
|
||||
* The command identifier of the target being validated.
|
||||
*/
|
||||
command: string;
|
||||
}
|
||||
|
||||
interface SafariExtensionContextMenuItemValidateEvent {
|
||||
/**
|
||||
* The target of the event.
|
||||
* This attribute stays the same as the event moves through the event-dispatch hierarchy. Its value is the same as the object that the event is sent to during the targeting phase.
|
||||
*/
|
||||
target: SafariExtensionContextMenuItem;
|
||||
|
||||
/**
|
||||
* The object that the event is currently being sent to.
|
||||
* This attribute varies as the event progresses through the phases, changing as the event moves through the event-dispatch hierarchy.
|
||||
*/
|
||||
currentTarget: SafariExtensionContextMenuItem;
|
||||
|
||||
/**
|
||||
* Information about the current context menu event.
|
||||
*/
|
||||
userInfo: any;
|
||||
}
|
||||
|
||||
interface SafariCommandEvent extends SafariEvent {
|
||||
/**
|
||||
* The command identifier of the target being dispatched.
|
||||
*/
|
||||
command: string;
|
||||
}
|
||||
|
||||
interface SafariExtensionContextMenuItemCommandEvent extends SafariCommandEvent {
|
||||
/**
|
||||
* The target of the event.
|
||||
* This attribute stays the same as the event moves through the event-dispatch hierarchy. Its value is the same as the object that the event is sent to during the targeting phase.
|
||||
*/
|
||||
target: SafariExtensionContextMenuItem;
|
||||
|
||||
/**
|
||||
* The object that the event is currently being sent to.
|
||||
* This attribute varies as the event progresses through the phases, changing as the event moves through the event-dispatch hierarchy.
|
||||
*/
|
||||
currentTarget: SafariExtensionContextMenuItem;
|
||||
|
||||
/**
|
||||
* The user info object for this context menu event.
|
||||
*/
|
||||
userInfo: any;
|
||||
}
|
||||
|
||||
interface SafariExtensionSettingsChangeEvent extends SafariEvent {
|
||||
/**
|
||||
* The target of the event.
|
||||
* This attribute stays the same as the event moves through the event-dispatch hierarchy. Its value is the same as the object that the event is sent to during the targeting phase.
|
||||
*/
|
||||
target: SafariExtensionSettings|SafariExtensionSecureSettings;
|
||||
|
||||
/**
|
||||
* The object that the event is currently being sent to.
|
||||
* This attribute varies as the event progresses through the phases, changing as the event moves through the event-dispatch hierarchy.
|
||||
*/
|
||||
currentTarget: SafariExtensionSettings|SafariExtensionSecureSettings;
|
||||
|
||||
/**
|
||||
* The key identifier of the setting that was changed.
|
||||
*/
|
||||
key: string;
|
||||
|
||||
/**
|
||||
* The value before the settings change.
|
||||
*/
|
||||
oldValue: any;
|
||||
|
||||
/**
|
||||
* The value after the settings change.
|
||||
*/
|
||||
newValue: any;
|
||||
}
|
||||
|
||||
interface SafariExtensionMessageEvent extends SafariEvent {
|
||||
/**
|
||||
* The name of the message.
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* The message data.
|
||||
*/
|
||||
message: any;
|
||||
}
|
||||
Reference in New Issue
Block a user