Last active
August 25, 2020 17:31
-
-
Save zuphilip/197adcba46450dd00b7f892e9933656f to your computer and use it in GitHub Desktop.
Output selected items as a bibliography by year or tag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var items = Zotero.getActiveZoteroPane().getSelectedItems(); | |
| var qc = Zotero.QuickCopy; | |
| var format = Zotero.Prefs.get("export.quickCopy.setting"); | |
| if (format.split("=")[0] !== "bibliography") { | |
| //return "No bibliography style is choosen in the settings for QuickCopy and therefore stop here."; | |
| await Zotero.Schema.schemeUpdatePromise; | |
| var styles = Zotero.Styles.getVisible(); | |
| format = "bibliography=" + styles[0].styleID; | |
| } | |
| var itemsByYear = {}; | |
| var years = []; | |
| for (let item of items) { | |
| let year = item.getField("year") || "n.d."; | |
| year = year.substr(0, 4); | |
| if (years.includes(year)) { | |
| itemsByYear[year].push(item); | |
| } | |
| else { | |
| itemsByYear[year] = [item]; | |
| years.push(year); | |
| } | |
| } | |
| years.sort().reverse(); | |
| var outputString = ""; | |
| for (let year of years) { | |
| outputString += "\n\n" + year + "\n\n"; | |
| outputString += qc.getContentFromItems(itemsByYear[year], format).text; | |
| } | |
| return outputString.substr(2); | |
| return biblio.text; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var items = Zotero.getActiveZoteroPane().getSelectedItems(); | |
| var qc = Zotero.QuickCopy; | |
| var format = Zotero.Prefs.get("export.quickCopy.setting"); | |
| if (format.split("=")[0] !== "bibliography") { | |
| //return "No bibliography style is choosen in the settings for QuickCopy and therefore stop here."; | |
| await Zotero.Schema.schemeUpdatePromise; | |
| var styles = Zotero.Styles.getVisible(); | |
| format = "bibliography=" + styles[0].styleID; | |
| } | |
| var itemsByTag = {}; | |
| var tags= []; | |
| for (let item of items) { | |
| let foundTags = item.getTags() || "untagged"; | |
| if (foundTags.length == 0) { | |
| foundTags = [{"tag": "[without tags]"}]; | |
| } | |
| for (let tag of foundTags) { | |
| tag = tag.tag; | |
| if (tags.includes(tag)) { | |
| itemsByTag[tag].push(item); | |
| } | |
| else { | |
| itemsByTag[tag] = [item]; | |
| tags.push(tag); | |
| } | |
| } | |
| } | |
| tags.sort(function(a, b) { | |
| return itemsByTag[b].length - itemsByTag[a].length; | |
| }); | |
| var outputString = ""; | |
| for (let tag of tags) { | |
| outputString += "\n\n" + tag + " : " + itemsByTag[tag].length + " item(s)\n\n"; | |
| outputString += qc.getContentFromItems(itemsByTag[tag], format).text; | |
| } | |
| return outputString.substr(2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment