updated to using types from violentmonkey instead of my handrolled ones

This commit is contained in:
Niki Wix Skaarup 2025-05-03 00:34:29 +02:00
parent f25cbae9e2
commit 7dd96ac108
Signed by: nikiskaarup
GPG key ID: FC2F1B116F6E788C
6 changed files with 201 additions and 416 deletions

View file

@ -1,76 +0,0 @@
// Greasemonkey api
// https://wiki.greasespot.net/Greasemonkey_Manual:API
type gm_responseObjectType = {
readyState: number;
responseHeaders: string;
responseText: string;
status: number;
statusText: string;
context?: unknown;
lengthComputable?: boolean;
loaded?: number;
total?: number;
};
type gm_detailType = {
binary?: boolean;
context?: unknown;
data?: string;
headers?: { [key: string]: string };
method?: string;
overrideMimeType?: string;
password?: string;
responseType?: string;
synchronous?: boolean;
timeout?: number;
upload?: {
onabort?: (event: gm_responseObjectType) => void;
onerror?: (event: gm_responseObjectType) => void;
onload?: (event: gm_responseObjectType) => void;
onprogress?: (event: gm_responseObjectType) => void;
};
url: string;
user?: string;
onabort?: (event: gm_responseObjectType) => void;
onerror?: (event: gm_responseObjectType) => void;
onload?: (event: gm_responseObjectType) => void;
onprogress?: (event: gm_responseObjectType) => void;
onreadystatechange?: (event: gm_responseObjectType) => void;
ontimeout?: (event: gm_responseObjectType) => void;
};
type gm_optionType = {
text: string;
title?: string;
image?: string;
onclick?: () => void;
ondone?: () => void;
};
type gm_resourceType = {
[key: string]: {
name: string;
mimetype: string;
url: string;
};
};
type gm_scriptType = {
description: string;
excludes: string[];
includes: string[];
matches: string[];
name: string;
namespace: string;
resources: gm_resourceType;
"run-at": string;
version: string;
};
type gm_infoType = {
script: gm_scriptType;
scriptMetaStr: string;
scriptHandler: string;
version: string;
};

View file

