From 84a3a61c0068a77e1d57d220883bb3dccfd58ead Mon Sep 17 00:00:00 2001 From: Trenton Schulz Date: Tue, 7 Mar 2023 22:01:05 +0100 Subject: [PATCH] Add a function for getting the non-deprecated link. This is mostly just adapted from Zutilo, but it seems to be considered the "blessed" version, so I'm keeping it for now. --- extension/bootstrap.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/extension/bootstrap.js b/extension/bootstrap.js index 9f8b054..933520d 100644 --- a/extension/bootstrap.js +++ b/extension/bootstrap.js @@ -42,6 +42,44 @@ const textMediaType = 'text/plain; charset=UTF-8'; const badRequestCode = 400; const okCode = 200; +function loadZotero () { + let callback = function (resolve, reject) { + if (!Zotero) { + if (!("@zotero.org/Zotero;1" in Components.classes)) { + let timer = Components.classes["@mozilla.org/timer;1"].createInstanceComponents.interfaces.nsITimer; + return timer.initWithCallback(function () { + return callback(resolve, reject); + }, 10000, Components.interfaces.nsITimer.TYPE_ONE_SHOT); + } else { + Zotero = Components.classes["@zotero.org/Zotero;1"] + .getService(Components.interfaces.nsISupports).wrappedJSObject; + return resolve(Zotero); + } + } else { + return resolve(Zotero); + } + }; + return new Promise(callback); +} + +function buildZoteroLink(item) { + // This is almost a direct copy from Zutilo + let libraryType = Zotero.Libraries.get(item.libraryID).libraryType; + var path = "undefined" + switch (libraryType) { + case 'group': + path = Zotero.URI.getLibraryPath(item.libraryID) + break; + case 'user': + path = 'library' + break; + default: + break; + } + return 'zotero://select/' + path + '/items/'+ item.key +} + + function collectionSearch(name) { let collections = Zotero.Collections.getByLibrary(Zotero.Libraries.userLibraryID, true); for (let collection of collections) { @@ -127,6 +165,8 @@ function buildResponse(items, format, style, locale) { return [okCode, 'application/json', jsonStringify(items.map(item2key))]; } else if (format === 'easykey') { return buildEasyKeyResponse(items); + } else if (format === 'zoteroLink') { + return [okCode, 'application/json', jsonStringify(items.map(buildZoteroLink))]; } else if (format === 'betterbibtexkey' || format === 'citekey') { return buildBBTKeyResponse(items); } else if (format === 'bibtex') {