Last active
March 26, 2024 09:56
-
-
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.68+c31a40c74 | |
pluginVersion: 1.0.0-beta.35 | |
timestamp: '2024-03-26T09:55:19.478Z' | |
actions: | |
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 | |
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.isCollection()) { | |
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'); | |
copyToClipboard(clipboardText) | |
return "Tags copied." | |
// 复制到剪贴板函数 | |
function copyToClipboard(clipboardText) { | |
var document = require('window').document; // Zotero Actions & Tags需要 | |
if (clipboardText) { | |
const gClipboardHelper = | |
Components.classes['@mozilla.org/widget/clipboardhelper;1'] | |
.getService(Components.interfaces.nsIClipboardHelper); | |
gClipboardHelper.copyString(clipboardText, document); | |
} else { | |
var prompts = Components. | |
classes['@mozilla.org/embedcomp/prompt-service;1']. | |
getService(Components.interfaces.nsIPromptService); | |
var title = 'Invalid copy selection'; | |
var text = 'No valid items selected for copying. The clipboard has not been modified.'; | |
prompts.alert(null, title, text) | |
} | |
} | |
shortcut: ⇧,⌃,t | |
enabled: true | |
menu: Copy tags | |
name: Copy tags | |
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: true | |
collection: false | |
tools: false | |
reader: true | |
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: true | |
collection: false | |
tools: false | |
reader: true | |
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 | |
1707921394782-0F2mzqBj: | |
event: 0 | |
operation: 4 | |
data: | | |
// Paste tags | |
// Codes from Zutilo. | |
// 从剪贴板获取tags | |
var clipboardText = getFromClipboard().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.isCollection()) { | |
for (let tag of tagArray) { | |
item.addTag(tag) | |
} | |
item.saveTx() | |
} | |
} | |
return "Tags pasted." | |
// 从剪贴板获取数据函数 | |
function getFromClipboard(silent) { | |
var trans = Components.classes['@mozilla.org/widget/transferable;1']. | |
createInstance(Components.interfaces.nsITransferable); | |
// if ('init' in trans) { | |
// trans.init(window.QueryInterface(Ci.nsIInterfaceRequestor). | |
// getInterface(Ci.nsIWebNavigation)); | |
// } | |
trans.addDataFlavor('text/unicode'); | |
Services.clipboard.getData(trans, Services.clipboard.kGlobalClipboard); | |
var str = {} | |
var strLength = {} | |
try { | |
trans.getTransferData('text/unicode', str, strLength); | |
} catch (err) { | |
if (!silent) { | |
var prompts = Cc['@mozilla.org/embedcomp/prompt-service;1']. | |
getService(Components.interfaces.nsIPromptService); | |
prompts.alert( | |
null, | |
'clipboard error', | |
'attempted to copy text from the clipboard, but no valid text was found.' | |
) | |
} | |
return ''; | |
} | |
var pasteText | |
if (str) { | |
pasteText = str.value. | |
QueryInterface(Components.interfaces.nsISupportsString).data; | |
} else { | |
pasteText = ''; | |
} | |
return pasteText; | |
}; | |
shortcut: ⇧,⌃,v | |
enabled: true | |
menu: Paste tags | |
name: Paste tags | |
showInMenu: | |
item: false | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 |
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.