Skip to content

Commit

Permalink
增加注入style功能。方便处理一些样式
Browse files Browse the repository at this point in the history
  • Loading branch information
zzlb0224 committed Apr 13, 2024
1 parent a702221 commit dd33b0a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/utils/zzlb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,28 @@ export async function openAnnotation(
else setTimeout(sidebarItemFocus, 50);
}
}

export async function injectCSS(doc: Document, path: "annotation.css") {
ztoolkit.UI.appendElement(
{
tag: "style",
id: "style_css_" + path.replace(/[\/:\s\.]/g, "_"),
properties: {
innerHTML: await getFileContent(rootURI + "chrome/content/" + path),
},
ignoreIfExists: true,
},
doc.querySelector("head") ||
doc.querySelector("body") ||
doc.querySelector("div") ||
doc.children[0],
);
}
export async function getFileContent(path: string) {
const contentOrXHR = await Zotero.File.getContentsAsync(path);
const content =
typeof contentOrXHR === "string"
? contentOrXHR
: (contentOrXHR as any as XMLHttpRequest).response;
return content;
}

0 comments on commit dd33b0a

Please sign in to comment.