Repository

Looks good to me!

User Tools

Site Tools


kb:intranet:software:zotero:start

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
kb:intranet:software:zotero:start [4 weeks ago (11 February 2025)] – [Scripts] justinkb: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, _year, _authors, _title, _journal, _volume, _issue, _pages, _fullYear;
 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: 
-  linkText = item.getField(linkTextField);+  // [Zhang15](([[zotero://select/library/items/2T8SAZ3T|Zhang, Pan, Light Sci Appl 4, e286-e286 (2015)]]: Advances in ...)) 
 +  // Reference schema: https://github.com/zotero/zotero-schema/blob/master/schema.json 
 +  // Inspired by: https://github.com/windingwind/zotero-better-notes/discussions/225 
 +  _item = item  // Parent items fall under here 
 +  if (item.isAttachment()) {  // PDFs 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;  // assumed to exist 
 +  _year = _item.getField("year").slice(-2); 
 + 
 +  // Prepare full link text 
 +  _authors = _firstAuthor; 
 +  if (_creators.length > 1) { 
 +    _authors += ", " + _creators[_creators.length-1].lastName;  // get last author 
 +  } 
 +  _title = _item.getField("title"); 
 +  _journal = _item.getField("journalAbbreviation"); 
 +  _volume = _item.getField("volume"); 
 +  _issue = _item.getField("issue"); 
 +  _pages = _item.getField("pages"); 
 +  _fullYear = _item.getField("year"); 
 + 
 +  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/${targetItem.key}`);   uriParts.push(`items/${targetItem.key}`);
 } }
- +
 // Join the parts together // Join the parts together
 let uri = uriParts.join("/"); let uri = uriParts.join("/");
Line 203: Line 228:
   clipboard.addText(`<a href="${uri}">${linkText}</a>`, "text/unicode");   clipboard.addText(`<a href="${uri}">${linkText}</a>`, "text/unicode");
 } else if (linkType == "dokuwiki") { } else if (linkType == "dokuwiki") {
-  clipboard.addText(`[[${uri}|${linkText}]]`, "text/unicode");+   _fullText = "["+_firstAuthor+_year+"](([[zotero>"+uri+"|
 +    + _authors + ", " + _journal + " " + _volume + "(" + _issue + "), " + _pages + " (" + _fullYear + ")]]: "+_title+"))"; 
 +  // _fullText = "[[zotero>"+uri+"|["+_firstAuthor+_year+"] ]]((" 
 +  //   + _authors + ", " + _journal + " " + _volume + "(" + _issue + "), " + _pages + " (" + _fullYear + "): "+_title+"))"; 
 +  clipboard.addText(_fullText, "text/unicode");
 } else if (linkType == "md") { } else if (linkType == "md") {
   clipboard.addText(`[${linkText}](${uri})`, "text/unicode");   clipboard.addText(`[${linkText}](${uri})`, "text/unicode");
Line 214: Line 243:
 return `[Copy Zotero Link] link ${uri} copied.`; return `[Copy Zotero Link] link ${uri} copied.`;
 </code> </code>
 +
 +++++
  
 Useful place to get Zotero Javascript API: https://github.com/zotero/zotero/tree/main/chrome/content/zotero/xpcom/data Useful place to get Zotero Javascript API: https://github.com/zotero/zotero/tree/main/chrome/content/zotero/xpcom/data
kb/intranet/software/zotero/start.txt · Last modified: 4 weeks ago (11 February 2025) by justin