{
"translatorID": "3f50f41c-0a07-49f7-af14-7fcf2ed5887a",
"translatorType": 4,
"label": "Library Catalog (TIND ILS)",
"creator": "Abe Jellinek",
"target": "/search.+p=|record/[0-9]+",
"minVersion": "3.0",
"maxVersion": null,
"priority": 260,
"inRepository": true,
"browserSupport": "gcsibv",
"lastUpdated": "2025-06-03 18:55:00"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2021 Abe Jellinek
This file is part of Zotero.
Zotero is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zotero is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Zotero. If not, see .
***** END LICENSE BLOCK *****
*/
/**
* @type {Map}
*/
const SCHEMA_ORG_TO_ZOTERO = new Map([
["Thing", "document"],
["CreativeWork", "document"],
["Article", "journalArticle"],
["ScholarlyArticle", "journalArticle"],
["Report", "report"],
["Thesis", "thesis"],
["Manuscript", "manuscript"],
["Dataset", "dataset"],
]);
/**
* @param {Document} doc The page document
*/
function detectWeb(doc, url) {
if (!doc.querySelector("#tind-shibboleth")) {
return false;
}
if (url.includes('/record/')) {
const schemaOrg = getSchemaOrg(doc);
if (schemaOrg) {
const zoteroType = getZoteroTypeFromSchemaOrg(schemaOrg);
if (zoteroType) {
return zoteroType;
}
}
return "book";
}
else if (getSearchResults(doc, true)) {
return "multiple";
}
else if (url.includes('/search')) {
Z.monitorDOMChanges(doc.querySelector('.pagebody'), {});
}
return false;
}
function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
var rows = doc.querySelectorAll('.result-title a');
for (let row of rows) {
let href = row.href;
let title = ZU.trimInternal(row.textContent);
if (!href || !title) continue;
if (checkOnly) return true;
found = true;
items[href] = title;
}
return found ? items : false;
}
async function doWeb(doc, url) {
if (detectWeb(doc, url) == 'multiple') {
let items = await Zotero.selectItems(getSearchResults(doc, false));
if (!items) return;
for (let url of Object.keys(items)) {
await scrape(await requestDocument(url));
}
}
else {
await scrape(doc);
}
}
/**
*
* @param {Document} doc The page document
*/
async function scrape(doc) {
let translator = Zotero.loadTranslator("import");
// MARCXML
translator.setTranslator("edd87d07-9194-42f8-b2ad-997c4c7deefd");
const schemaOrg = getSchemaOrg(doc);
let marcXMLURL = attr(doc, 'a[href$="/export/xm"], a[download$=".xml"]', 'href');
if (!marcXMLURL) marcXMLURL = attr(doc, 'form[action$="/export/xm"]', 'action');
if (!marcXMLURL) {
throw new Error('Unable to find MARCXML URL');
}
let xml = new DOMParser().parseFromString(await requestText(marcXMLURL), "text/xml");
let marcxml = await translator.getTranslatorObject();
let fileInformation = await getFileInformation(doc);
for (let record of await marcxml.parseDocument(xml)) {
let item = new Zotero.Item();
// Set the right item type if schemaorg exists
if (schemaOrg) {
enrichItemWithSchemaOrgItemType(item, schemaOrg);
}
record.translate(item);
//// Enhance the item with TIND-specific information
// Catalog name
item.libraryCatalog = text(doc, '#headerlogo')
|| attr(doc, 'meta[property="og:site_name"]', 'content');
// URL
item.url = attr(doc, 'meta[property="og:url"]', 'content') || item.url;
// Attachments
if (fileInformation) {
enrichItemWithAttachments(item, fileInformation);
}
// Tind-specific date field 269. Assume there's only one.
let tindDate = record.getFieldSubfields("269")[0];
if (tindDate && tindDate.a && !item.date) {
// Assign the date if it doesn't already exist.
item.date = tindDate.a;
}
if (item.abstractNote === 'No abstract') {
delete item.abstractNote;
}
item.complete();
}
}
/**
* @param {Document} doc The page document
* @returns {?Promise>} The file information object
*/
async function getFileInformation(doc) {
let fileApiArgs;
try {
fileApiArgs = JSON.parse(text(doc, "#detailed-file-api-args"));
}
catch (e) {
return null;
}
// eslint camelcase is disabled because the API requires snake case.
let urlParams = new URLSearchParams({
recid: fileApiArgs.recid,
file_types: fileApiArgs.file_types, // eslint-disable-line camelcase
hidden_types: fileApiArgs.hidden_types, // eslint-disable-line camelcase
ln: fileApiArgs.ln,
hr: fileApiArgs.hr,
hide_transcripts: fileApiArgs.hide_transcripts, // eslint-disable-line camelcase
});
try {
return await requestJSON(`/api/v1/file?${urlParams}`);
}
catch (e) {
Zotero.debug(e);
return null;
}
}
/**
* @param {Z.Item} item The Zotero item
* @param {Array