Skip to content

Instantly share code, notes, and snippets.

@htsign
Last active April 24, 2016 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save htsign/6e0f48586626695c723546a7114845ae to your computer and use it in GitHub Desktop.
Save htsign/6e0f48586626695c723546a7114845ae to your computer and use it in GitHub Desktop.
TypeScript Definition for AnciaScript
declare namespace Ancia {
interface App {
/**
* 現在アクティブなTabオブジェクトを返却します。
*/
activeTab: Tab;
/**
* 現在のタブの数を返却します。
*/
tabCount: number;
/**
* 指定インデックス(現在のタブの順序で0起算)のタブオブジェクトを返却します。
* @param index 指定インデックス
*/
tab(index: number): Tab;
/**
* 新しいタブを開き、開いたタブオブジェクトを返却します(ナビゲート無し)。
* @param index タブ追加位置。省略した場合、アプリケーションのタブ追加位置設定となります。-1は省略が指定されたものとみなします。
* @param activate タブのactive指定。タブをactiveにするときtrue、非アクティブにするときfalseを指定します。省略した場合、アプリケーションの新規タブactive設定に従います。
*/
createTab(index?: number, activate?: boolean): Tab;
/**
* クリップボードオブジェクトを返却します。
*/
clipboard: Clipboard;
/**
* XMLファイルを読み込み、OpenSearchオブジェクトを返却します。
* @param xmlFileName オープンサーチ形式のXMLファイル。searchフォルダから読み込むXMLファイルを指定します。
*/
openSearch(xmlFileName: string): OpenSearch;
/**
* タブIDからタブのインデックス(現在のタブの位置)を返します。
* @param tabId インデックスを取得したいタブIDを指定します。
*/
tabIndex(tabId: number): number;
/**
* URLを指定して新しいタブを開きます。開いたタブオブジェクトを返します。
* @param url 開くURLを指定します。
* @param activate タブのactive指定。タブをactiveにするときtrue、非アクティブにするときfalseを指定します。省略した場合、アプリケーションの新規タブactive設定に従います。
* @param index タブ追加位置。省略した場合、アプリケーションのタブ追加位置設定となります。-1は省略が指定されたものとみなします。
*/
NewTab(url: string, activate?: boolean, index?: number): Tab;
/**
* 指定したスクリプトを実行します。
* @param scriptFile 実行するスクリプトを指定します。指定したファイルがscriptフォルダから読まれます。
*/
execScript(scriptFile: string): void;
/**
* メッセージボックスを表示し、押されたボタン結果を返却します。
* @param message 表示するメッセージを指定します。省略した場合、空メッセージとなります。
* @param title 表示するタイトルを指定します。省略した場合、空タイトルとなります。
* @param type メッセージボックスのボタンタイプを指定します。省略した場合、0が指定されたとみなします。
*/
MsgBox(message?: string, title?: string, type?: MsgBoxTypes): MsgBoxResult;
/**
* アプリケーションのフルパス(Ancia.exe)を返却します。
*/
path: string;
/**
* urlに対するローカルキャッシュファイルフルパスを返却します。取得できなかった場合、falseが返されます。
* @param url 取得したいURLを指定します。
*/
cacheFile(url: string): string | boolean;
/**
* 指定したURL先をダウンロードし、保存したローカルキャッシュファイルフルパスを返却します。失敗した場合、falseが返されます。メソッドは、ダウンロードが完了するまで応答を返しません。
* @param url ダウンロードするURLを指定します。
*/
downloadToCacheFile(url: string): string | boolean;
/**
* pathについている余計な文字を取り除いた結果を返却します。主にcacheFile()メソッドやdownloadToCacheFile()メソッドの返却結果に対して使用します。
* @param path ファイルパスを指定します。
*/
pathUndecorate(path: string): string;
/**
* 名前を付けて保存ダイアログを表示し、選択されたファイルフルパスを返却します。選択されなかった場合やキャンセルされたとき、falseが返されます。
* @param filename 表示ファイル名を指定します。
* @param dir 表示するディレクトリを指定します。undefinedを指定したとき、表示フォルダはシステム任せになります。
* @param filter "allfilter" 全てのファイル(*.*) のみ指定できます。
*/
saveFileNameDlg(filename: string, dir: string | void, filter: "allfilter"): string | boolean;
saveFileNameDlg(filename: string, dir: string | void, filter: string): string | boolean;
/**
* 複数の入力が可能なInputBoxを表示します。結果は、jsonでの文字列を返します。
*/
InputBox(param: InputBoxParam): string | boolean;
/**
* 複数の入力が可能なInputBoxを表示します。結果は、jsonでの文字列を返します。
*/
InputBox(param: string): string | boolean;
/**
* beepを鳴らします。
* @param type MessageBeepでのbeepのタイプを数値で指定します(指定省略で0xFFFFFFFF)。
*/
beep(type: MessageBeep): void;
/**
* 履歴・cookie・キャッシュを削除します。
* @param deleteFlags 削除フラグ
*/
deleteHistory(deleteFlags: DeleteFlags): void;
/**
* cookieを取得します。用途としては、ページの読み込みが完了していなくても、このメソッドからcookieを取得できます。取得できなかったとき、falseを返します。
* @param url 取得するURL
* @param name cookieを取得する名前を指定します。
*/
getCookie(url: string, name: string): string;
/**
* キー状態を取得します。押されていればtrueが返ります。押されていなければfalseが返ります。
* @param virtualKey Virtualキーコード
*/
getKeyState(virtualKey: KeyCode): boolean;
/**
* proxy設定を取得・設定します。設定には、オプションのユーザ設定プロキシサーバ一覧にあらかじめ追加する必要があります。
* App.proxy=undefinedでIEの設定を使用します。App.proxy=":direct:";でproxyを使用せず直接接続になります。変更するとすべてのタブで変更が行われます。
*/
proxy: ":direct:" | string | void;
/* !!! 以降はリファレンスに載っていません !!! */
CmdExec(command: "about", arg0: number): void;
CmdExec(command: "add.favorites", title: string, url: string): void;
CmdExec(command: "close.tabgroup"): void;
CmdExec(command: "exit"): void;
CmdExec(command: "fullScreen"): void;
CmdExec(command: "fullWindow"): void;
CmdExec(command: "go", url: string): void;
CmdExec(command: "go", url: string, position: number, flags: number): void;
CmdExec(command: "lasttab"): void;
CmdExec(command: "localhome"): void;
CmdExec(command: "mpanel"): void;
CmdExec(command: "new"): void;
CmdExec(command: "new.home"): void;
CmdExec(command: "new.localhome"): void;
CmdExec(command: "next.tab"): void;
CmdExec(command: "open.closed"): void;
CmdExec(command: "option"): void;
CmdExec(command: "prev.tab"): void;
CmdExec(command: "refresh.all", mode?: number): void;
CmdExec(command: "scrolltab.left", arg0?: number): void;
CmdExec(command: "scrolltab.right", arg0?: number): void;
CmdExec(command: "setup.mousegesture"): void;
CmdExec(command: "sidebarcontrol"): void;
CmdExec(command: "tabSnapshot"): void;
CmdExec(command: "urlaction"): void;
CmdExec(command: string | number, ...args: any[]): void;
Go(url: string, position: number, flag: number): void;
createUrlInfo(): UrlInfo;
openTabList(urls: UrlInfo[], position: number, flag: number): void;
reloadSetting(setting: "urlAction,"): void;
reloadSetting(setting: string): void;
showSideBar(uuid: string): void;
}
interface Tab {
/**
* browserオブジェクトを返却します。返却されるオブジェクトは、常にトップレベルです。マルチスレッド/プロセスで他のスレッド/プロセスのタブのbrowserオブジェクトを取得することは推奨しません(Xpで固まる現象が出る)。利用対象によりますが、固まり抑止でhtmlプロパティを用意しています。
*/
browser: Browser;
/**
* タブを閉じます。
*/
close(): void;
/**
* 拡大レベル(%)を設定・取得します。IE6の場合、ズーム機能をCSSによりシミュレートします。
*/
zoom: number;
/**
* セキュリティを設定・取得します。セキュリティの値は次の値の組み合わせです。 値を変更した後は、browser.Refresh()やNavigate2()を行なうまで、ページに反映されません。
*/
security: SecurityFlags;
/**
* タブのユニークなIDを返します。
*/
id: number;
/**
* 参照/設定が可能です。設定の場合、タブのHTMLドキュメントに対し、HTMLを書き込みます。参照の場合、topレベルのドキュメントのHTMLをstringとして取得します。
*/
html: string;
/**
* ブラウザにキー入力を行います。行えるキーは矢印キーやBackspaceなどで、「A」などは行えません。アプリではvirtualKeyの値はチェックせず、ブラウザへキー入力処理を行っています。もしかすると、virtualKeyによっては、入力を行えるものがあるかもしれません。
* @param virtualKey 入力する Virtual-Key Codes の値を指定します。省略できません。
* @param keyState Controlまたは、Shiftキー状態を指定します。次の値の組み合わせです。省略時は0が指定されたものとして扱います。
*/
translateKey(virtualKey: KeyCode, keyState?: KeyState): void;
/**
* popupでURLを開きます。openPopupメソッドは、popupをタブで開くアプリ設定であってもタブではなくpopupで開きます。
* @param url 開くURLを指定します。
* @param name 開くpopupの名前を指定します。_blank,_parent,_self,_topを指定できます。
* @param feature widthやheightなどopen method (Windows)と同じパラメータを指定できます。ただしtoolbarなどは、まだ未対応です。 width,height,scrollbarsは指定可能です。
*/
openPopup(url: string, name?: string, feature?: string): number;
/* !!! 以降はリファレンスに載っていません !!! */
AutoRefresh: number;
CmdExec(command: "add.hilite", keyword: string): void;
CmdExec(command: "back", arg0?: number): void;
CmdExec(command: "close"): void;
CmdExec(command: "close.all"): void;
CmdExec(command: "close.except"): void;
CmdExec(command: "close.except", arg0: any, arg1: boolean): void;
CmdExec(command: "close.left"): void;
CmdExec(command: "close.left", arg0: any, arg1: boolean): void;
CmdExec(command: "close.lock"): void;
CmdExec(command: "close.right"): void;
CmdExec(command: "close.right", arg0: any, arg1: boolean): void;
CmdExec(command: "duplicate"): void;
CmdExec(command: "duplicate", arg0: number, arg1: number, arg2: number): void;
CmdExec(command: "focus.browser"): void;
CmdExec(command: "focus.searchbar", arg0: number): void;
CmdExec(command: "forward", arg0?: number): void;
CmdExec(command: "go", url: string): void;
CmdExec(command: "hilite", arg0: number, arg1: boolean): void;
CmdExec(command: "isearch", arg0: boolean, arg1: string): void;
CmdExec(command: "isolate"): void;
CmdExec(command: "nav.lock"): void;
CmdExec(command: "refresh", mode?: number): void;
CmdExec(command: "refresh.hilite"): void;
CmdExec(command: "refresh.isearch"): void;
CmdExec(command: "search", searchDefinitionFile: string, keyword: string): void;
CmdExec(command: "source.select"): void;
CmdExec(command: "stop"): void;
CmdExec(command: "up", arg0?: number): void;
CmdExec(command: string | number, ...args: any[]): void;
}
interface Browser extends WebBrowser {
/**
* ドキュメントオブジェクトを返却します。
*/
document: Document;
}
interface Clipboard {
/**
* クリップボードから値を取得します。取得する形式を指定できます。
* @param format "TEXT" クリップボードからテキストを取得します。
*/
getData(format: "TEXT"): string;
getData(format: string): any;
/**
* クリップボードに値を設定します。設定する形式を指定できます。
* @param format "TEXT" テキスト形式を設定します。
* @param value 設定する値
*/
setData(format: "TEXT", value: string): void;
setData(format: string, value: any): void;
}
/**
* ドロップアクションでのスクリプト実行のとき取得できるグローバルオブジェクトです。
*/
interface DataObject {
/**
* ドロップされたテキストを取得します。取得できなかった場合、falseが返されます。
*/
text: string | boolean;
/**
* ドロップされたURLを取得します。取得できなかった場合、falseが返されます。URLアクションのときは、ナビゲート前で、ナビゲートされようとしているURL、ナビゲート後でナビゲート後のURLを返却します。
*/
url: string | boolean;
/**
* ドロップされたURLのタイトルを取得します。取得できなかった場合、falseが返されます。
*/
title: string | boolean;
/**
* ドラッグドロップ元がイメージだった場合、イメージのURLを取得します。取得できなかった場合、falseが返されます。ページがイメージのみのときは、タブのドラッグドロップでもDataObject.imageUrlは、イメージのURLを返却します。data schemeの場合キャッシュのパスをfile schemeで返却します。
*/
imageUrl: string | boolean;
/**
* ドロップされたHTMLを取得します。取得できなかった場合、falseが返されます。
*/
html: string | boolean;
/**
* ドロップされた選択HTMLを取得します。取得できなかった場合、falseが返されます。
*/
selectionHtml: string | boolean;
/**
* URLアクションのとき、hitしたブラウザオブジェクトを返却します。CurrentTab.browserは常にトップレベルのブラウザオブジェクトを返却しますが、DataObject.browserは、フレームでhitしたとき、フレームのブラウザオブジェクトを返却するところが異なります。
*/
browser: Browser;
}
/**
* App.openSerach()メソッドで返却されるオブジェクトです。
*/
interface OpenSearch {
/**
* 指定されたtermで検索クエリURLを構築し、返却します(エスケープ処理込み)。encodingはApp.openSearch()で開いたOpenSearchファイルの内容から決定されます。
* @param term 検索するキーワードを指定します。
*/
buildUrl(term: string): string;
}
/**
* スクリプトでの、状況情報を保持します。新規タブ位置や新規タブをアクティブにする設定は、アドレスバーや検索バーなど実行元により異なることがあります。スクリプトではContextオブジェクトを参照することにより、実行元を意識することなく、動作設定を参照できます。
*/
interface Context {
/**
* 新規タブを追加する位置を返却します。
*/
NewTabPosition: number;
/**
* タブに関する動作フラグです。
*/
tabFlags: TabFlags;
/**
* 実行しているスクリプトのフルパスを返却します。
*/
path: string;
/**
* スクリプト個別で保存できる設定ファイルフルパスを返します。
* @param isScript sample.jsだと、isScriptがfalseでsetting配下のsetting\script\sample.jsonが返却されます。isScriptがtrueだとscriptがあるフォルダと同じscript\sample.jsonが返却されます。省略すると、false指定の動作をします。
*/
settingPath(isScript: boolean): string;
/**
* オプション設定から起動されたときのみtrueを返却します。それ以外はfalseを返却します。
*/
isSetting: boolean;
/**
* このプロパティは、URLアクション、ナビゲート前のとき有効です。ナビゲートをキャンセルするときはtrueを指定します。規定では、ナビゲートはキャンセルされません。
*/
eventCancel: boolean;
}
/**
* App.InputBoxメソッドにおける引数の型を示します。
*/
interface InputBoxParam {
/**
* Windowキャプション
*/
caption?: string;
/**
* 2つまで定義できます。順に「上部表示テキスト」「下部表示テキスト」の順です。
*/
statics?: InputBoxStatic[];
/**
* 5つまで定義できます。
*/
inputs: InputBoxInput[];
/**
* 2つまで定義できます。1つ目が確定ボタン、2つ目がキャンセルボタンになります。
*/
buttons?: InputBoxButton[];
}
/**
* App.InputBoxメソッドで表示されるダイアログのメッセージを示します。
*/
interface InputBoxStatic {
text?: string;
}
/**
* App.InputBoxメソッドで表示されるダイアログの入力欄を示します。
*/
interface InputBoxInput {
label?: string;
value?: string;
type?: "number";
}
/**
* App.InputBoxメソッドで表示されるダイアログのボタンを示します。
*/
interface InputBoxButton {
text?: string;
type?: "default";
}
/**
* App.InputBoxメソッドの返り値がJSONのとき、パースされたオブジェクトをこの型にキャストできます。
*/
interface InputBoxResult {
inputs: string[];
}
interface UrlInfo {
url: string;
title: string;
tabGroupId: number;
}
export enum MsgBoxTypes {
OK = 0x000,
OKCancel = 0x001,
YesNoCancel = 0x003,
YesNo = 0x004,
Error = 0x010,
Stop = 0x010,
Question = 0x020,
Warning = 0x030,
Information = 0x040,
Default1 = 0x000,
Default2 = 0x100,
Default3 = 0x200,
}
export enum MsgBoxResult {
OK = 1,
Cancel = 2,
Yes = 6,
No = 7,
}
export enum MessageBeep {
Simple = 0xffffffff,
Information = 0x00000040,
Asterisk = 0x00000040,
Warning = 0x00000030,
Exclamation = 0x00000030,
Critical = 0x00000010,
Error = 0x00000010,
Question = 0x00000020,
OK = 0x00000000,
Default = 0x00000000,
}
export enum KeyCode {
Backspace = 0x08,
Tab = 0x09,
Enter = 0x0d,
Return = 0x0d,
Shift = 0x10,
Control = 0x11,
Alt = 0x12,
Meta = 0x12,
Menu = 0x12,
Pause = 0x13,
CapsLock = 0x14,
Escape = 0x1b,
Esc = 0x1b,
Space = 0x20,
PageUp = 0x21,
Prior = 0x21,
PageDown = 0x22,
Next = 0x22,
End = 0x23,
Home = 0x24,
Left = 0x25,
LeftArrow = 0x25,
Up = 0x26,
UpArrow = 0x26,
Right = 0x27,
RightArrow = 0x27,
Down = 0x28,
DownArrow = 0x28,
PrintScreen = 0x2c,
Snapshot = 0x2c,
Insert = 0x2d,
Ins = 0x2d,
Delete = 0x2e,
Del = 0x2e,
Key0 = 0x30,
Key1 = 0x31,
Key2 = 0x32,
Key3 = 0x33,
Key4 = 0x34,
Key5 = 0x35,
Key6 = 0x36,
Key7 = 0x37,
Key8 = 0x38,
Key9 = 0x39,
KeyA = 0x41,
KeyB = 0x42,
KeyC = 0x43,
KeyD = 0x44,
KeyE = 0x45,
KeyF = 0x46,
KeyG = 0x47,
KeyH = 0x48,
KeyI = 0x49,
KeyJ = 0x4a,
KeyK = 0x4b,
KeyL = 0x4c,
KeyM = 0x4d,
KeyN = 0x4e,
KeyO = 0x4f,
KeyP = 0x50,
KeyQ = 0x51,
KeyR = 0x52,
KeyS = 0x53,
KeyT = 0x54,
KeyU = 0x55,
KeyV = 0x56,
KeyW = 0x57,
KeyX = 0x58,
KeyY = 0x59,
KeyZ = 0x5a,
LeftWindows = 0x5b,
RightWindows = 0x5c,
Applications = 0x5d,
Numpad0 = 0x60,
Numpad1 = 0x61,
Numpad2 = 0x62,
Numpad3 = 0x63,
Numpad4 = 0x64,
Numpad5 = 0x65,
Numpad6 = 0x66,
Numpad7 = 0x67,
Numpad8 = 0x68,
Numpad9 = 0x69,
F1 = 0x70,
F2 = 0x71,
F3 = 0x72,
F4 = 0x73,
F5 = 0x74,
F6 = 0x75,
F7 = 0x76,
F8 = 0x77,
F9 = 0x78,
F10 = 0x79,
F11 = 0x7a,
F12 = 0x7b,
NumLock = 0x90,
ScrollLock = 0x91,
LeftShift = 0xa0,
RightShift = 0xa1,
LeftControl = 0xa2,
RightControl = 0xa3,
LeftAlt = 0xa4,
LeftMeta = 0xa4,
LeftMenu = 0xa4,
RightAlt = 0xa5,
RightMeta = 0xa5,
RightMenu = 0xa5,
}
export enum KeyState {
None = 0x0,
Shift = 0x4,
Control = 0x8,
}
export enum DeleteFlags {
SearchHistory = 0x01,
AddressbarHistory = 0x02,
History = 0x04,
IECache = 0x08,
IECookie = 0x10,
Tabs = 0x20,
FormData = 0x40,
Passwords = 0x80,
}
export enum SecurityFlags {
ImageEnabled = 0x000010,
VideoEnabled = 0x000020,
BackgroundSoundEnabled = 0x000040,
ScriptDisabled = 0x000080,
JavaAppletDisabled = 0x000100,
ActiveXDisabled = 0x000400,
MetaRefreshBlocked = 0x100000,
}
export enum TabFlags {
ShouldMake = 0x1,
Activate = 0x2,
Deactivate = 0x4,
}
}
/**
* WebBrowser Control https://msdn.microsoft.com/en-us/library/aa768397(v=vs.85).aspx
* Properties : https://msdn.microsoft.com/en-us/library/aa768398(v=vs.85).aspx
* Methods : https://msdn.microsoft.com/en-us/library/aa768399(v=vs.85).aspx
* Enums : https://msdn.microsoft.com/en-us/library/aa768401(v=vs.85).aspx
*/
interface WebBrowser {
/**
* Navigates the browser to a location that might not be expressed as a URL, such as a pointer to an item identifier list (PIDL) for an entity in the Windows Shell namespace.
* @param url Required. A variable or expression that evaluates to the URL of the resource to display, the full path to the file location, or a PIDL that represents a folder in the Shell namespace.
* @param mode A constant or value that specifies a combination of the values defined by the BrowserNavConstants enumeration.
* @param target Case-sensitive string expression that evaluates to the name of the frame in which to display the resource. The possible values for this parameter are.
* @param postData Data that is sent to the server as part of a HTTP POST transaction. A POST transaction typically is used to send data collected by an HTML form. If this parameter does not specify any POST data, this method issues an HTTP GET transaction. This parameter is ignored if URL is not an HTTP (or HTTPS) URL.
* @param headers A String that contains additional HTTP headers to send to the server. These headers are added to the default Internet Explorer headers. For example, headers can specify the action required of the server, the type of data being passed to the server, or a status code. This parameter is ignored if the URL is not an HTTP (or HTTPS) URL.
*/
Navigate2(url: string, mode: BrowserNavConstants, target: string | number, postData: number[], headers: string): HRESULT;
}
declare enum BrowserNavConstants {
navOpenInNewWindow = 0x000001,
navNoHistory = 0x000002,
navNoReadFromCache = 0x000004,
navNoWriteToCache = 0x000008,
navAllowAutosearch = 0x000010,
navBrowserBar = 0x000020,
navHyperlink = 0x000040,
navEnforceRestricted = 0x000080,
navNewWindowsManaged = 0x000100,
navUntrustedForDownload = 0x000200,
navTrustedForActiveX = 0x000400,
navOpenInNewTab = 0x000800,
navOpenInBackgroundTab = 0x001000,
navKeepWordWheelText = 0x002000,
navVirtualTab = 0x004000,
navBlockRedirectsXDomain = 0x008000,
navOpenNewForegroundTab = 0x010000,
navTravelLogScreenshot = 0x020000,
navDeferUnload = 0x040000,
navSpeculative = 0x080000,
navSuggestNewWindow = 0x100000,
navSuggestNewTab = 0x200000,
navReserved1 = 0x400000,
navHomepageNavigate = 0x800000,
}
declare enum HRESULT {
/**
* Operation successful
*/
S_OK = 0x00000000,
/**
* One or more arguments are not valid
*/
E_INVALIDARG = 0x80070057,
/**
* Failed to allocate necessary memory
*/
E_OUTOFMEMORY = 0x8007000E,
/**
* Unspecified failure
*/
E_FAIL = 0x80004005,
}
declare var App: Ancia.App;
declare var CurrentTab: Ancia.Tab;
declare var DataObject: Ancia.DataObject;
declare var Context: Ancia.Context;
declare var activeDocument: Document;
class Utility {
public static getInputBoxResult(result: string | boolean): Ancia.InputBoxResult {
if (typeof result === "boolean") return { inputs: <string[]>[] };
return <Ancia.InputBoxResult>JSON.parse(<string>result);
}
}
@htsign
Copy link
Author

htsign commented Apr 22, 2016

InputBoxResultインターフェースの使い道としてサンプルにUtilityクラス、getInputBoxResultメソッドを定義してみました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment