Skip to content

Commit

Permalink
chore(deps): update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
windingwind committed Dec 31, 2024
1 parent af06c2d commit 3f334be
Show file tree
Hide file tree
Showing 11 changed files with 733 additions and 891 deletions.
1,565 changes: 692 additions & 873 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@
"franc": "^6.2.0",
"iso639-js": "^1.1.3",
"jsencrypt": "^3.3.2",
"zotero-plugin-toolkit": "^4.0.11"
"zotero-plugin-toolkit": "^4.1.1"
},
"devDependencies": {
"@eslint/js": "^9.7.0",
"@types/node": "^20.17.8",
"@types/node": "^20.17.10",
"chokidar-cli": "^3.0.0",
"concurrently": "^8.2.2",
"cross-env": "^7.0.3",
"eslint": "^9.15.0",
"eslint": "^9.17.0",
"husky": "^9.1.7",
"lint-staged": "^15.2.10",
"prettier": "^3.4.1",
"lint-staged": "^15.3.0",
"prettier": "^3.4.2",
"typescript": "^5.7.2",
"typescript-eslint": "^8.16.0",
"typescript-eslint": "^8.19.0",
"zotero-plugin-scaffold": "^0.1.7",
"zotero-types": "^3.0.3"
"zotero-types": "^3.1.1"
},
"prettier": {
"printWidth": 80,
Expand Down
1 change: 1 addition & 0 deletions src/elements/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export class PluginCEBase extends XULElementBase {
useShadowRoot = false;

connectedCallback(): void {
// @ts-ignore - Plugin instance is not typed
this._addon = Zotero[config.addonInstance];
Zotero.UIProperties.registerRoot(this);
if (!this.useShadowRoot) {
Expand Down
1 change: 1 addition & 0 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function onShutdown(): void {
ztoolkit.unregisterAll();
// Remove addon object
addon.data.alive = false;
// @ts-ignore - Plugin instance is not typed
delete Zotero[config.addonInstance];
}

Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { config } from "../package.json";

const basicTool = new BasicTool();

// @ts-ignore - Plugin instance is not typed
if (!basicTool.getGlobal("Zotero")[config.addonInstance]) {
// Set global variables
_globalThis.Zotero = basicTool.getGlobal("Zotero");
Expand All @@ -13,6 +14,7 @@ if (!basicTool.getGlobal("Zotero")[config.addonInstance]) {
defineGlobal("ztoolkit", () => {
return _globalThis.addon.data.ztoolkit;
});
// @ts-ignore - Plugin instance is not typed
Zotero[config.addonInstance] = addon;
// Trigger addon hook for initialization
addon.hooks.onStartup();
Expand Down
2 changes: 1 addition & 1 deletion src/modules/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function registerPrompt() {
let task = queue.find(
(task: any) => task.raw == selection && task.result.length > 0,
);
task = null;
task = undefined;
if (!task) {
prompt.showTip("Loading...");
task = await Zotero.PDFTranslate.api.translate(selection);
Expand Down
16 changes: 10 additions & 6 deletions src/modules/services/haicidict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@ export default <TranslateTaskProcessor>async function (data) {
const doc = new DOMParser().parseFromString(res, "text/html");

const audioList: Array<{ text: string; url: string }> = [];
for (const span of doc.querySelectorAll<HTMLSpanElement>(
"div.phonetic > span",
)) {
for (const span of Array.from(
doc.querySelectorAll<HTMLSpanElement>("div.phonetic > span"),
) as Array<HTMLSpanElement>) {
const text = span.innerText.replace(/\s+/g, " ").trim();
for (const item of span.querySelectorAll("i")) {
for (const item of Array.from(
span.querySelectorAll("i"),
) as Array<HTMLElement>) {
audioList.push({
text: `${text} ${item.title}`,
url: `https://audio.dict.cn/${item.getAttribute("naudio")}`,
});
}
}
data.audio = audioList;
const items = Array.from(
doc.querySelectorAll<HTMLLIElement>("ul.dict-basic-ul > li"),
const items = (
Array.from(
doc.querySelectorAll<HTMLLIElement>("ul.dict-basic-ul > li"),
) as Array<HTMLLIElement>
)
.filter((item) => !item.querySelector("script"))
.map((item) => item.innerText.replace(/\s+/g, " ").trim())
Expand Down
4 changes: 3 additions & 1 deletion src/modules/services/webliodict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export default <TranslateTaskProcessor>async function (data) {
);

for (const e of doc.querySelectorAll<Element>(".intrst")) {
const tableRow = e.querySelector<HTMLTableRowElement>("tr");
const tableRow = (e as HTMLElement)?.querySelector<HTMLTableRowElement>(
"tr",
);
if (tableRow) {
translations.push(process(tableRow));
}
Expand Down
9 changes: 9 additions & 0 deletions src/utils/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export class TranslateTaskRunner {
}

public async run(data: TranslateTask) {
// @ts-ignore - Plugin instance is not typed
const addon = Zotero[config.addonInstance] as Addon;
const ztoolkit = addon.data.ztoolkit;
if (!data.langfrom || !data.langto) {
Expand Down Expand Up @@ -153,6 +154,7 @@ export function addTranslateTask(
if (!raw) {
return;
}
// @ts-ignore - Plugin instance is not typed
const addon = Zotero[config.addonInstance] as Addon;
type = type || "text";
// Filter raw string
Expand Down Expand Up @@ -250,6 +252,7 @@ export function addTranslateTitleTask(
itemId: number,
skipIfExists: boolean = false,
) {
// @ts-ignore - Plugin instance is not typed
const addon = Zotero[config.addonInstance] as Addon;
const ztoolkit = addon.data.ztoolkit;
const item = Zotero.Items.get(itemId);
Expand All @@ -268,6 +271,7 @@ export function addTranslateAbstractTask(
itemId: number,
skipIfExists: boolean = false,
) {
// @ts-ignore - Plugin instance is not typed
const addon = Zotero[config.addonInstance] as Addon;
const ztoolkit = addon.data.ztoolkit;
const item = Zotero.Items.get(itemId);
Expand Down Expand Up @@ -303,6 +307,7 @@ function setDefaultService(task: TranslateTask) {
}

function cleanTasks() {
// @ts-ignore - Plugin instance is not typed
const addon = Zotero[config.addonInstance] as Addon;

if (
Expand All @@ -316,6 +321,7 @@ function cleanTasks() {
}

export function getTranslateTasks(count: number) {
// @ts-ignore - Plugin instance is not typed
return (Zotero[config.addonInstance] as Addon).data.translate.queue.slice(
-count,
);
Expand All @@ -325,6 +331,7 @@ export function getLastTranslateTask<
K extends keyof TranslateTask,
V extends TranslateTask[K],
>(conditions?: { [key in K]: V }) {
// @ts-ignore - Plugin instance is not typed
const queue = (Zotero[config.addonInstance] as Addon).data.translate.queue;
let i = queue.length - 1;
while (i >= 0) {
Expand Down Expand Up @@ -353,6 +360,7 @@ export function updateTranslateTaskLang(task: TranslateTask) {
}

export function putTranslateTaskAtHead(taskId: string) {
// @ts-ignore - Plugin instance is not typed
const queue = (Zotero[config.addonInstance] as Addon).data.translate.queue;
const idx = queue.findIndex((task) => task.id === taskId);
if (idx >= 0) {
Expand All @@ -370,6 +378,7 @@ export function autoDetectLanguage(item: Zotero.Item | null) {
toLanguage: getPref("targetLanguage") as string,
};
}
// @ts-ignore - Plugin instance is not typed
const addon = Zotero[config.addonInstance] as Addon;
const ztoolkit = addon.data.ztoolkit;
const topItem = Zotero.Items.getTopLevel([item])[0];
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// used by 'src/utils/config.ts'
"esModuleInterop": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"strict": true
},
"include": ["src", "typings", "node_modules/zotero-types"],
Expand Down
8 changes: 6 additions & 2 deletions typings/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ declare class XULElementBase extends HTMLElement {
newValue: string,
): void;
_handleWindowUnload(): void;
initialized: boolean = false;
initialized: boolean;
static get observedAttributes(): string[];
}

declare class MozXULElement {
static parseXULToFragment(xul: string): Fragment;
static parseXULToFragment(xul: string): DocumentFragment;
static insertFTLIfNeeded(ftl: string): void;
}

declare namespace Zotero {
const PDFTranslate: import("../src/addon").default;
}

0 comments on commit 3f334be

Please sign in to comment.