View Online: Prioritize DOI over attachment URL (#4714)

And lint and remove no-op ifs.
This commit is contained in:
Abe Jellinek 2024-10-01 01:56:19 -04:00 committed by GitHub
parent a4225592a1
commit 5ff35c896c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -498,36 +498,38 @@ var Zotero_LocateMenu = new function() {
var _getURL = Zotero.Promise.coroutine(function* (item) {
// try url field for item and for attachments
var urlField = item.getField('url');
if(urlField) {
var itemURL = item.getField('url');
if (itemURL) {
var uri;
try {
uri = Zotero_LocateMenu.ios.newURI(urlField, null, null);
if(uri && uri.host && uri.scheme !== 'file') return urlField;
} catch(e) {};
}
if(item.isRegularItem()) {
var attachments = item.getAttachments();
if(attachments) {
// look through url fields for non-file:/// attachments
for (let attachment of Zotero.Items.get(attachments)) {
var urlField = attachment.getField('url');
if(urlField) return urlField;
uri = Zotero_LocateMenu.ios.newURI(itemURL, null, null);
if (uri && uri.host && uri.scheme !== 'file') {
return itemURL;
}
}
catch (e) {
}
}
// if no url field, try DOI field
var doi = item.getField('DOI');
if(doi && typeof doi === "string") {
if (doi) {
doi = Zotero.Utilities.cleanDOI(doi);
if(doi) {
if (doi) {
return "https://doi.org/" + encodeURIComponent(doi);
}
}
// Try attachment url fields
if (item.isRegularItem()) {
for (let attachment of Zotero.Items.get(item.getAttachments())) {
let attachmentURL = attachment.getField('url');
if (attachmentURL) {
return attachmentURL;
}
}
}
return false;
});
};