From 3c6b8a118a62bd61fa788bc3ce86b55efc14a00e Mon Sep 17 00:00:00 2001 From: RumovZ Date: Sun, 28 Apr 2024 21:37:10 +0200 Subject: [PATCH 1/2] Add demo add-on for adding a custom exporter --- demos/add_exporter/__init__.py | 15 +++++++++++++++ demos/add_exporter/init.js | 27 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 demos/add_exporter/__init__.py create mode 100644 demos/add_exporter/init.js diff --git a/demos/add_exporter/__init__.py b/demos/add_exporter/__init__.py new file mode 100644 index 0000000..847fead --- /dev/null +++ b/demos/add_exporter/__init__.py @@ -0,0 +1,15 @@ +""" +An example of extending the deck options screen with raw HTML/JS. +""" + +from pathlib import Path + +from aqt import gui_hooks +from aqt.webview import AnkiWebView + + +def setup(webview: AnkiWebView) -> None: + webview.eval(Path(__file__).with_name("init.js").read_text(encoding="utf8")) + + +gui_hooks.webview_did_inject_style_into_page.append(setup) diff --git a/demos/add_exporter/init.js b/demos/add_exporter/init.js new file mode 100644 index 0000000..6a87667 --- /dev/null +++ b/demos/add_exporter/init.js @@ -0,0 +1,27 @@ +function updateExporters(exporters) { + for (const exporter of exporters) { + exporter.isDefault = false; + } + exporters.push({ + extension: "csv", + label: "My fancy CSV", + showDeckList: true, + showIncludeScheduling: false, + showIncludeDeckConfigs: false, + showIncludeMedia: false, + showIncludeTags: false, + showIncludeHtml: false, + showLegacySupport: false, + showIncludeDeck: false, + showIncludeNotetype: false, + showIncludeGuid: false, + isDefault: true, + doExport: (outPath, limit, options) => { + alert("Not implemented!"); + return Promise.resolve(); + } + }); + return exporters; +} + +addEventListener("exportersDidInitialize", (event) => event.detail.exporters.update(updateExporters)); From 923657dcecdaf8478ba3762337e30d98ae03ac24 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Sat, 18 May 2024 21:30:23 +0200 Subject: [PATCH 2/2] Use requireAsync() --- demos/add_exporter/__init__.py | 2 +- demos/add_exporter/init.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/demos/add_exporter/__init__.py b/demos/add_exporter/__init__.py index 847fead..e0c0bd2 100644 --- a/demos/add_exporter/__init__.py +++ b/demos/add_exporter/__init__.py @@ -1,5 +1,5 @@ """ -An example of extending the deck options screen with raw HTML/JS. +An example of adding an exporter to export page. """ from pathlib import Path diff --git a/demos/add_exporter/init.js b/demos/add_exporter/init.js index 6a87667..ccc21ab 100644 --- a/demos/add_exporter/init.js +++ b/demos/add_exporter/init.js @@ -24,4 +24,4 @@ function updateExporters(exporters) { return exporters; } -addEventListener("exportersDidInitialize", (event) => event.detail.exporters.update(updateExporters)); +requireAsync("anki/ExportPage").then(mod => mod.exporters.update(updateExporters));