Developing a plugin, unable to get preferences

With the help of ChatGPT (hopefully that isn't cringe, LOL), I'm trying to build a Zotero 7 plugin. I'm not really a competent developer, though I'm capable and learning. The documentation I've found is thin and I've looked at other plugins, which has helped some but there isn't much consistency, especially with some that work with 6/7.

It's a plugin to automate the generation of tags for items. I have a basic script that works in the "Run Javascript" console and have been able to integrate it into an installable plugin with a working preference pane and menu item (the menu from right-clicking on an item) that runs the script, but I have not been able to retrieve the preferences I have set from the script. ChatGPT helped me with adding logging for troubleshooting but everything I try to retrieve with Zotero.Prefs.get is empty. ChatGPT seems to think the proper window isn't in scope, or something like that but nothing I've tried works.

I'm hoping someone can help me figure this out. Here are some snippets of the code:

In bootstrap.js:
async function startup({ id, version, rootURI }) {
log("Starting: " + myVersion);
Zotero.PreferencePanes.register({
src: rootURI + 'prefs.xhtml',
scripts: [rootURI + 'prefs.js']
});
Services.scriptloader.loadSubScript(rootURI + "itemtagger.js");
ItemTagger.addToAllWindows();
}

In my main plugin script (itemtagger.js):
var ItemTagger = {
menuId: "itemtagger-generate-tags",

addToWindow(win) {
let doc = win.document;
let menu = doc.getElementById("zotero-itemmenu");
if (!menu) return;
// Prevent duplicate
if (doc.getElementById(this.menuId)) return;

let menuitem = doc.createXULElement("menuitem");
menuitem.id = this.menuId;
menuitem.setAttribute("label", "Generate Tags for Item");
menuitem.setAttribute("class", "menuitem-iconic");
menuitem.setAttribute("image", "chrome://zotero/skin/tag.svg");
menuitem.addEventListener("command", async (event) => {
try {
await ItemTagger.runOnSelected(win);
} catch (e) {
Zotero.alert(win, "Item Tagger", "Error: " + e.message);
}
});
menu.appendChild(menuitem);
},

...

async runOnSelected(win) {
let pane = win.ZoteroPane;
let items = pane.getSelectedItems();
if (!items || !items.length) throw new Error("No item selected.");
let selItem = items[0];

let tagThreshold = Zotero.Prefs.get('extensions.itemtagger.tag_threshold', true);
log('Log Zotero font:', Zotero.Prefs.get('font.size'));
log('Log pref:', Zotero.Prefs.get('extensions.itemtagger.tag_threshold', true));

Sign In or Register to comment.