Last active
July 4, 2024 13:49
-
-
Save dschaehi/7dae3136ad126ff66de9c88efc511ab2 to your computer and use it in GitHub Desktop.
Actions and Tags for Zotero
This file contains 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
type: ActionsTagsBackup | |
author: jaeheelee | |
platformVersion: 7.0.0-beta.95+694ccecf4 | |
pluginVersion: 1.0.0-beta.44 | |
timestamp: '2024-07-04T13:48:56.124Z' | |
actions: | |
1715690567316-0F2mzqBj: | |
event: 0 | |
operation: 4 | |
data: > | |
/** | |
* Toggle Right Pane | |
* @author [MuiseDestiny](https://github.com/MuiseDestiny), windingwind | |
* @usage Assign a shortcut | |
* @link https://github.com/windingwind/zotero-actions-tags/discussions/169 | |
* @see https://github.com/windingwind/zotero-actions-tags/discussions/169 | |
*/ | |
const Zotero = require("Zotero"); | |
const Zotero_Tabs = require("Zotero_Tabs"); | |
const document = require("document"); | |
const DEFAULT_OPEN_PANE = "item"; | |
if (item) { | |
return; | |
} | |
const splitter = document.querySelector(Zotero_Tabs.selectedType === | |
"library" ? "#zotero-items-splitter":"#zotero-context-splitter"); | |
if (splitter.getAttribute("state") == "collapsed") { | |
splitter.setAttribute("state", ""); | |
return; | |
} else { | |
splitter.setAttribute("state", "collapsed"); | |
return; | |
} | |
shortcut: ⇧,⌃,arrowright | |
enabled: true | |
menu: '' | |
name: Toggle Right Pane | |
showInMenu: | |
item: false | |
collection: false | |
tools: false | |
reader: false | |
readerAnnotation: false | |
1715690499454-0F2mzqBj: | |
event: 0 | |
operation: 4 | |
data: |- | |
/** | |
* Toggle Left Pane | |
* @author [MuiseDestiny](https://github.com/MuiseDestiny), windingwind | |
* @usage Assign a shortcut | |
* @link https://github.com/windingwind/zotero-actions-tags/discussions/169 | |
* @see https://github.com/windingwind/zotero-actions-tags/discussions/169 | |
*/ | |
const Zotero = require("Zotero"); | |
const Zotero_Tabs = require("Zotero_Tabs"); | |
const document = require("document"); | |
if (item) { | |
return; | |
} | |
if (Zotero_Tabs.selectedType === "library") { | |
const splitter = document.querySelector("#zotero-collections-splitter"); | |
if (splitter.getAttribute("state") == "collapsed") { | |
splitter.setAttribute("state", ""); | |
return; | |
} else { | |
splitter.setAttribute("state", "collapsed"); | |
return; | |
} | |
} else { | |
Zotero.Reader.getByTabID( | |
Zotero_Tabs.selectedID | |
)._internalReader.toggleSidebar(); | |
return; | |
} | |
shortcut: ⇧,⌃,ArrowLeft | |
enabled: true | |
menu: '' | |
name: Toggle Left Pane | |
showInMenu: | |
item: false | |
collection: false | |
tools: false | |
reader: false | |
readerAnnotation: false | |
1707936562886-0F2mzqBj: | |
event: 0 | |
operation: 4 | |
data: >- | |
const ZoteroPane = require("ZoteroPane"); | |
var iv = ZoteroPane.itemsView; await | |
iv.selectItem(iv.getRow(Zotero.Utilities.rand(0, iv.rowCount - 1)).id) | |
shortcut: ⌘,r | |
enabled: true | |
menu: Select random item | |
name: Select random item | |
showInMenu: | |
item: false | |
collection: false | |
tools: true | |
reader: false | |
readerAnnotation: false | |
default1: | |
event: 3 | |
operation: 2 | |
data: /unread | |
shortcut: '' | |
enabled: false | |
menu: '' | |
name: Remove Unread When Close Tab | |
showInMenu: | |
item: true | |
collection: true | |
tools: true | |
reader: true | |
readerAnnotation: true | |
1707922271773-0F2mzqBj: | |
event: 0 | |
operation: 4 | |
data: >- | |
// Remove tags | |
// @author Yang1824 | |
// @link | |
https://github.com/windingwind/zotero-actions-tags/discussions/127 | |
// @usage Shortcut | |
if (!item) return; | |
item.getTags().map((tag) => tag.tag).forEach((tag) => | |
{item.removeTag(tag)}) | |
shortcut: ⇧,⌃,d | |
enabled: true | |
menu: Remove tags | |
name: Remove tags | |
showInMenu: | |
item: false | |
collection: false | |
tools: false | |
reader: false | |
readerAnnotation: false | |
1707944365108-0F2mzqBj: | |
event: 0 | |
operation: 4 | |
data: "/**\n * Relate selected items\n * @author windingwind\n * @usage Set all selected items to be related to each other from a right-click on several items\n * @link https://github.com/windingwind/zotero-actions-tags/discussions/164\n * @see https://github.com/windingwind/zotero-actions-tags/discussions/164\n */\nif (items?.length === 0 || item) {\n\treturn;\n}\n\n// https://github.com/wshanks/Zutilo/blob/8d53047cf35c11490e0d82156d4ee12136c7fb31/addon/chrome/content/zutilo/zoteroOverlay.js#L710\nconst zitems = items.filter(_item => _item.isRegularItem() || _item.isNote() || _item.isAttachment());\nif (zitems.length < 2) {\n\treturn \"Must select 2 or more items\";\n}\n\nfor (let zitem of zitems) {\n\tfor (let addItem of zitems) {\n\t\tif (zitem != addItem) {\n\t\t\tzitem.addRelatedItem(addItem)\n\t\t}\n\t}\n\tzitem.saveTx();\n}\n\nreturn `Successfully relate ${zitems.length} items.`;" | |
shortcut: ⇧,⌃,l | |
enabled: true | |
menu: Related selected items | |
name: Relate selected items | |
showInMenu: | |
item: false | |
collection: false | |
tools: false | |
reader: false | |
readerAnnotation: false | |
1711397904537-0F2mzqBj: | |
event: 9 | |
operation: 4 | |
data: "const ZoteroPane = require(\"ZoteroPane\");\nconst Zotero_Tabs = require(\"Zotero_Tabs\");\nconst document = require(\"document\");\n\nasync function getAttachmentPath(item) {\n if (item.isAttachment() && !item.isNote()) {\n return await item.getFilePathAsync();\n }\n else if (item.isRegularItem() && !item.isAttachment()) {\n let attachments = await item.getAttachments();\n for (let attachmentID of attachments) {\n let attachment = await Zotero.Items.getAsync(attachmentID);\n\t\t\treturn await attachment.getFilePathAsync();\n }\n }\n return null;\n}\n\nasync function openFile(item) {\n let filePath = await getAttachmentPath(item);\n if (!filePath) {\n return false;\n }\n // macbook path : -p /usr/bin/qlmanage\n // linux path : /usr/bin/sushi\n let applicationPath = \"/usr/bin/qlmanage\"\n\tlet args = ['-p', filePath]\n\tZotero.Utilities.Internal.exec(applicationPath, args);\n}\n\nasync function oneKey(event) {\n\tvar key = String.fromCharCode(event.which);\n\tlet item = ZoteroPane.getSelectedItems()[0];\n\tif (Zotero_Tabs.selectedID === \"zotero-pane\") {\n\t\tif ((key == ' ' && !(event.ctrlKey || event.altKey || event.metaKey)) || (key == 'y' && event.metaKey && !(event.ctrlKey || event.altKey))) {\n\t\t\tawait openFile(item);\n\t\t\tZoteroPane.collectionsView.selectItems([item.id]);\n\t\t\treturn \n\t\t}\n\t}\n}\n\ndocument.getElementById('zotero-items-tree').addEventListener(\"keydown\", oneKey, false);" | |
shortcut: '' | |
enabled: true | |
menu: QuickLook | |
name: QuickLook | |
showInMenu: | |
item: false | |
collection: false | |
tools: false | |
reader: false | |
readerAnnotation: false | |
1710970507615-0F2mzqBj: | |
event: 0 | |
operation: 4 | |
data: "/**\n * QuickCopy items\n * @author Zotero Community\n * @usage Copy selected items to the clipboard\n * @link https://github.com/windingwind/zotero-actions-tags/discussions/165\n * @see https://github.com/windingwind/zotero-actions-tags/discussions/165\n */\nif (items?.length === 0 || item) {\n\treturn;\n}\n\nconst Zotero = require(\"Zotero\");\nconst ZoteroPane = require(\"ZoteroPane\");\n\nconst pref = 'export.quickCopy.setting';\nconst origSetting = Zotero.Prefs.get(pref);\n\n/**\n * Replace this line with your own setting\n * Steps:\n * 1. Change Settings -> Export -> Quick Copy -> Item Format\n * 2. Open Settings -> Advanced -> Config Editor\n * 3. Search for `export.quickCopy.setting`.\n * 4. Paste the value and replace the string `bibliography/html=http://www.zotero.org/styles/acm-siggraph` below.\n * 5. Reset Settings -> Export -> Quick Copy -> Item Format (If necessary)\n */\nconst newSetting = \"export=ca65189f-8815-4afe-8c8b-8c7c15f0edca\";\n\nZotero.Prefs.set(pref, newSetting);\nZoteroPane.copySelectedItemsToClipboard(false);\nZotero.Prefs.set(pref, origSetting);\nreturn `QuickCopy done`;" | |
shortcut: ⇧,⌃,C | |
enabled: true | |
menu: Quick copy BibTeX entry | |
name: Quick copy BibTeX entry | |
showInMenu: | |
item: true | |
collection: false | |
tools: false | |
reader: false | |
readerAnnotation: false | |
1710769848631-0F2mzqBj: | |
event: 0 | |
operation: 4 | |
data: "/**\n * QuickCopy items\n * @author Zotero Community\n * @usage Copy selected items to the clipboard\n * @link https://github.com/windingwind/zotero-actions-tags/discussions/165\n * @see https://github.com/windingwind/zotero-actions-tags/discussions/165\n */\nif (items?.length === 0 || item) {\n\treturn;\n}\n\nconst Zotero = require(\"Zotero\");\nconst ZoteroPane = require(\"ZoteroPane\");\n\nconst pref = 'export.quickCopy.setting';\nconst origSetting = Zotero.Prefs.get(pref);\n\n/**\n * Replace this line with your own setting\n * Steps:\n * 1. Change Settings -> Export -> Quick Copy -> Item Format\n * 2. Open Settings -> Advanced -> Config Editor\n * 3. Search for `export.quickCopy.setting`.\n * 4. Paste the value and replace the string `bibliography/html=http://www.zotero.org/styles/acm-siggraph` below.\n * 5. Reset Settings -> Export -> Quick Copy -> Item Format (If necessary)\n */\nconst newSetting = \"export=f895aa0d-f28e-47fe-b247-2ea77c6ed583\";\n\nZotero.Prefs.set(pref, newSetting);\nZoteroPane.copySelectedItemsToClipboard(false);\nZotero.Prefs.set(pref, origSetting);\nreturn `QuickCopy done`;" | |
shortcut: ⇧,⌃,L | |
enabled: true | |
menu: Quick copy BibLaTeX entry | |
name: Quick copy BibLaTeX entry | |
showInMenu: | |
item: true | |
collection: false | |
tools: false | |
reader: false | |
readerAnnotation: false | |
1708208087533-0F2mzqBj: | |
event: 0 | |
operation: 4 | |
data: "/**\n * QuickCopy items\n * @author Zotero Community\n * @usage Copy selected items to the clipboard\n * @link https://github.com/windingwind/zotero-actions-tags/discussions/165\n * @see https://github.com/windingwind/zotero-actions-tags/discussions/165\n */\nif (items?.length === 0 || item) {\n\treturn;\n}\n\nconst Zotero = require(\"Zotero\");\nconst ZoteroPane = require(\"ZoteroPane\");\n\nconst pref = 'export.quickCopy.setting';\nconst origSetting = Zotero.Prefs.get(pref);\n\n/**\n * Replace this line with your own setting\n * Steps:\n * 1. Change Settings -> Export -> Quick Copy -> Item Format\n * 2. Open Settings -> Advanced -> Config Editor\n * 3. Search for `export.quickCopy.setting`.\n * 4. Paste the value and replace the string `bibliography/html=http://www.zotero.org/styles/acm-siggraph` below.\n * 5. Reset Settings -> Export -> Quick Copy -> Item Format (If necessary)\n */\nconst newSetting = \"export=a515a220-6fef-45ea-9842-8025dfebcc8f\";\n\nZotero.Prefs.set(pref, newSetting);\nZoteroPane.copySelectedItemsToClipboard(false);\nZotero.Prefs.set(pref, origSetting);\nreturn `QuickCopy done`;" | |
shortcut: '' | |
enabled: true | |
menu: Quick copy BibLaTeX citation | |
name: Quick copy BibLaTeX citation | |
showInMenu: | |
item: true | |
collection: false | |
tools: false | |
reader: false | |
readerAnnotation: false | |
1707921394782-0F2mzqBj: | |
event: 0 | |
operation: 4 | |
data: > | |
// Paste tags | |
// Codes from Zutilo. | |
// 从剪贴板获取tags | |
var clipboardText = | |
Zotero.Utilities.Internal.getClipboard("text/plain").trim() | |
if (!clipboardText) { | |
return false; | |
} | |
// 拆分 | |
var tagArray = clipboardText.split(/\r\n?|\n/) | |
tagArray = tagArray.map(function (val) { return val.trim() }); | |
tagArray = tagArray.filter(Boolean) | |
// 添加tags | |
var items = Zotero.getActiveZoteroPane().getSelectedItems(); | |
for (let item of items) { | |
if (item.isRegularItem() && !(item instanceof Zotero.Collection)) { | |
for (let tag of tagArray) { | |
item.addTag(tag) | |
} | |
item.saveTx() | |
} | |
} | |
return "Tags pasted." | |
shortcut: ⇧,⌃,v | |
enabled: true | |
menu: Paste tags | |
name: Paste tags | |
showInMenu: | |
item: false | |
collection: false | |
tools: false | |
reader: false | |
readerAnnotation: false | |
1708811994533-0F2mzqBj: | |
event: 2 | |
operation: 1 | |
data: opened | |
shortcut: '' | |
enabled: false | |
menu: '' | |
name: Opened | |
showInMenu: | |
item: false | |
collection: false | |
tools: false | |
reader: false | |
readerAnnotation: false | |
1708357331797-0F2mzqBj: | |
event: 0 | |
operation: 4 | |
data: "if(item) return;\n\nconst Zotero = require(\"Zotero\");\nconst window = require(\"window\");\nconst Zotero_Tabs = require(\"Zotero_Tabs\");\n\nasync function getPDFAttachmentPath(item) {\n if (item.isAttachment() && item.attachmentContentType === 'application/pdf') {\n return await item.getFilePathAsync();\n }\n else if (item.isRegularItem() && !item.isAttachment()) {\n let attachments = await item.getAttachments();\n for (let attachmentID of attachments) {\n let attachment = await Zotero.Items.getAsync(attachmentID);\n if (attachment.attachmentContentType === 'application/pdf') {\n return await attachment.getFilePathAsync();\n }\n }\n }\n return null;\n}\n\nasync function openPDF(item) {\n let filePath = await getPDFAttachmentPath(item);\n if (!filePath) {\n Zotero.alert(window, \"Failed to open.\", \"PDF attachment not found.\");\n return \"PDF attachment not found.\";\n }\n\tlet args = [filePath, '-a', \"/Applications/Skim.app\"];\n\tlet\tapplicationPath = '/usr/bin/open';\n\tZotero.Utilities.Internal.exec(applicationPath, args);\n}\n\nif (Zotero_Tabs._selectedID !== 'zotero-pane') {\n\tlet item = Zotero.Items.get(Zotero.Reader.getByTabID(Zotero_Tabs._selectedID).itemID);\n\treturn await openPDF(item);\n}\n\nreturn await openPDF(items[0]);" | |
shortcut: ⌘,o | |
enabled: true | |
menu: Open with Skim | |
name: Open with Skim | |
showInMenu: | |
item: false | |
collection: false | |
tools: false | |
reader: false | |
readerAnnotation: false | |
1708293083187-0F2mzqBj: | |
event: 0 | |
operation: 4 | |
data: "if(item) return;\n\nconst window = require(\"window\");\nconst Zotero_Tabs = require(\"Zotero_Tabs\");\n\nasync function getPDFAttachmentPath(item) {\n if (item.isAttachment() && item.attachmentContentType === 'application/pdf') {\n return await item.getFilePathAsync();\n }\n else if (item.isRegularItem() && !item.isAttachment()) {\n let attachments = await item.getAttachments();\n for (let attachmentID of attachments) {\n let attachment = await Zotero.Items.getAsync(attachmentID);\n if (attachment.attachmentContentType === 'application/pdf') {\n return await attachment.getFilePathAsync();\n }\n }\n }\n return null;\n}\n\nasync function openPDF(item) {\n let filePath = await getPDFAttachmentPath(item);\n if (!filePath) {\n Zotero.alert(window, \"Failed to open.\", \"PDF attachment not found.\");\n return \"PDF attachment not found.\";\n }\n\tlet args = [filePath, '-a', \"/Applications/Adobe\\ Acrobat\\ Reader.app\"];\n\tlet\tapplicationPath = '/usr/bin/open';\n\tZotero.Utilities.Internal.exec(applicationPath, args);\n}\n\nif (Zotero_Tabs._selectedID !== 'zotero-pane') {\n\tlet item = Zotero.Items.get(Zotero.Reader.getByTabID(Zotero_Tabs._selectedID).itemID);\n\treturn await openPDF(item);\n}\n\nreturn await openPDF(items[0]);" | |
shortcut: ⌘,b | |
enabled: true | |
menu: Open with Adobe Reader | |
name: Open with Adobe Reader | |
showInMenu: | |
item: false | |
collection: false | |
tools: false | |
reader: false | |
readerAnnotation: false | |
1707921136649-0F2mzqBj: | |
event: 0 | |
operation: 4 | |
data: |- | |
// Copy tags. | |
// Codes from Zutilo. | |
// 获取条目tags,并存入剪贴板 | |
var tagsArray = []; | |
var items = Zotero.getActiveZoteroPane().getSelectedItems(); | |
for (let item of items) { | |
if (item.isRegularItem() && !(item instanceof Zotero.Collection)) { | |
var tempTags = item.getTags(); | |
var arrayStr = ''; | |
for (var j = 0; j < tempTags.length; j++) { | |
arrayStr = '\n' + tagsArray.join('\n') + '\n'; | |
let tag | |
tag = tempTags[j].tag | |
if (arrayStr.indexOf('\n' + tag + '\n') == -1) { | |
tagsArray.push(tag); | |
} | |
} | |
} | |
} | |
var clipboardText = tagsArray.join('\r\n'); | |
Zotero.Utilities.Internal.copyTextToClipboard(clipboardText); | |
return "Tags copied." | |
shortcut: ⇧,⌃,t | |
enabled: true | |
menu: Copy tags | |
name: Copy tags | |
showInMenu: | |
item: false | |
collection: false | |
tools: false | |
reader: false | |
readerAnnotation: false | |
default0: | |
event: 1 | |
operation: 1 | |
data: /unread | |
shortcut: '' | |
enabled: false | |
menu: '' | |
name: Add Unread When Create Item | |
showInMenu: | |
item: true | |
collection: true | |
tools: true | |
reader: true | |
readerAnnotation: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Script for https://github.com/windingwind/zotero-actions-tags
Provides functions for Zotero 7 equivalent to those in Zotero QuickLook, Zutilo, and more.