Skip to content

Commit

Permalink
add files
Browse files Browse the repository at this point in the history
  • Loading branch information
FrLars21 committed Nov 11, 2023
1 parent 40e8dfd commit 9f80808
Show file tree
Hide file tree
Showing 12 changed files with 813 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Zotero 7 Citation Counts Manager Enhaned

- [GitHub](https://github.com/FrLars21/ZoteroCitationCountsManager): Source
code repository

This is an add-on for [Zotero](https://www.zotero.org), a research source management tool. The add-on can auto-fetch citation counts for journal articles using various APIs, including [Crossref](https://www.crossref.org), [INSPIRE-HEP](https://inspirehep.net), and [Semantic Scholar](https://www.semanticscholar.org). [Google Scholar](https://scholar.google.com) is not supported because automated access is against its terms of service.

Please report any bugs, questions, or feature requests in the Github repository.

## Features

- Autoretrieve citation counts when a new item is added to your Zotero library.
- Retrieve citation counts manually by right-clicking on one or more items in your Zotero library.
- Works with the following APIs: [Crossref](https://www.crossref.org), [INSPIRE-HEP](https://inspirehep.net) and [Semantic Scholar](https://www.semanticscholar.org).
- _NEW:_ The plugin is compatible with **Zotero 7** (Zotero 6 is **NOT** supported!).
- _NEW:_ The plugin registers a custom column ("Citation Counts") in your Zotero library so that items can be **ordered by citation count**.
- _NEW:_ Improved _citation count retrieval operation_ status reporting, including item-specific error messages for those items where a citation count couldn't be retrieved.
- _NEW:_ Concurrent citation count retrieval operations is now possible. Especially important for the autoretrieve feature.
- _NEW:_ Fluent is used for localizing, while the locale file has been simplified and now cover the whole plugin. You are welcome to submit translations as a PR.
- _NEW:_ The whole codebade has been refactored with a focus on easy maintenance, especially for the supported citation count APIs.

## Acknowledgements

This plugin is a refactored and enhanced version of Erik Schnetter's [Zotero Citations Counts Manager](https://github.com/eschnett/zotero-citationcounts) for Zotero 7. Code for that extension was based on [Zotero DOI Manager](https://github.com/bwiernik/zotero-shortdoi), which is based in part on [Zotero Google Scholar Citations](https://github.com/beloglazov/zotero-scholar-citations) by Anton Beloglazov.
Boilerplate for this plugin was based on Zotero's sample plugin for v7 [Make-It-Red](https://github.com/zotero/make-it-red).

## Installing

- Download the add-on (the .xpi file) from the latest release: https://github.com/FrLars21/ZoteroCitationCountsManager/releases
- To download the .xpi file, right click it and select 'Save link as'
- Run Zotero (version 7.x)
- Go to `Tools -> Add-ons`
- `Install Add-on From File`
- Choose the file `zoterocitationcountsmanager-2.0.0.xpi`
- Restart Zotero

## License

Distributed under the Mozilla Public License (MPL) Version 2.0.
Binary file added bin/.DS_Store
Binary file not shown.
14 changes: 14 additions & 0 deletions bin/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

cd ..

version='2.0'

rm -f zoterocitationcountsmanager-${version}.xpi
zip -r zoterocitationcountsmanager-${version}.xpi locale/* manifest.json bootstrap.js preferences.js preferences.xhtml prefs.js zoterocitationcounts.js

# To release a new version:
# - increase version number in all files (not just here)
# - run this script to create a new .xpi file
# - commit and push to Github
# - make a release on Github, and manually upload the new .xpi file
58 changes: 58 additions & 0 deletions bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
let ZoteroCitationCounts, itemObserver;

async function startup({ id, version, rootURI }) {
Services.scriptloader.loadSubScript(rootURI + "zoterocitationcounts.js");

ZoteroCitationCounts.init({ id, version, rootURI });
ZoteroCitationCounts.addToAllWindows();

Zotero.PreferencePanes.register({
pluginID: id,
label: await ZoteroCitationCounts.l10n.formatValue(
"citationcounts-preference-pane-label"
),
image: ZoteroCitationCounts.icon("edit-list-order", false),
src: "preferences.xhtml",
scripts: ["preferences.js"],
});

await Zotero.ItemTreeManager.registerColumns({
dataKey: "citationcounts",
label: await ZoteroCitationCounts.l10n.formatValue(
"citationcounts-column-title"
),
pluginID: id,
dataProvider: (item) => ZoteroCitationCounts.getCitationCount(item),
});

itemObserver = Zotero.Notifier.registerObserver(
{
notify: function (event, type, ids, extraData) {
if (event == "add") {
const pref = ZoteroCitationCounts.getPref("autoretrieve");
if (pref === "none") return;

const api = ZoteroCitationCounts.APIs.find((api) => api.key === pref);
if (!api) return;

ZoteroCitationCounts.updateItems(Zotero.Items.get(ids), api);
}
},
},
["item"]
);
}

function onMainWindowLoad({ window }) {
ZoteroCitationCounts.addToWindow(window);
}

function onMainWindowUnload({ window }) {
ZoteroCitationCounts.removeFromWindow(window);
}

function shutdown() {
ZoteroCitationCounts.removeFromAllWindows();
Zotero.Notifier.unregisterObserver(itemObserver);
ZoteroCitationCounts = undefined;
}
Binary file added locale/.DS_Store
Binary file not shown.
36 changes: 36 additions & 0 deletions locale/en-US/citation-counts.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## For the custom column that the plugin registers
citationcounts-column-title = Citation count
## For the "Item" contextmenu, where citation counts can be manually retrieved for the selected items.
citationcounts-itemmenu-retrieve-title =
.label = Get citation count
citationcounts-itemmenu-retrieve-api =
.label = Get { $api } citation count
## For the ProgressWindow, showing citation counts retrieval operation status
citationcounts-progresswindow-headline = Getting { $api } citation counts.
citationcounts-progresswindow-finished-headline = Finished getting { $api } citation counts.
citationcounts-progresswindow-error-no-doi = No DOI field exists on the item.
citationcounts-progresswindow-error-no-arxiv = No arXiv id found on the item.
citationcounts-progresswindow-error-no-doi-or-arxiv = No DOI / arXiv ID found on the item.
citationcounts-progresswindow-error-bad-api-response = Problem accesing the { $api } API.
citationcounts-progresswindow-error-no-citation-count = { $api } doesn't have a citation count for this item.
## For the "Tools" menu, where the "autoretrieve" preference can be set.
citationcounts-menutools-autoretrieve-title =
.label = Get citation counts for new items?
citationcounts-menutools-autoretrieve-api =
.label = { $api }
citationcounts-menutools-autoretrieve-api-none =
.label = No
## For the plugins "Preferences" pane.
citationcounts-preference-pane-label = Citation Counts
citationcounts-preferences-pane-autoretrieve-title = Get citation counts for new items?
citationcounts-preferences-pane-autoretrieve-api =
.label = { $api }
citationcounts-preferences-pane-autoretrieve-api-none =
.label = No
## Misc
citationcounts-internal-error = Internal error
15 changes: 15 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"manifest_version": 2,
"name": "Zotero Citation Counts Manager",
"version": "2.0",
"description": "Enhanced Citation Counts Manager for Zotero 7",
"homepage_url": "https://github.com/FrLars21/ZoteroCitationCountsManager",
"applications": {
"zotero": {
"id": "[email protected]",
"update_url": "https://www.zotero.org/download/plugins/make-it-red/updates.json",
"strict_min_version": "6.999",
"strict_max_version": "7.0.*"
}
}
}
73 changes: 73 additions & 0 deletions preferences.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
ZoteroCitationCounts_Prefs = {
/**
* @TODO reference ZoteroCitationCounts.APIs directly.
*/
APIs: [
{
key: "crossref",
name: "Crossref",
},
{
key: "inspire",
name: "INSPIRE-HEP",
},
{
key: "semanticscholar",
name: "Semantic Scholar",
},
],

init: function () {
this.APIs.concat({ key: "none" }).forEach((api) => {
const label =
api.key === "none"
? {
"data-l10n-id":
"citationcounts-preferences-pane-autoretrieve-api-none",
}
: {
"data-l10n-id":
"citationcounts-preferences-pane-autoretrieve-api",
"data-l10n-args": `{"api": "${api.name}"}`,
};

this._injectXULElement(
document,
"radio",
`citationcounts-preferences-pane-autoretrieve-radio-${api.key}`,
{
...label,
value: api.key,
},
"citationcounts-preference-pane-autoretrieve-radiogroup"
);
});
},

/**
* @TODO reference ZoteroCitationCounts._injectXULElement directly.
*/
_injectXULElement: function (
document,
elementType,
elementID,
elementAttributes,
parentID,
eventListeners
) {
const element = document.createXULElement(elementType);
element.id = elementID;

Object.entries(elementAttributes || {})
.filter(([_, value]) => value !== null && value !== undefined)
.forEach(([key, value]) => element.setAttribute(key, value));

Object.entries(eventListeners || {}).forEach(([eventType, listener]) => {
element.addEventListener(eventType, listener);
});

document.getElementById(parentID).appendChild(element);

return element;
},
};
19 changes: 19 additions & 0 deletions preferences.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<linkset>
<html:link rel="localization" href="citation-counts.ftl" />
</linkset>

<vbox onload="ZoteroCitationCounts_Prefs.init()">
<groupbox>
<label
><html:h2
data-l10n-id="citationcounts-preferences-pane-autoretrieve-title"
></html:h2
></label>
<radiogroup
id="citationcounts-preference-pane-autoretrieve-radiogroup"
preference="extensions.citationcounts.autoretrieve"
>
<!-- Radiobuttons are dynamically created by the script -->
</radiogroup>
</groupbox>
</vbox>
1 change: 1 addition & 0 deletions prefs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pref("extensions.citationcounts.autoretrieve", "none");
Loading

0 comments on commit 9f80808

Please sign in to comment.