kb:intranet:software:zotero:start
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
kb:intranet:software:zotero:start [4 weeks ago (11 February 2025)] – [Scripts] justin | kb:intranet:software:zotero:start [4 weeks ago (11 February 2025)] (current) – [Scripts] justin | ||
---|---|---|---|
Line 66: | Line 66: | ||
Action script for Zotero link (Copy link, Ctrl+Shift+C shortcut): | Action script for Zotero link (Copy link, Ctrl+Shift+C shortcut): | ||
+ | |||
+ | ++++ Copy | | ||
<code javascript> | <code javascript> | ||
Line 142: | Line 144: | ||
// Get the link text using the `link_text_field` argument | // Get the link text using the `link_text_field` argument | ||
let linkText; | let linkText; | ||
+ | |||
+ | let _firstAuthor, | ||
if (collection) { | if (collection) { | ||
// When `collection` is truthy, this script was triggered in the collection menu. | // When `collection` is truthy, this script was triggered in the collection menu. | ||
// Use collection name if this is a collection link | // Use collection name if this is a collection link | ||
linkText = collection.name; | linkText = collection.name; | ||
- | } else if (item.isAttachment()) { | ||
- | // Try to use top-level item for link text | ||
- | linkText = Zotero.Items.getTopLevel([item])[0].getField(linkTextField); | ||
} else if (item.isAnnotation()) { | } else if (item.isAnnotation()) { | ||
// Add the annotation text to the link text | // Add the annotation text to the link text | ||
Line 155: | Line 156: | ||
})`; | })`; | ||
} else { | } else { | ||
- | // Use the item's field | + | // Desired format: |
- | | + | // [Zhang15](([[zotero:// |
+ | // Reference schema: https:// | ||
+ | // Inspired by: https:// | ||
+ | _item = item // Parent items fall under here | ||
+ | | ||
+ | // Try to use top-level item for link text | ||
+ | _item = Zotero.Items.getTopLevel([item])[0] | ||
+ | } | ||
+ | // Retrieve first and last authors | ||
+ | let _creators = _item.getCreators(); | ||
+ | _firstAuthor = _creators[0].lastName; | ||
+ | _year = _item.getField(" | ||
+ | |||
+ | // Prepare full link text | ||
+ | _authors = _firstAuthor; | ||
+ | if (_creators.length > 1) { | ||
+ | _authors += ", " + _creators[_creators.length-1].lastName; | ||
+ | } | ||
+ | _title = _item.getField(" | ||
+ | _journal = _item.getField(" | ||
+ | _volume = _item.getField(" | ||
+ | _issue = _item.getField(" | ||
+ | _pages = _item.getField(" | ||
+ | _fullYear = _item.getField(" | ||
+ | |||
+ | linkText = _title; | ||
} | } | ||
- | |||
// Add the library or group URI part (collection must go first) | // Add the library or group URI part (collection must go first) | ||
let libraryType = (collection || item).library.libraryType; | let libraryType = (collection || item).library.libraryType; | ||
Line 185: | Line 210: | ||
uriParts.push(`items/ | uriParts.push(`items/ | ||
} | } | ||
- | + | ||
// Join the parts together | // Join the parts together | ||
let uri = uriParts.join("/" | let uri = uriParts.join("/" | ||
Line 203: | Line 228: | ||
clipboard.addText(`< | clipboard.addText(`< | ||
} else if (linkType == " | } else if (linkType == " | ||
- | clipboard.addText(`[[${uri}|${linkText}]]`, " | + | |
+ | + _authors + ", " + _journal + " " + _volume + " | ||
+ | // _fullText = " | ||
+ | // + _authors + ", " + _journal + " " + _volume + " | ||
+ | clipboard.addText(_fullText, " | ||
} else if (linkType == " | } else if (linkType == " | ||
clipboard.addText(`[${linkText}](${uri})`, | clipboard.addText(`[${linkText}](${uri})`, | ||
Line 214: | Line 243: | ||
return `[Copy Zotero Link] link ${uri} copied.`; | return `[Copy Zotero Link] link ${uri} copied.`; | ||
</ | </ | ||
+ | |||
+ | ++++ | ||
Useful place to get Zotero Javascript API: https:// | Useful place to get Zotero Javascript API: https:// |
kb/intranet/software/zotero/start.txt · Last modified: 4 weeks ago (11 February 2025) by justin