@ -1,291 +1 @@
type vm_responseObjectTypeUnknown = vm_responseObjectType<unknown>;
type vm_responseObjectType<T> = {
status: number;
statusText: string;
readyState: number;
responseHeaders: string;
response: string | Blob | ArrayBuffer | Document | object | null;
responseText: string | undefined;
responseXML: Document | null;
lengthComputable: boolean;
loaded: number;
total: number;
finalUrl: string;
context: T;
};
type vm_detailType<T> = {
url: string;
method?: string;
user?: string;
password?: string;
overrideMimeType?: string;
headers?: { [key: string]: string };
responseType?: string;
timeout?: number;
data?:
| string
| ArrayBuffer
| Blob
| DataView
| FormData
| ReadableStream
| TypedArray
| URLSearchParams;
binary?: boolean;
context?: T;
anonymous?: boolean;
onabort?: (resp: vm_responseObjectType<T>) => void;
onerror?: (resp: vm_responseObjectType<T>) => void;
onload?: (resp: vm_responseObjectType<T>) => void;
onloadend?: (resp: vm_responseObjectType<T>) => void;
onloadstart?: (resp: vm_responseObjectType<T>) => void;
onprogress?: (resp: vm_responseObjectType<T>) => void;
onreadystatechange?: (resp: vm_responseObjectType<T>) => void;
ontimeout?: (resp: vm_responseObjectType<T>) => void;
};
type vm_optionType = {
text: string;
title?: string;
image?: string;
onclick?: () => void;
ondone?: () => void;
};
type vm_resourceType = {
name: string;
url: string;
};
type vm_scriptType = {
description: string;
excludes: Array<string>;
includes: Array<string>;
matches: Array<string>;
name: string;
namespace: string;
resources: Array<vm_resourceType>;
"run-at": string;
version: string;
};
type vm_platformType = {
arch: string;
browserName: string;
browserVersion: string;
fullVersionList: Array<{
brand: string;
version: string;
}>;
mobile: boolean;
os: string;
};
type vm_infoType = {
uuid: string;
scriptMetaStr: string;
scriptWillUpdate: boolean;
scriptHandler: string;
version: string;
isIncognito: boolean;
platform: vm_platformType;
userAgent: string;
userAgentData: {
brands: Array<{ brand: string; version: string }>;
mobile: boolean;
platform: string;
getHighEntropyValues: (
hints: string[],
) => Promise<{ [key: string]: unknown }>;
};
script: vm_scriptType;
injectInto: string;
};
type openInNewTabOptionsType = {
active?: boolean;
container?: number;
insert?: boolean;
pinned?: boolean;
};
type openInNewTabReturnType = {
onclose: () => void;
closed: boolean;
close: () => void;
};
declare namespace GM {
function addStyle(css: string): void;
function addElement(
tagName: string,
attributes?: { [key: string]: unknown },
): HTMLElement;
function addElement(
parent: Node | Element | ShadowRoot,
tagName: string,
attributes?: { [key: string]: unknown },
): HTMLElement;
function registerMenuCommand(
caption: string,
func: (event: MouseEvent | KeyboardEvent) => void,
options?: { id?: string; title?: string; autoClose?: boolean },
): string;
function deleteValue(key: string): Promise<void>;
function deleteValues(keys: string[]): Promise<void>;
function download(options: {
url: string;
name: string;
headers?: object;
timeout?: number;
context?: unknown;
user?: string;
password?: string;
anonymous?: boolean;
onabort?: () => void;
onerror?: () => void;
onload?: () => void;
onloadend?: () => void;
onloadstart?: () => void;
onprogress?: () => void;
onreadystatechange?: () => void;
ontimeout?: () => void;
}): Promise<void>;
function download(url: string, name: string): Promise<void>;
function getResourceUrl(name: string, isBlobUrl?: boolean): Promise<string>;
function getValue<T>(
key: string,
defaultValue?: string | number | boolean,
): Promise<T>;
function getValue(
key: string,
defaultValue?: string | number | boolean,
): Promise<string>;
function getValues<T>(keys: string[]): Promise<{ [key: string]: T }>;
function getValues<T>(obj: {
[key: string]: T;
}): Promise<{ [key: string]: T }>;
const info: vm_infoType;
function listValues(): Promise<string[]>;
function notification(options: {
text: string;
title?: string;
image?: string;
silent?: boolean; // false
tag?: string;
zombieTimeout?: number;
zombieUrl?: string;
onclick?: () => void;
ondone?: () => void;
}): Promise<() => void>;
function notification(
text: string,
title?: string,
image?: string,
onclick?: () => void,
): promise<() => void>;
function openInTab(
url: string,
options?: {
active?: boolean; // true
container?: number; // 0 = default (main) container 1, 2, etc. = internal container index
insert?: boolean; // true
pinned?: boolean; // false
},
): {
onclose?: () => void;
closed: boolean;
close: () => void;
};
function openInTab(
url: string,
openInBackground: boolean,
): {
onclose?: () => void;
closed: boolean;
close: () => void;
};
function setClipboard(data: string, type: string): void;
function setValue(key: string, value: unknown): Promise<void>;
function setValues(obj: { [key: string]: unknown }): Promise<void>;
// function xmlHttpRequest<T>(details: vm_detailType<T>): { abort: () => void };
function xmlHttpRequest<T>(
details: vm_detailType<T>,
): Promise<vm_responseObjectType<T>>;
}
function GM_getValue<t>(key: string, defaultValue?: t): t;
function GM_getValue<t>(
key: string,
defaultValue?: string | number | boolean,
): t;
function GM_getValue(
key: string,
defaultValue?: string | number | boolean,
): string;
function GM_setValue<t>(key: string, value: t): void;
function GM_setValue(key: string, value: string | number | boolean): void;
function GM_deleteValue(key: string): void;
function GM_listValues(): string[];
function GM_addValueChangeListener(
name,
callback: (name, oldValue, newValue, remote) => void,
): string;
function GM_removeValueChangeListener(listenerId: string): void;
function GM_getResourceText(name: string): string;
function GM_getResourceURL(name: string): string;
function GM_getResourceURL(name: string, isBlobUrl: boolean): string;
function GM_addElement(
tagName: string,
attributes?: { [key: string]: string },
): HTMLElement;
function GM_addElement(
parentNode: Node | Element | ShadowRoot,
tagName: string,
attributes?: { [key: string]: string },
): HTMLElement;
function GM_addStyle(css: string): HTMLStyleElement;
function GM_openInTab(
url: string,
options?: openInNewTabOptionsType,
): openInNewTabReturnType;
function GM_openInTab(
url: string,
openInBackground?: boolean,
): openInNewTabReturnType;
function GM_registerMenuCommand(
caption: string,
onClick: (e: MouseEvent | KeyboardEvent) => void,
): void;
function GM_unregisterMenuCommand(caption: string): void;
function GM_notification(option: vm_optionType): vm_notificationReturnType;
function GM_notification(
text: string,
title?: string,
image?: string,
onclick?: () => void,
): vm_notificationReturnType;
function GM_setClipboard(data: string, type: string): void;
function GM_xmlhttpRequest(
request: vm_xmlhttpRequestType,
): Promise<vm_xmlhttpRequestReturnType>;
function GM_download(url: string, name?: string): void;
function GM_download(options: vm_downloadOptionsType): void;
import '@violentmonkey/types';

View file

@ -2,7 +2,7 @@
// @name manga reading
// @namespace https://userscripts.skaarup.dev
// @homepageURL https://userscripts.skaarup.dev
// @version 3.3
// @version 3.4
// @author nws
// @description Adds nearly complete keyboard navigation and cleans up the user interface of manganato
// @updateURL https://userscripts.skaarup.dev/scripts/manga-reading.user.js
@ -169,7 +169,7 @@ async function initMangaReading() {
};
} = {};
function registerConfig(info: vm_infoType, container: HTMLElement, callback: () => void) {
function registerConfig(info: typeof GM.info, container: HTMLElement, callback: () => void) {
registeredConfigurations[info.script.name] = {
name: info.script.name,
container,
@ -179,7 +179,7 @@ async function initMangaReading() {
ui.subConfigTarget.appendChild(container);
}
function unregisterConfig(info: vm_infoType) {
function unregisterConfig(info: typeof GM.info) {
registeredConfigurations[info.script.name]?.container.remove();
delete registeredConfigurations[info.script.name];
}
@ -928,7 +928,7 @@ async function initMangaReading() {
timeout: 5000,
responseType: 'json',
anonymous: true,
data: init?.body ?? undefined
data: init?.body?.toString() ?? undefined
});
const respHeaders = parseHeaders(resp.responseHeaders);