├── README.md ├── tampermonkey-module.d.ts └── tampermonkey-reference.d.ts /README.md: -------------------------------------------------------------------------------- 1 | # Typescript declaration for Tampermonkey 2 | 3 | - tampermonkey-reference.d.ts: 4 | Use triple-slash directives to include the declareations in this file 5 | 6 | - tampermonkey-module.d.ts: 7 | 'import' to use tempermonkey api as an external module 8 | 9 | # License 10 | Apache License -------------------------------------------------------------------------------- /tampermonkey-module.d.ts: -------------------------------------------------------------------------------- 1 | declare global { 2 | 3 | var unsafeWindow : Window; 4 | 5 | var GM_info : { 6 | version : string, 7 | scriptWillUpdate : boolean, 8 | scriptHandler : "Tampermonkey", 9 | scriptUpdateURL ?: string, 10 | scriptSource : string, 11 | scriptMetaStr ?: string, 12 | isIncognito : boolean, 13 | downloadMode : "native" | "disabled" | "browser", 14 | script : { 15 | author ?: string, 16 | description ?: string, 17 | excludes : string[], 18 | homepage ?: string, 19 | icon ?: string, 20 | icon64 ?: string, 21 | includes ?: string[], 22 | lastModified : number, 23 | matches : string[], 24 | name : string, 25 | namespace ?: string, 26 | position : number, 27 | "run-at" : string, 28 | resources : string[], 29 | unwrap : boolean, 30 | version : string, 31 | options : { 32 | awareOfChrome : boolean, 33 | run_at : string, 34 | noframes ?: boolean, 35 | compat_arrayLeft : boolean, 36 | compat_foreach : boolean, 37 | compat_forvarin : boolean, 38 | compat_metadata : boolean, 39 | compat_uW_gmonkey : boolean, 40 | override : { 41 | orig_excludes : string[], 42 | orig_includes : string[], 43 | use_includes : string[], 44 | use_excludes : string[], 45 | [ key : string ] : any, 46 | }, 47 | [ key : string ] : any, 48 | }, 49 | [ key : string ] : any, 50 | }, 51 | [ key : string ] : any, 52 | }; 53 | 54 | function GM_addStyle(css : string) : void; 55 | 56 | function GM_deleteValue(name : string) : void; 57 | 58 | function GM_listValues() : string[]; 59 | 60 | function GM_addValueChangeListener(name : string, listener : GM_Types.ValueChangeListener) : number; 61 | 62 | function GM_removeValueChangeListener(listenerId : number) : void; 63 | 64 | function GM_setValue(name : string, value : any) : void; 65 | 66 | function GM_getValue(name : string, defaultValue ?: any) : any; 67 | 68 | function GM_log(message : string) : any; 69 | 70 | function GM_getResourceText(name : string) : string; 71 | 72 | function GM_getResourceURL(name : string) : string; 73 | 74 | function GM_registerMenuCommand(name : string, listener: Function, accessKey ?: string) : number; 75 | 76 | function GM_unregisterMenuCommand(id : number) : void; 77 | 78 | function GM_openInTab(url: string, options : GM_Types.OpenTabOptions) : void; 79 | function GM_openInTab(url: string, loadInBackground : boolean) : void; 80 | function GM_openInTab(url: string) : void; 81 | 82 | function GM_xmlhttpRequest(details : GM_Types.XHRDetails) : GM_Types.AbortHandle; 83 | 84 | 85 | function GM_download(details : GM_Types.DownloadDetails) : GM_Types.AbortHandle; 86 | function GM_download(url: string, filename: string) : GM_Types.AbortHandle; 87 | 88 | function GM_getTab(callback : (obj : object) => any) : void; 89 | function GM_saveTab(obj : object) : void; 90 | function GM_getTabs(callback : (objs : { [ key : number ] : object }) => any) : void; 91 | 92 | function GM_notification(details : GM_Types.NotificationDetails, ondone : Function) : void; 93 | function GM_notification(text : string, title : string, image : string, onclick : Function) : void; 94 | 95 | function GM_setClipboard(data : string, info ?: string | { type ?: string, minetype ?: string}) : void; 96 | } 97 | 98 | export namespace GM_Types { 99 | 100 | type ValueChangeListener = (name : string, oldValue : any, newValue : any, remote : boolean) => any; 101 | 102 | interface OpenTabOptions { 103 | active ?: boolean, 104 | insert ?: boolean, 105 | setParent ?: boolean 106 | } 107 | 108 | interface XHRResponse extends Function { 109 | 110 | DONE : 4, 111 | HEADERS_RECEIVED : 2, 112 | LOADING : 3, 113 | OPENED : 1, 114 | UNSENT : 0 115 | 116 | context : CONTEXT_TYPE, 117 | finalUrl : string, 118 | readyState : 0 | 1 | 2 | 3 | 4, 119 | responseHeaders : string, 120 | status : number, 121 | statusText : string, 122 | response : string | null, 123 | responseText : string, 124 | responseXML : Document | null 125 | } 126 | 127 | interface XHRProgress extends XHRResponse { 128 | done : number, 129 | lengthComputable : boolean, 130 | loaded : number, 131 | position : number, 132 | total : number, 133 | totalSize : number 134 | } 135 | 136 | type Listener = (this : OBJ, event : OBJ) => any; 137 | 138 | interface XHRDetails { 139 | method ?: "GET" | "HEAD" | "POST", 140 | url ?: string, 141 | headers ?: { readonly [ key : string ] : string }, 142 | data ?: string, 143 | binary ?: boolean, 144 | timeout ?: number, 145 | context ?: CONTEXT_TYPE, 146 | responseType ?: "arraybuffer" | "blob" | "json", 147 | overrideMimeType ?: string, 148 | anonymous ?: boolean, 149 | fetch ?: boolean, 150 | username ?: string, 151 | password ?: string, 152 | 153 | onload ?: Listener>, 154 | onloadstart ?: Listener>, 155 | onprogress ?: Listener>, 156 | onreadystatechange ?: Listener>, 157 | ontimeout ?: Listener, 158 | onabort ?: Function, 159 | onerror ?: Function 160 | } 161 | 162 | interface AbortHandle { 163 | abort() : RETURN_TYPE 164 | } 165 | 166 | interface DownloadError { 167 | error : "not_enabled" | "not_whitelisted" | "not_permitted" | "not_supported" | "not_succeeded", 168 | details ?: string 169 | } 170 | 171 | interface DownloadDetails { 172 | url : string, 173 | name : string, 174 | headers ?: { readonly [ key : string ] : string }, 175 | saveAs ?: boolean, 176 | timeout ?: number, 177 | onerror ?: Listener, 178 | ontimeout ?: Listener, 179 | onload ?: Listener, 180 | onprogress ?: Listener> 181 | } 182 | 183 | interface NotificationThis extends NotificationDetails { 184 | id : string 185 | } 186 | 187 | type NotificationOnClick = (this : NotificationThis) => any; 188 | type NotificationOnDone = (this : NotificationThis, clicked: boolean) => any; 189 | 190 | interface NotificationDetails { 191 | text ?: string, 192 | title ?: string, 193 | image ?: string, 194 | highlight ?: boolean, 195 | timeout ?: number 196 | onclick ?: NotificationOnClick, 197 | ondone ?: NotificationOnDone, 198 | } 199 | } -------------------------------------------------------------------------------- /tampermonkey-reference.d.ts: -------------------------------------------------------------------------------- 1 | declare var unsafeWindow : Window; 2 | 3 | declare var GM_info : { 4 | version : string, 5 | scriptWillUpdate : boolean, 6 | scriptHandler : "Tampermonkey", 7 | scriptUpdateURL ?: string, 8 | scriptSource : string, 9 | scriptMetaStr ?: string, 10 | isIncognito : boolean, 11 | downloadMode : "native" | "disabled" | "browser", 12 | script : { 13 | author ?: string, 14 | description ?: string, 15 | excludes : string[], 16 | homepage ?: string, 17 | icon ?: string, 18 | icon64 ?: string, 19 | includes ?: string[], 20 | lastModified : number, 21 | matches : string[], 22 | name : string, 23 | namespace ?: string, 24 | position : number, 25 | "run-at" : string, 26 | resources : string[], 27 | unwrap : boolean, 28 | version : string, 29 | options : { 30 | awareOfChrome : boolean, 31 | run_at : string, 32 | noframes ?: boolean, 33 | compat_arrayLeft : boolean, 34 | compat_foreach : boolean, 35 | compat_forvarin : boolean, 36 | compat_metadata : boolean, 37 | compat_uW_gmonkey : boolean, 38 | override : { 39 | orig_excludes : string[], 40 | orig_includes : string[], 41 | use_includes : string[], 42 | use_excludes : string[], 43 | [ key : string ] : any, 44 | }, 45 | [ key : string ] : any, 46 | }, 47 | [ key : string ] : any, 48 | }, 49 | [ key : string ] : any, 50 | }; 51 | 52 | declare function GM_addStyle(css : string) : void; 53 | 54 | declare function GM_deleteValue(name : string) : void; 55 | 56 | declare function GM_listValues() : string[]; 57 | 58 | declare function GM_addValueChangeListener(name : string, listener : GM_Types.ValueChangeListener) : number; 59 | 60 | declare function GM_removeValueChangeListener(listenerId : number) : void; 61 | 62 | declare function GM_setValue(name : string, value : any) : void; 63 | 64 | declare function GM_getValue(name : string, defaultValue ?: any) : any; 65 | 66 | declare function GM_log(message : string) : any; 67 | 68 | declare function GM_getResourceText(name : string) : string; 69 | 70 | declare function GM_getResourceURL(name : string) : string; 71 | 72 | declare function GM_registerMenuCommand(name : string, listener: Function, accessKey ?: string) : number; 73 | 74 | declare function GM_unregisterMenuCommand(id : number) : void; 75 | 76 | declare function GM_openInTab(url: string, options : GM_Types.OpenTabOptions) : void; 77 | declare function GM_openInTab(url: string, loadInBackground : boolean) : void; 78 | declare function GM_openInTab(url: string) : void; 79 | 80 | declare function GM_xmlhttpRequest(details : GM_Types.XHRDetails) : GM_Types.AbortHandle; 81 | 82 | 83 | declare function GM_download(details : GM_Types.DownloadDetails) : GM_Types.AbortHandle; 84 | declare function GM_download(url: string, filename: string) : GM_Types.AbortHandle; 85 | 86 | declare function GM_getTab(callback : (obj : object) => any) : void; 87 | declare function GM_saveTab(obj : object) : void; 88 | declare function GM_getTabs(callback : (objs : { [ key : number ] : object }) => any) : void; 89 | 90 | declare function GM_notification(details : GM_Types.NotificationDetails, ondone : Function) : void; 91 | declare function GM_notification(text : string, title : string, image : string, onclick : Function) : void; 92 | 93 | declare function GM_setClipboard(data : string, info ?: string | { type ?: string, minetype ?: string}) : void; 94 | 95 | declare namespace GM_Types { 96 | 97 | type ValueChangeListener = (name : string, oldValue : any, newValue : any, remote : boolean) => any; 98 | 99 | interface OpenTabOptions { 100 | active ?: boolean, 101 | insert ?: boolean, 102 | setParent ?: boolean 103 | } 104 | 105 | interface XHRResponse extends Function { 106 | 107 | DONE : 4, 108 | HEADERS_RECEIVED : 2, 109 | LOADING : 3, 110 | OPENED : 1, 111 | UNSENT : 0 112 | 113 | context : CONTEXT_TYPE, 114 | finalUrl : string, 115 | readyState : 0 | 1 | 2 | 3 | 4, 116 | responseHeaders : string, 117 | status : number, 118 | statusText : string, 119 | response : string | null, 120 | responseText : string, 121 | responseXML : Document | null 122 | } 123 | 124 | interface XHRProgress extends XHRResponse { 125 | done : number, 126 | lengthComputable : boolean, 127 | loaded : number, 128 | position : number, 129 | total : number, 130 | totalSize : number 131 | } 132 | 133 | type Listener = (this : OBJ, event : OBJ) => any; 134 | 135 | interface XHRDetails { 136 | method ?: "GET" | "HEAD" | "POST", 137 | url ?: string, 138 | headers ?: { readonly [ key : string ] : string }, 139 | data ?: string, 140 | binary ?: boolean, 141 | timeout ?: number, 142 | context ?: CONTEXT_TYPE, 143 | responseType ?: "arraybuffer" | "blob" | "json", 144 | overrideMimeType ?: string, 145 | anonymous ?: boolean, 146 | fetch ?: boolean, 147 | username ?: string, 148 | password ?: string, 149 | 150 | onload ?: Listener>, 151 | onloadstart ?: Listener>, 152 | onprogress ?: Listener>, 153 | onreadystatechange ?: Listener>, 154 | ontimeout ?: Listener, 155 | onabort ?: Function, 156 | onerror ?: Function 157 | } 158 | 159 | interface AbortHandle { 160 | abort() : RETURN_TYPE 161 | } 162 | 163 | interface DownloadError { 164 | error : "not_enabled" | "not_whitelisted" | "not_permitted" | "not_supported" | "not_succeeded", 165 | details ?: string 166 | } 167 | 168 | interface DownloadDetails { 169 | url : string, 170 | name : string, 171 | headers ?: { readonly [ key : string ] : string }, 172 | saveAs ?: boolean, 173 | timeout ?: number, 174 | onerror ?: Listener, 175 | ontimeout ?: Listener, 176 | onload ?: Listener, 177 | onprogress ?: Listener> 178 | } 179 | 180 | interface NotificationThis extends NotificationDetails { 181 | id : string 182 | } 183 | 184 | type NotificationOnClick = (this : NotificationThis) => any; 185 | type NotificationOnDone = (this : NotificationThis, clicked: boolean) => any; 186 | 187 | interface NotificationDetails { 188 | text ?: string, 189 | title ?: string, 190 | image ?: string, 191 | highlight ?: boolean, 192 | timeout ?: number 193 | onclick ?: NotificationOnClick, 194 | ondone ?: NotificationOnDone, 195 | } 196 | } --------------------------------------------------------------------------------