From a85b22fd1cfb7c0d1438281e424d191a488b72df Mon Sep 17 00:00:00 2001 From: franklindyer Date: Tue, 9 Jan 2024 20:18:05 -0700 Subject: [PATCH 01/10] basic implementation of TinREAD translator based on exportable MARCXML file --- TinREAD.js | 276 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 276 insertions(+) create mode 100644 TinREAD.js diff --git a/TinREAD.js b/TinREAD.js new file mode 100644 index 0000000000..ce389f8d51 --- /dev/null +++ b/TinREAD.js @@ -0,0 +1,276 @@ +{ + "translatorID": "78835a5b-3378-49c2-a94f-3422aab0e949", + "label": "TinREAD", + "creator": "Franklin Pezzuti Dyer", + "target": "^https?://.+/opac/bibliographic_view", + "minVersion": "5.0", + "maxVersion": "", + "priority": 100, + "inRepository": true, + "translatorType": 4, + "browserSupport": "gcsibv", + "lastUpdated": "2024-01-10 03:17:33" +} + +/* + ***** BEGIN LICENSE BLOCK ***** + + Copyright © 2024 Franklin Pezzuti Dyer + + 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 ***** +*/ + +const ICON_DETECT_MAPPING = { + "s_book.gif": "journalArticle", + "s_e_resource.gif": "journalArticle", + "book.gif": "book" +} + +function detectWeb(doc, url) { + // Rather than parsing text in two different languages, we are using the icon + let typeIcon = doc.getElementsByClassName("crs_recordtype_icon")[0].src; + for (iname in ICON_DETECT_MAPPING) { + if (typeIcon.includes(iname)) { + return ICON_DETECT_MAPPING[iname]; + } + } + return false; +} + +function getSearchResults(doc, checkOnly) { + var items = {}; + var found = false; + var rows = doc.querySelectorAll('li.reslt_item_head > a[name="book_link"]'); + 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, url); + } +} + +async function scrape(doc, url = doc.location.href) { + doc.getElementById("DirectLink").click(); + await new Promise(resolve => setTimeout(resolve, 2000)); + + let exportButton = doc.getElementById("exportBibs"); + let marcUrl = exportButton.href; + + ZU.doGet(marcUrl, function(result) { + var translator = Zotero.loadTranslator("import"); + translator.setTranslator("edd87d07-9194-42f8-b2ad-997c4c7deefd"); + translator.setString(result); + translator.setHandler("itemDone", function (obj, item) { + finalize(doc, item); + item.complete(); + }); + translator.translate(); + }); +} + +async function finalize(doc, item) { + +}/** BEGIN TEST CASES **/ +var testCases = [ + { + "type": "web", + "url": "https://opac.biblioteca.ase.ro/opac/bibliographic_view/144193?pn=opac%2FSearch&q=gheorghe+carstea#level=all&location=0&ob=asc&q=gheorghe+carstea&sb=relevance&start=0&view=CONTENT", + "detectedItemType": "book", + "items": [ + { + "itemType": "book", + "title": "Managementul achizitiilor publice", + "creators": [ + { + "firstName": "Gheorghe", + "lastName": "Carstea", + "creatorType": "author" + }, + { + "firstName": "Monica Viorica", + "lastName": "Nedelcu", + "creatorType": "author" + } + ], + "date": "2002", + "ISBN": "9789735941130", + "callNumber": "352.5", + "libraryCatalog": "TinREAD", + "numPages": "165", + "place": "Bucuresti", + "publisher": "Editura ASE", + "attachments": [], + "tags": [ + { + "tag": "achizitii" + }, + { + "tag": "administratie publica" + }, + { + "tag": "cursuri multigrafiate" + }, + { + "tag": "guvern" + }, + { + "tag": "licitatii" + }, + { + "tag": "management" + }, + { + "tag": "sector public" + } + ], + "notes": [ + { + "note": "CZU 35.073.511 ; 65.012.4 ; 075.8" + } + ], + "seeAlso": [] + } + ] + }, + { + "type": "web", + "url": "https://tinread.biblioteca.ct.ro/opac/bibliographic_view/238969?pn=opac/Search&q=educatie+fizica#level=all&location=0&ob=asc&q=educatie+fizica&sb=relevance&start=0&view=CONTENT", + "detectedItemType": "book", + "items": [ + { + "itemType": "book", + "title": "Cursus. Educaţie fizică", + "creators": [], + "language": "rum", + "libraryCatalog": "TinREAD", + "attachments": [], + "tags": [], + "notes": [], + "seeAlso": [] + }, + { + "itemType": "book", + "title": "Metodica predării educaţiei fizice şi sportului", + "creators": [ + { + "firstName": "Elena", + "lastName": "Lupu", + "creatorType": "author" + } + ], + "date": "2006", + "ISBN": "9789736114366", + "callNumber": "796(075.8)", + "language": "rum", + "libraryCatalog": "TinREAD", + "place": "Iaşi", + "publisher": "Institutul European", + "series": "Cursus. Educaţie fizică", + "seriesNumber": "18", + "attachments": [], + "tags": [], + "notes": [], + "seeAlso": [] + } + ] + }, + { + "type": "web", + "url": "https://catalog.ucv.ro/opac/bibliographic_view/68938?pn=opac/Search&q=educatie+fizica#level=all&location=0&ob=asc&q=educatie+fizica&sb=relevance&start=0&view=CONTENT", + "detectedItemType": "book", + "items": [ + { + "itemType": "book", + "title": "Lecţia de educaţie fizică", + "creators": [ + { + "firstName": "Emil", + "lastName": "Ghibu", + "creatorType": "author" + } + ], + "date": "1957", + "callNumber": "796:371.3", + "language": "rum", + "libraryCatalog": "TinREAD", + "place": "Bucureşti", + "publisher": "Editura Tineretului", + "attachments": [], + "tags": [], + "notes": [], + "seeAlso": [] + } + ] + }, + { + "type": "web", + "url": "https://tinread.upit.ro/opac/bibliographic_view/37902?pn=opac/Search&q=metodica+educatie+fizica#level=all&location=0&ob=asc&q=metodica+educatie+fizica&sb=relevance&start=0&view=CONTENT", + "detectedItemType": "book", + "items": [ + { + "itemType": "book", + "title": "Metodica dezvoltării calităţilor fizice", + "creators": [ + { + "firstName": "Corneliu", + "lastName": "Florescu", + "creatorType": "author" + }, + { + "firstName": "Vasile", + "lastName": "Dumitrescu", + "creatorType": "author" + }, + { + "firstName": "Aurel", + "lastName": "Predescu", + "creatorType": "author" + } + ], + "date": "1969", + "callNumber": "796", + "edition": "Ediţia a II-a revăzută", + "language": "rum", + "libraryCatalog": "TinREAD", + "place": "Bucureşti", + "publisher": "Editura Consiliului Naţional pentru Educaţie Fizică şi Sport", + "attachments": [], + "tags": [], + "notes": [], + "seeAlso": [] + } + ] + } +] +/** END TEST CASES **/ From 9ebeab5ed147aad0c26d80f81a38d8ee78fd368f Mon Sep 17 00:00:00 2001 From: franklindyer Date: Tue, 9 Jan 2024 20:27:54 -0700 Subject: [PATCH 02/10] fixed minor linter issues --- TinREAD.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/TinREAD.js b/TinREAD.js index ce389f8d51..81f455c014 100644 --- a/TinREAD.js +++ b/TinREAD.js @@ -9,7 +9,7 @@ "inRepository": true, "translatorType": 4, "browserSupport": "gcsibv", - "lastUpdated": "2024-01-10 03:17:33" + "lastUpdated": "2024-01-10 03:27:11" } /* @@ -39,11 +39,12 @@ const ICON_DETECT_MAPPING = { "s_book.gif": "journalArticle", "s_e_resource.gif": "journalArticle", "book.gif": "book" -} +}; -function detectWeb(doc, url) { +function detectWeb(doc, _url) { // Rather than parsing text in two different languages, we are using the icon let typeIcon = doc.getElementsByClassName("crs_recordtype_icon")[0].src; + let iname; for (iname in ICON_DETECT_MAPPING) { if (typeIcon.includes(iname)) { return ICON_DETECT_MAPPING[iname]; @@ -80,14 +81,14 @@ async function doWeb(doc, url) { } } -async function scrape(doc, url = doc.location.href) { +async function scrape(doc, _url = doc.location.href) { doc.getElementById("DirectLink").click(); await new Promise(resolve => setTimeout(resolve, 2000)); let exportButton = doc.getElementById("exportBibs"); let marcUrl = exportButton.href; - ZU.doGet(marcUrl, function(result) { + ZU.doGet(marcUrl, function (result) { var translator = Zotero.loadTranslator("import"); translator.setTranslator("edd87d07-9194-42f8-b2ad-997c4c7deefd"); translator.setString(result); @@ -99,7 +100,7 @@ async function scrape(doc, url = doc.location.href) { }); } -async function finalize(doc, item) { +async function finalize(_doc, _item) { }/** BEGIN TEST CASES **/ var testCases = [ From 3e1ac88d4e31ba56f5c9f26704b70fe83ecc8191 Mon Sep 17 00:00:00 2001 From: franklindyer Date: Thu, 11 Jan 2024 13:34:42 -0700 Subject: [PATCH 03/10] A few changes requested by @AbeJellinek: - changed label to include "Library Catalog" - improved regex for matching URL - added a few lines to `detectWeb` to allow for early failure - stylistic changes --- Library Catalog (TinREAD).js | 282 +++++++++++++++++++++++++++++++++++ 1 file changed, 282 insertions(+) create mode 100644 Library Catalog (TinREAD).js diff --git a/Library Catalog (TinREAD).js b/Library Catalog (TinREAD).js new file mode 100644 index 0000000000..a84402e1df --- /dev/null +++ b/Library Catalog (TinREAD).js @@ -0,0 +1,282 @@ +{ + "translatorID": "78835a5b-3378-49c2-a94f-3422aab0e949", + "label": "Library Catalog (TinREAD)", + "creator": "Franklin Pezzuti Dyer", + "target": "^https?://[^/]+/opac/bibliographic_view", + "minVersion": "5.0", + "maxVersion": "", + "priority": 250, + "inRepository": true, + "translatorType": 4, + "browserSupport": "gcsibv", + "lastUpdated": "2024-01-11 20:32:10" +} + +/* + ***** BEGIN LICENSE BLOCK ***** + + Copyright © 2024 Franklin Pezzuti Dyer + + 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 ***** +*/ + +const ICON_DETECT_MAPPING = { + "s_book.gif": "journalArticle", + "s_e_resource.gif": "journalArticle", + "book.gif": "book" +}; + +function detectWeb(doc, _url) { + let footer = text(doc, "#footer"); + if (!footer.toUpperCase().includes("TINREAD")) return false; + + // Rather than parsing text in two different languages, we are using the icon + let typeIcon = attr(doc, ".crs_recordtype_icon", "src"); + if (!typeIcon) return false; + let iname; + for (iname in ICON_DETECT_MAPPING) { + if (typeIcon.includes(iname)) { + return ICON_DETECT_MAPPING[iname]; + } + } + return false; +} + +function getSearchResults(doc, checkOnly) { + var items = {}; + var found = false; + var rows = doc.querySelectorAll('li.reslt_item_head > a[name="book_link"]'); + 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, url); + } +} + +async function scrape(doc, _url = doc.location.href) { + doc.getElementById("DirectLink").click(); + await new Promise(resolve => setTimeout(resolve, 2000)); + + let exportButton = doc.getElementById("exportBibs"); + let marcUrl = exportButton.href; + + ZU.doGet(marcUrl, function (result) { + var translator = Zotero.loadTranslator("import"); + translator.setTranslator("edd87d07-9194-42f8-b2ad-997c4c7deefd"); // MARCXML + translator.setString(result); + translator.setHandler("itemDone", function (obj, item) { + finalize(doc, item); + item.complete(); + }); + translator.translate(); + }); +} + +async function finalize(_doc, _item) { + +} +/** BEGIN TEST CASES **/ +var testCases = [ + { + "type": "web", + "url": "https://opac.biblioteca.ase.ro/opac/bibliographic_view/144193?pn=opac%2FSearch&q=gheorghe+carstea#level=all&location=0&ob=asc&q=gheorghe+carstea&sb=relevance&start=0&view=CONTENT", + "detectedItemType": "book", + "items": [ + { + "itemType": "book", + "title": "Managementul achizitiilor publice", + "creators": [ + { + "firstName": "Gheorghe", + "lastName": "Carstea", + "creatorType": "author" + }, + { + "firstName": "Monica Viorica", + "lastName": "Nedelcu", + "creatorType": "author" + } + ], + "date": "2002", + "ISBN": "9789735941130", + "callNumber": "352.5", + "libraryCatalog": "Library Catalog (TinREAD)", + "numPages": "165", + "place": "Bucuresti", + "publisher": "Editura ASE", + "attachments": [], + "tags": [ + { + "tag": "achizitii" + }, + { + "tag": "administratie publica" + }, + { + "tag": "cursuri multigrafiate" + }, + { + "tag": "guvern" + }, + { + "tag": "licitatii" + }, + { + "tag": "management" + }, + { + "tag": "sector public" + } + ], + "notes": [ + { + "note": "CZU 35.073.511 ; 65.012.4 ; 075.8" + } + ], + "seeAlso": [] + } + ] + }, + { + "type": "web", + "url": "https://tinread.biblioteca.ct.ro/opac/bibliographic_view/238969?pn=opac/Search&q=educatie+fizica#level=all&location=0&ob=asc&q=educatie+fizica&sb=relevance&start=0&view=CONTENT", + "detectedItemType": "book", + "items": [ + { + "itemType": "book", + "title": "Cursus. Educaţie fizică", + "creators": [], + "language": "rum", + "libraryCatalog": "Library Catalog (TinREAD)", + "attachments": [], + "tags": [], + "notes": [], + "seeAlso": [] + }, + { + "itemType": "book", + "title": "Metodica predării educaţiei fizice şi sportului", + "creators": [ + { + "firstName": "Elena", + "lastName": "Lupu", + "creatorType": "author" + } + ], + "date": "2006", + "ISBN": "9789736114366", + "callNumber": "796(075.8)", + "language": "rum", + "libraryCatalog": "Library Catalog (TinREAD)", + "place": "Iaşi", + "publisher": "Institutul European", + "series": "Cursus. Educaţie fizică", + "seriesNumber": "18", + "attachments": [], + "tags": [], + "notes": [], + "seeAlso": [] + } + ] + }, + { + "type": "web", + "url": "https://catalog.ucv.ro/opac/bibliographic_view/68938?pn=opac/Search&q=educatie+fizica#level=all&location=0&ob=asc&q=educatie+fizica&sb=relevance&start=0&view=CONTENT", + "detectedItemType": "book", + "items": [ + { + "itemType": "book", + "title": "Lecţia de educaţie fizică", + "creators": [ + { + "firstName": "Emil", + "lastName": "Ghibu", + "creatorType": "author" + } + ], + "date": "1957", + "callNumber": "796:371.3", + "language": "rum", + "libraryCatalog": "Library Catalog (TinREAD)", + "place": "Bucureşti", + "publisher": "Editura Tineretului", + "attachments": [], + "tags": [], + "notes": [], + "seeAlso": [] + } + ] + }, + { + "type": "web", + "url": "https://tinread.upit.ro/opac/bibliographic_view/37902?pn=opac/Search&q=metodica+educatie+fizica#level=all&location=0&ob=asc&q=metodica+educatie+fizica&sb=relevance&start=0&view=CONTENT", + "detectedItemType": "book", + "items": [ + { + "itemType": "book", + "title": "Metodica dezvoltării calităţilor fizice", + "creators": [ + { + "firstName": "Corneliu", + "lastName": "Florescu", + "creatorType": "author" + }, + { + "firstName": "Vasile", + "lastName": "Dumitrescu", + "creatorType": "author" + }, + { + "firstName": "Aurel", + "lastName": "Predescu", + "creatorType": "author" + } + ], + "date": "1969", + "callNumber": "796", + "edition": "Ediţia a II-a revăzută", + "language": "rum", + "libraryCatalog": "Library Catalog (TinREAD)", + "place": "Bucureşti", + "publisher": "Editura Consiliului Naţional pentru Educaţie Fizică şi Sport", + "attachments": [], + "tags": [], + "notes": [], + "seeAlso": [] + } + ] + } +] +/** END TEST CASES **/ From 3b34d8e641aa15d96da5e33679ae82287054fdcd Mon Sep 17 00:00:00 2001 From: franklindyer Date: Thu, 11 Jan 2024 14:01:56 -0700 Subject: [PATCH 04/10] removed reliance on button click, instead building MARCXML export URL using resource ID --- Library Catalog (TinREAD).js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Library Catalog (TinREAD).js b/Library Catalog (TinREAD).js index a84402e1df..898c79ab19 100644 --- a/Library Catalog (TinREAD).js +++ b/Library Catalog (TinREAD).js @@ -9,7 +9,7 @@ "inRepository": true, "translatorType": 4, "browserSupport": "gcsibv", - "lastUpdated": "2024-01-11 20:32:10" + "lastUpdated": "2024-01-11 21:00:57" } /* @@ -85,12 +85,15 @@ async function doWeb(doc, url) { } } -async function scrape(doc, _url = doc.location.href) { - doc.getElementById("DirectLink").click(); - await new Promise(resolve => setTimeout(resolve, 2000)); - - let exportButton = doc.getElementById("exportBibs"); - let marcUrl = exportButton.href; +async function scrape(doc, url = doc.location.href) { + let exportBtnLink = attr(doc, "#DirectLink", "href"); + let urlParts = new URL(url); + let pathParts = urlParts.pathname.split('/'); + let entryID = pathParts[pathParts.length - 1]; // Last part of path is typically the ID + Z.debug(entryID); + let marcUrl = "/marcexport.svc?enc=UTF-8&fmt=xml&items=none&marc=Current&type=bib&id="; + marcUrl = marcUrl.concat(entryID); + Z.debug(marcUrl); ZU.doGet(marcUrl, function (result) { var translator = Zotero.loadTranslator("import"); From 2b4c26b0312906b6ea5f638b6c0ed33a58c5a61c Mon Sep 17 00:00:00 2001 From: franklindyer Date: Thu, 11 Jan 2024 14:56:04 -0700 Subject: [PATCH 05/10] improved handling of search pages and added search test --- Library Catalog (TinREAD).js | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/Library Catalog (TinREAD).js b/Library Catalog (TinREAD).js index 898c79ab19..986614e975 100644 --- a/Library Catalog (TinREAD).js +++ b/Library Catalog (TinREAD).js @@ -9,7 +9,7 @@ "inRepository": true, "translatorType": 4, "browserSupport": "gcsibv", - "lastUpdated": "2024-01-11 21:00:57" + "lastUpdated": "2024-01-11 21:54:58" } /* @@ -46,8 +46,10 @@ function detectWeb(doc, _url) { if (!footer.toUpperCase().includes("TINREAD")) return false; // Rather than parsing text in two different languages, we are using the icon - let typeIcon = attr(doc, ".crs_recordtype_icon", "src"); - if (!typeIcon) return false; + let typeIcons = doc.querySelectorAll(".crs_recordtype_icon"); + if (typeIcons.length == 0) return false; + else if (typeIcons.length > 1) return "multiple"; + let typeIcon = typeIcons[0].src; let iname; for (iname in ICON_DETECT_MAPPING) { if (typeIcon.includes(iname)) { @@ -62,8 +64,8 @@ function getSearchResults(doc, checkOnly) { var found = false; var rows = doc.querySelectorAll('li.reslt_item_head > a[name="book_link"]'); for (let row of rows) { - let href = row.href; - let title = ZU.trimInternal(row.textContent); + let href = new URL(row.href).href; + let title = row.title; if (!href || !title) continue; if (checkOnly) return true; found = true; @@ -74,11 +76,9 @@ function getSearchResults(doc, checkOnly) { 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)); - } + Zotero.selectItems(getSearchResults(doc, false), function (items) { + if (items) return ZU.processDocuments(Object.keys(items), scrape); + }); } else { await scrape(doc, url); @@ -90,26 +90,16 @@ async function scrape(doc, url = doc.location.href) { let urlParts = new URL(url); let pathParts = urlParts.pathname.split('/'); let entryID = pathParts[pathParts.length - 1]; // Last part of path is typically the ID - Z.debug(entryID); let marcUrl = "/marcexport.svc?enc=UTF-8&fmt=xml&items=none&marc=Current&type=bib&id="; marcUrl = marcUrl.concat(entryID); - Z.debug(marcUrl); ZU.doGet(marcUrl, function (result) { var translator = Zotero.loadTranslator("import"); translator.setTranslator("edd87d07-9194-42f8-b2ad-997c4c7deefd"); // MARCXML translator.setString(result); - translator.setHandler("itemDone", function (obj, item) { - finalize(doc, item); - item.complete(); - }); translator.translate(); }); } - -async function finalize(_doc, _item) { - -} /** BEGIN TEST CASES **/ var testCases = [ { @@ -280,6 +270,12 @@ var testCases = [ "seeAlso": [] } ] + }, + { + "type": "web", + "url": "https://opac.biblioteca.ase.ro/opac/search?q=wirtschaftstheorie&max=0&view=&sb=relevance&ob=asc&level=all&material_type=all&do_file_type=all&location=0", + "detectedItemType": "multiple", + "items": "multiple" } ] /** END TEST CASES **/ From 0850a7f2299e1a9e839134b9c8c249c044c55cd9 Mon Sep 17 00:00:00 2001 From: franklindyer Date: Thu, 11 Jan 2024 14:58:30 -0700 Subject: [PATCH 06/10] minor tweaks to satisfy linter --- Library Catalog (TinREAD).js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Library Catalog (TinREAD).js b/Library Catalog (TinREAD).js index 986614e975..17850e18a2 100644 --- a/Library Catalog (TinREAD).js +++ b/Library Catalog (TinREAD).js @@ -9,7 +9,7 @@ "inRepository": true, "translatorType": 4, "browserSupport": "gcsibv", - "lastUpdated": "2024-01-11 21:54:58" + "lastUpdated": "2024-01-11 21:58:13" } /* @@ -78,6 +78,7 @@ async function doWeb(doc, url) { if (detectWeb(doc, url) == 'multiple') { Zotero.selectItems(getSearchResults(doc, false), function (items) { if (items) return ZU.processDocuments(Object.keys(items), scrape); + return true; }); } else { @@ -86,7 +87,6 @@ async function doWeb(doc, url) { } async function scrape(doc, url = doc.location.href) { - let exportBtnLink = attr(doc, "#DirectLink", "href"); let urlParts = new URL(url); let pathParts = urlParts.pathname.split('/'); let entryID = pathParts[pathParts.length - 1]; // Last part of path is typically the ID @@ -100,6 +100,7 @@ async function scrape(doc, url = doc.location.href) { translator.translate(); }); } + /** BEGIN TEST CASES **/ var testCases = [ { From 5cd56a5583b5876e531da14dcbfbbb0b8509a757 Mon Sep 17 00:00:00 2001 From: franklindyer Date: Thu, 11 Jan 2024 15:02:10 -0700 Subject: [PATCH 07/10] prefer requestText to doGet --- Library Catalog (TinREAD).js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Library Catalog (TinREAD).js b/Library Catalog (TinREAD).js index 17850e18a2..993d4057e5 100644 --- a/Library Catalog (TinREAD).js +++ b/Library Catalog (TinREAD).js @@ -9,7 +9,7 @@ "inRepository": true, "translatorType": 4, "browserSupport": "gcsibv", - "lastUpdated": "2024-01-11 21:58:13" + "lastUpdated": "2024-01-11 22:01:06" } /* @@ -92,13 +92,12 @@ async function scrape(doc, url = doc.location.href) { let entryID = pathParts[pathParts.length - 1]; // Last part of path is typically the ID let marcUrl = "/marcexport.svc?enc=UTF-8&fmt=xml&items=none&marc=Current&type=bib&id="; marcUrl = marcUrl.concat(entryID); + let marcText = await requestText(marcUrl); - ZU.doGet(marcUrl, function (result) { - var translator = Zotero.loadTranslator("import"); - translator.setTranslator("edd87d07-9194-42f8-b2ad-997c4c7deefd"); // MARCXML - translator.setString(result); - translator.translate(); - }); + var translator = Zotero.loadTranslator("import"); + translator.setTranslator("edd87d07-9194-42f8-b2ad-997c4c7deefd"); // MARCXML + translator.setString(marcText); + await translator.translate(); } /** BEGIN TEST CASES **/ From 2c3794a585cfdc395ef7c6598826e1ff1691cd0a Mon Sep 17 00:00:00 2001 From: Franklin Pezzuti Dyer <46753556+franklindyer@users.noreply.github.com> Date: Mon, 22 Jan 2024 15:30:03 -0700 Subject: [PATCH 08/10] make entryID concatenation less verbose Co-authored-by: Abe Jellinek --- Library Catalog (TinREAD).js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Library Catalog (TinREAD).js b/Library Catalog (TinREAD).js index 993d4057e5..406c8b7eb7 100644 --- a/Library Catalog (TinREAD).js +++ b/Library Catalog (TinREAD).js @@ -90,8 +90,7 @@ async function scrape(doc, url = doc.location.href) { let urlParts = new URL(url); let pathParts = urlParts.pathname.split('/'); let entryID = pathParts[pathParts.length - 1]; // Last part of path is typically the ID - let marcUrl = "/marcexport.svc?enc=UTF-8&fmt=xml&items=none&marc=Current&type=bib&id="; - marcUrl = marcUrl.concat(entryID); + let marcUrl = "/marcexport.svc?enc=UTF-8&fmt=xml&items=none&marc=Current&type=bib&id=" + entryID; let marcText = await requestText(marcUrl); var translator = Zotero.loadTranslator("import"); From 391bda732aae97dd23fb92e05f63a31f6f7cc7ea Mon Sep 17 00:00:00 2001 From: Franklin Pezzuti Dyer <46753556+franklindyer@users.noreply.github.com> Date: Mon, 22 Jan 2024 15:33:35 -0700 Subject: [PATCH 09/10] asyncify retrieval of search results Co-authored-by: Abe Jellinek --- Library Catalog (TinREAD).js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Library Catalog (TinREAD).js b/Library Catalog (TinREAD).js index 406c8b7eb7..830401eef8 100644 --- a/Library Catalog (TinREAD).js +++ b/Library Catalog (TinREAD).js @@ -76,10 +76,11 @@ function getSearchResults(doc, checkOnly) { async function doWeb(doc, url) { if (detectWeb(doc, url) == 'multiple') { - Zotero.selectItems(getSearchResults(doc, false), function (items) { - if (items) return ZU.processDocuments(Object.keys(items), scrape); - return true; - }); + 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, url); From 988f542a2ed84fc5fa90b3884a85f7d5f01ddf37 Mon Sep 17 00:00:00 2001 From: franklindyer Date: Mon, 22 Jan 2024 15:36:44 -0700 Subject: [PATCH 10/10] no hedging in comment ;-P --- Library Catalog (TinREAD).js | 44 ++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Library Catalog (TinREAD).js b/Library Catalog (TinREAD).js index 830401eef8..ff354854d8 100644 --- a/Library Catalog (TinREAD).js +++ b/Library Catalog (TinREAD).js @@ -9,30 +9,30 @@ "inRepository": true, "translatorType": 4, "browserSupport": "gcsibv", - "lastUpdated": "2024-01-11 22:01:06" + "lastUpdated": "2024-01-22 22:36:15" } /* - ***** BEGIN LICENSE BLOCK ***** + ***** BEGIN LICENSE BLOCK ***** - Copyright © 2024 Franklin Pezzuti Dyer + Copyright © 2024 Franklin Pezzuti Dyer - This file is part of Zotero. + 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 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. + 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 . + You should have received a copy of the GNU Affero General Public License + along with Zotero. If not, see . - ***** END LICENSE BLOCK ***** + ***** END LICENSE BLOCK ***** */ const ICON_DETECT_MAPPING = { @@ -76,11 +76,10 @@ function getSearchResults(doc, checkOnly) { 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)); - } + Zotero.selectItems(getSearchResults(doc, false), function (items) { + if (items) return ZU.processDocuments(Object.keys(items), scrape); + return true; + }); } else { await scrape(doc, url); @@ -90,8 +89,9 @@ async function doWeb(doc, url) { async function scrape(doc, url = doc.location.href) { let urlParts = new URL(url); let pathParts = urlParts.pathname.split('/'); - let entryID = pathParts[pathParts.length - 1]; // Last part of path is typically the ID - let marcUrl = "/marcexport.svc?enc=UTF-8&fmt=xml&items=none&marc=Current&type=bib&id=" + entryID; + let entryID = pathParts[pathParts.length - 1]; // Last part of path is the ID + let marcUrl = "/marcexport.svc?enc=UTF-8&fmt=xml&items=none&marc=Current&type=bib&id="; + marcUrl = marcUrl.concat(entryID); let marcText = await requestText(marcUrl); var translator = Zotero.loadTranslator("import");