Closed calmwaves111 closed 11 months ago
copyZoteroSelectLink: function() {
var zitems = this.getSelectedItems();
var links = [];
if (!this.checkItemNumber(zitems, 'regularNoteAttachment1')) {
return false;
}
var libraryType
var path
var nowtitle = item.getFields('title');
for (var ii = 0; ii < zitems.length; ii++) {
libraryType = Zotero.Libraries.get(zitems[ii].libraryID).libraryType
switch (libraryType) {
case 'group':
path = Zotero.URI.getLibraryPath(zitems[ii].libraryID)
break;
case 'user':
path = 'library'
break;
default:
// Feeds?
continue
}
links.push('[' +nowtitle+ ']' + '(zotero://select/' + path + '/items/'+ zitems[ii].key + ')')
}
var clipboardText = links.join('\r\n');
this._copyToClipboard(clipboardText)
return true;
},
I just add two line of code like this: var nowtitle = item.getFields('title'); links.push('[' +nowtitle+ ']' + '(zotero://select/' + path + '/items/'+ zitems[ii].key + ')')
however,I cannot return the correct title of an item,it doesnot work,I don't know where I went wrong
You tried to adapt this Zutilo function. A more general version of such a function could be nice.
This code should work in Zotero's JavaScript API. Open "Tools" -> "Developer" -> "Run JavaScript" and paste in and run this code:
function copyZoteroSelectLink() {
var zitems = ZutiloChrome.zoteroOverlay.getSelectedItems();
var links = [];
if (!ZutiloChrome.zoteroOverlay.checkItemNumber(zitems, 'regularNoteAttachment1')) {
return false;
}
var libraryType
var path
for (var ii = 0; ii < zitems.length; ii++) {
libraryType = Zotero.Libraries.get(zitems[ii].libraryID).libraryType
switch (libraryType) {
case 'group':
path = Zotero.URI.getLibraryPath(zitems[ii].libraryID)
break;
case 'user':
path = 'library'
break;
default:
// Feeds?
continue
}
let title = zitems[ii].getField('title');
links.push('[' + title + ']' + '(zotero://select/' + path + '/items/'+ zitems[ii].key + ')')
}
var clipboardText = links.join('\r\n');
ZutiloChrome.zoteroOverlay._copyToClipboard(clipboardText)
return true;
}
copyZoteroSelectLink();
BTW, I've been using this code to copy zotero://select links of the form discussed in #105. It produces links in HTML format that are clickable if pasted to a Zotero note. Unfortunately, it's currently not possible to run such scripts with a shortcut, see #171. However, note that there's a Zutilo shortcut for opening the "Run JavaScript" window.
For such Markdown links, it should also be possible to write an export translator that does the same. See #129 and the related DOI export translator for an example. The advantage would be that it'd be easy to modify if your workflow evolves. You can set a Zutilo shortcut for exporting with that translator using the Quick Copy function.
Issue #182 is a request that is somewhat related.
first,thank for your reply,This really gives me great encouragement,Actually, I've given up,and before I've used Similar to your code in the in "zutilo zoteroOverlay.js",but it can't work well.so i try work in JavaScript API like you,it can work well. second, i try to copy your code and modify in "zutilo zoteroOverlay.js" as follows,and when i install the modified xpi, "zotilo preferences" can't appear in "Tools",I know something must have gone wrong.
copyZoteroSelectLink: function() {
var zitems = this.getSelectedItems();
var links = [];
if (!this.checkItemNumber(zitems, 'regularNoteAttachment1')) {
return false;
}
var libraryType
var path
for (var ii = 0; ii < zitems.length; ii++) {
libraryType = Zotero.Libraries.get(zitems[ii].libraryID).libraryType
switch (libraryType) {
case 'group':
path = Zotero.URI.getLibraryPath(zitems[ii].libraryID)
break;
case 'user':
path = 'library'
break;
default:
// Feeds?
continue
}
let title = zitems[ii].getField('title');
links.push('[' + title + ']' + '(zotero://select/' + path + '/items/'+ zitems[ii].key + ')')
}
and then,I noticed that defining the variable “path”,no semicolon“;",so i remove the semicolon of this line "let title = zitems[ii].getField('title');",Something magical happened, It can work normally. infact,i don't learn about JavaScript,i just learned a little about other programming languages such as C and matlab,so i don’t why,But at present,it work well after removing the semicolon. Thank you again for your help,As for the others you mentioned, In fact, I can't understand it,I'm sorry that I don't study programming deeply.
btw,for html link,it maybe modify in the same way.and zotero Update to 6.0,it support markdown link that is also clickable,although the current markdown rendering has a lot of problems.
in addition,i guess you want these features in orde to add references to your notes,if a normal item, you can open the note "Edit in a Separate Window",and drag item to the note window,it can add a zotero citation
Export translator
For such Markdown links, it should also be possible to write an export translator that does the same. See #129 and the related DOI export translator for an example. The advantage would be that it'd be easy to modify if your workflow evolves. You can set a Zutilo shortcut for exporting with that translator using the Quick Copy function.
Here's one example: https://github.com/silentdot/zotero-markdown-translator
now,zutilo “copy select item links”,i can get“zotero://select/library/items/YNIIS8LA” and i hope,"[title](zotero://select/library/items/YNIIS8LA",like markdown link