Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/app/service/content/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default class ContentRuntime {
case "GM_addElement": {
const [parentNodeId, tagName, tmpAttr] = data.params;
let attr = { ...tmpAttr };
let parentNode: EventTarget | undefined;
let parentNode: Node | undefined;
// 判断是不是content脚本发过来的
let msg: CustomEventMessage;
if (this.contentScriptSet.has(data.uuid) || this.scriptExecutor.execMap.has(data.uuid)) {
Expand All @@ -85,7 +85,7 @@ export default class ContentRuntime {
msg = this.senderToInject;
}
if (parentNodeId) {
parentNode = msg.getAndDelRelatedTarget(parentNodeId);
parentNode = msg.getAndDelRelatedTarget(parentNodeId) as Node | undefined;
}
const el = <Element>document.createElement(tagName);

Expand All @@ -104,7 +104,7 @@ export default class ContentRuntime {
if (textContent) {
el.textContent = textContent;
}
(<Element>parentNode || document.head || document.body || document.querySelector("*")).appendChild(el);
(parentNode || document.head || document.body || document.querySelector("*")).appendChild(el);
const nodeId = msg.sendRelatedTarget(el);
return nodeId;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/service/content/gm_api/gm_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ export default class GMApi extends GM_Base {

@GMContext.API({ alias: "GM.addElement" })
GM_addElement(
parentNode: EventTarget | string,
parentNode: Node | string,
tagName: string | Record<string, string | number | boolean>,
attrs: Record<string, string | number | boolean> = {}
) {
Expand Down
22 changes: 13 additions & 9 deletions src/template/scriptcat.d.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ declare function GM_xmlhttpRequest(details: GMTypes.XHRDetails): GMTypes.AbortHa
declare function GM_download(details: GMTypes.DownloadDetails<string | Blob | File>): GMTypes.AbortHandle<boolean>;
declare function GM_download(url: string, filename: string): GMTypes.AbortHandle<boolean>;

declare function GM_getTab(callback: (obj: object) => void): void;
declare function GM_getTab(callback: (tab: object) => void): void;

declare function GM_saveTab(obj: object): Promise<void>;
declare function GM_saveTab(tab: object): Promise<void>;

declare function GM_getTabs(callback: (objs: { [key: number]: object }) => void): void;
declare function GM_getTabs(callback: (tabs: { [key: number]: object }) => void): void;

declare function GM_notification(details: GMTypes.NotificationDetails, ondone?: GMTypes.NotificationOnDone): void;
declare function GM_notification(
Expand All @@ -191,8 +191,12 @@ declare function GM_updateNotification(id: string, details: GMTypes.Notification

declare function GM_setClipboard(data: string, info?: string | { type?: string; mimetype?: string }): void;

declare function GM_addElement(tag: string, attributes: any): HTMLElement;
declare function GM_addElement(parentNode: Element, tag: string, attrs: any): HTMLElement;
declare function GM_addElement(tag: string, attributes: Record<string, string | number | boolean>): HTMLElement;
declare function GM_addElement(
parentNode: Node,
tag: string,
attrs: Record<string, string | number | boolean>
): HTMLElement;

declare function GM_addStyle(css: string): HTMLStyleElement;

Expand Down Expand Up @@ -266,7 +270,7 @@ declare const GM: {
unregisterMenuCommand(id: number | string): Promise<void>;

/** 样式注入 */
addStyle(css: string): Promise<void>;
addStyle(css: string): Promise<HTMLStyleElement>;

/** 通知 */
notification(details: GMTypes.NotificationDetails, ondone?: GMTypes.NotificationOnDone): Promise<void>;
Expand All @@ -278,8 +282,8 @@ declare const GM: {
setClipboard(data: string, info?: string | { type?: string; mimetype?: string }): Promise<void>;

/** 添加元素 */
addElement(tag: string, attributes: any): Promise<HTMLElement>;
addElement(parentNode: Element, tag: string, attrs: any): Promise<HTMLElement>;
addElement(tag: string, attributes: Record<string, string | number | boolean>): Promise<HTMLElement>;
addElement(parentNode: Node, tag: string, attrs: Record<string, string | number | boolean>): Promise<HTMLElement>;

/** XMLHttpRequest */
xmlHttpRequest(details: GMTypes.XHRDetails): Promise<GMTypes.XHRResponse>;
Expand All @@ -290,7 +294,7 @@ declare const GM: {

/** Tab 存储 */
getTab(): Promise<object>;
saveTab(obj: object): Promise<void>;
saveTab(tab: object): Promise<void>;
getTabs(): Promise<{ [key: number]: object }>;

/** 打开新标签页 */
Expand Down
22 changes: 13 additions & 9 deletions src/types/scriptcat.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ declare function GM_xmlhttpRequest(details: GMTypes.XHRDetails): GMTypes.AbortHa
declare function GM_download(details: GMTypes.DownloadDetails<string | Blob | File>): GMTypes.AbortHandle<boolean>;
declare function GM_download(url: string, filename: string): GMTypes.AbortHandle<boolean>;

declare function GM_getTab(callback: (obj: object) => void): void;
declare function GM_getTab(callback: (tab: object) => void): void;

declare function GM_saveTab(obj: object): Promise<void>;
declare function GM_saveTab(tab: object): Promise<void>;

declare function GM_getTabs(callback: (objs: { [key: number]: object }) => void): void;
declare function GM_getTabs(callback: (tabs: { [key: number]: object }) => void): void;

declare function GM_notification(details: GMTypes.NotificationDetails, ondone?: GMTypes.NotificationOnDone): void;
declare function GM_notification(
Expand All @@ -191,8 +191,12 @@ declare function GM_updateNotification(id: string, details: GMTypes.Notification

declare function GM_setClipboard(data: string, info?: string | { type?: string; mimetype?: string }): void;

declare function GM_addElement(tag: string, attributes: any): HTMLElement;
declare function GM_addElement(parentNode: Element, tag: string, attrs: any): HTMLElement;
declare function GM_addElement(tag: string, attributes: Record<string, string | number | boolean>): HTMLElement;
declare function GM_addElement(
parentNode: Node,
tag: string,
attrs: Record<string, string | number | boolean>
): HTMLElement;

declare function GM_addStyle(css: string): HTMLStyleElement;

Expand Down Expand Up @@ -266,7 +270,7 @@ declare const GM: {
unregisterMenuCommand(id: number | string): Promise<void>;

/** 样式注入 */
addStyle(css: string): Promise<void>;
addStyle(css: string): Promise<HTMLStyleElement>;

/** 通知 */
notification(details: GMTypes.NotificationDetails, ondone?: GMTypes.NotificationOnDone): Promise<void>;
Expand All @@ -278,8 +282,8 @@ declare const GM: {
setClipboard(data: string, info?: string | { type?: string; mimetype?: string }): Promise<void>;

/** 添加元素 */
addElement(tag: string, attributes: any): Promise<HTMLElement>;
addElement(parentNode: Element, tag: string, attrs: any): Promise<HTMLElement>;
addElement(tag: string, attributes: Record<string, string | number | boolean>): Promise<HTMLElement>;
addElement(parentNode: Node, tag: string, attrs: Record<string, string | number | boolean>): Promise<HTMLElement>;

/** XMLHttpRequest */
xmlHttpRequest(details: GMTypes.XHRDetails): Promise<GMTypes.XHRResponse>;
Expand All @@ -290,7 +294,7 @@ declare const GM: {

/** Tab 存储 */
getTab(): Promise<object>;
saveTab(obj: object): Promise<void>;
saveTab(tab: object): Promise<void>;
getTabs(): Promise<{ [key: number]: object }>;

/** 打开新标签页 */
Expand Down
Loading