{ "translatorID": "df9dca51-1f66-4dc6-a3e1-09b4c416db23", "label": "NYPL Menus", "creator": "Abe Jellinek", "target": "^https?://menus\\.nypl\\.org/", "minVersion": "3.0", "maxVersion": "", "priority": 100, "inRepository": true, "translatorType": 4, "browserSupport": "gcsibv", "lastUpdated": "2021-06-23 00:03:16" } /* ***** 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 ***** */ function detectWeb(doc, url) { if (/\/menu(s|_pages)\/\d+/.test(url)) { return "document"; } else if (getSearchResults(doc, true)) { return "multiple"; } return false; } function getSearchResults(doc, checkOnly) { var items = {}; var found = false; var rows = doc.querySelectorAll('.item .menu'); for (let row of rows) { let href = attr(row, 'a[href*="/menus/"]', 'href'); let title = ZU.trimInternal(text(row, 'a:not(.thumbportrait)') + ' ' + (text(row, 'div').match(/([0-9]{4})/) || [''])[0]); if (!href || !title) continue; if (checkOnly) return true; found = true; items[href] = title; } return found ? items : false; } function doWeb(doc, url) { if (detectWeb(doc, url) == "multiple") { Zotero.selectItems(getSearchResults(doc, false), function (items) { if (items) ZU.processDocuments(Object.keys(items), scrape); }); } else if (url.includes('/menu_pages/')) { ZU.processDocuments(attr(doc, '#carousel li:first-child a', 'href'), scrape); } else { scrape(doc, url); } } function scrape(doc, _url) { let item = new Zotero.Item('document'); item.title = text(doc, 'div.modes') + ' menu'; item.libraryCatalog = 'New York Public Library Menu Collection'; item.numPages = '' + doc.querySelector('.pages').childElementCount; item.url = attr(doc, '.pages a', 'href').replace(/\/explore$/, ''); if (item.url.startsWith('/')) { // only one case (/menu_pages/12345) to deal with here. // no HTTPS. item.url = 'http://menus.nypl.org' + item.url; } item.extra = 'genre: Restaurant menu\n'; for (let p of doc.querySelectorAll('.metadata p')) { let text = ZU.trimInternal(p.innerText); if (text.startsWith('Location')) { text = text.substring('Location'.length).trim(); item.extra += `Restaurant Location: ${text}\n`; } else if (text.startsWith('Date')) { text = text.substring('Date'.length); item.date = ZU.strToISO(text); } else if (text.startsWith('Place')) { text = text.substring('Place'.length).trim(); item.extra += `Place: ${text}\n`; } else if (text.startsWith('Physical description')) { text = text.substring('Physical description'.length).trim(); item.extra += `Physical Description: ${text}\n`; } else if (text.startsWith('Call number')) { text = text.substring('Call number'.length); item.callNumber = text; } else if (text.startsWith('Notes')) { text = text.substring('Notes'.length); item.abstractNote = text; } } let note = '

Dishes

'; item.notes.push({ note }); item.complete(); } /** BEGIN TEST CASES **/ var testCases = [ { "type": "web", "url": "http://menus.nypl.org/menus/26680", "items": [ { "itemType": "document", "title": "Zum Durnbrau menu", "creators": [], "date": "2005-01-14", "abstractNote": "Dieter Zander Collection; includes three paper inserts.", "callNumber": "Zander 324", "extra": "genre: Restaurant menu\nRestaurant Location: Zum Durnbrau\nPlace: Zum Durnbrau\nPhysical Description: Tri-fold; 11.75 x 16.5 inches folded", "libraryCatalog": "New York Public Library Menu Collection", "url": "http://menus.nypl.org/menu_pages/46080", "attachments": [], "tags": [], "notes": [ { "note": "

Dishes

" } ], "seeAlso": [] } ] }, { "type": "web", "url": "http://menus.nypl.org/menus/28929/explore", "items": [ { "itemType": "document", "title": "The Famous Anchor Sea Food House menu", "creators": [], "date": "1962-07-29", "abstractNote": "German is secondary language", "callNumber": "1962-0040_wotm", "extra": "genre: Restaurant menu\nRestaurant Location: The Famous Anchor Sea Food House\nPhysical Description: 33.5x25.5cm folded; 33.5x51cm open", "libraryCatalog": "New York Public Library Menu Collection", "url": "http://menus.nypl.org/menu_pages/54352", "attachments": [], "tags": [], "notes": [ { "note": "

Dishes

" } ], "seeAlso": [] } ] }, { "type": "web", "url": "http://menus.nypl.org/menus/31054", "items": [ { "itemType": "document", "title": "Plaza Hotel menu", "creators": [], "date": "1933", "abstractNote": "62 menus bound into 1 volume", "callNumber": "1933-0128_wotm", "extra": "genre: Restaurant menu\nRestaurant Location: Plaza Hotel\nPhysical Description: 30x21", "libraryCatalog": "New York Public Library Menu Collection", "url": "http://menus.nypl.org/menu_pages/62720", "attachments": [], "tags": [], "notes": [ { "note": "

Dishes

" } ], "seeAlso": [] } ] }, { "type": "web", "url": "http://menus.nypl.org/menu_pages/55739", "items": [ { "itemType": "document", "title": "Legal Sea Foods menu", "creators": [], "date": "1998-01-26", "callNumber": "1998-0005_wotm", "extra": "genre: Restaurant menu\nRestaurant Location: Legal Sea Foods\nPhysical Description: 37.5x23 folded; 37.5x46cm open", "libraryCatalog": "New York Public Library Menu Collection", "url": "http://menus.nypl.org/menu_pages/55736", "attachments": [], "tags": [], "notes": [ { "note": "

Dishes

" } ], "seeAlso": [] } ] }, { "type": "web", "url": "http://menus.nypl.org/menu_pages/35364/explore", "items": [ { "itemType": "document", "title": "American Asiatic Association menu", "creators": [], "date": "1906-02-03", "abstractNote": "WINES INCLUDED; EVENT WAS 1P.M. MENU MORE APPROPIATE FOR LUNCH THAN BREAKFAST;", "callNumber": "1906-126", "extra": "genre: Restaurant menu\nRestaurant Location: American Asiatic Association\nPlace: MERCHANTS CLUB,NY\nPhysical Description: BOOKLET; ILLUS; 4.5X7;", "libraryCatalog": "New York Public Library Menu Collection", "url": "http://menus.nypl.org/menu_pages/35366", "attachments": [], "tags": [], "notes": [ { "note": "

Dishes

" } ], "seeAlso": [] } ] }, { "type": "web", "url": "http://menus.nypl.org/dishes/9512", "items": "multiple" }, { "type": "web", "url": "http://menus.nypl.org/search?utf8=%E2%9C%93&query=aspic", "defer": true, "items": "multiple" } ] /** END TEST CASES **/