{
	"translatorID": "d8341c22-8cf4-428f-be3b-ada9fa8933eb",
	"label": "Deutsche Nationalbibliothek",
	"creator": "Philipp Zumstein",
	"target": "^https?://portal\\.dnb\\.de/opac(\\.htm|/(enhancedSearch|simpleSearch|showFullRecord)\\?)",
	"minVersion": "3.0",
	"maxVersion": "",
	"priority": 100,
	"inRepository": true,
	"translatorType": 4,
	"browserSupport": "gcsibv",
	"lastUpdated": "2024-01-15 19:48:46"
}

/*
	***** BEGIN LICENSE BLOCK *****

	Copyright © 2015 Philipp Zumstein

	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 <http://www.gnu.org/licenses/>.

	***** END LICENSE BLOCK *****
*/

var typeMapping = {
	//"Blindendrucke"
	Bücher: "book",
	//"Elektronische Datenträger"
	"Filme/Hörbücher": "videoRecording",
	Karten: "map",
	//"Medienkombinationen"
	//"Mikroformen"
	Musiktonträger: "audioRecording",
	//"Musiknoten"
	Artikel: "journalArticle",
	//"Online Ressourcen"
	//"Zeitschriften/Serien"
	//"Ausgaben/Hefte"
	"archivierte Webseiten": "webpage",
	//"Gesamttitel Sammlung/Nachlass"
	Manuskripte: "manuscript",
	Briefe: "letter",
	//"Lebensdokumente"
	//"Sammlungen"
	//"Trägermaterialien (Papiere und Einbände)"
	"Bilder/Grafiken": "artwork"
	//"Flugblätter"
};

function detectWeb(doc, url) {
	if (
		(url.includes('method=showFullRecord') || url.includes('/showFullRecord?'))
		|| ((url.includes('method=simpleSearch') || url.includes('/simpleSearch?') || url.includes('/enhancedSearch?') || url.includes('method=enhancedSearch'))
		&& doc.getElementById('fullRecordTable'))
	) {
		var type = ZU.xpathText(doc, '//table[@id="fullRecordTable"]/tbody/tr/td/img/@alt');
		if (typeMapping[type]) {
			return typeMapping[type];
		}
		else {
			return "book";
		}
	}
	else if (getSearchResults(doc, true)) {
		return "multiple";
	}
	return false;
}

function getSearchResults(doc, checkOnly) {
	var items = {};
	var found = false;
	var rows = ZU.xpath(doc, '//table[@id="searchresult"]//a[contains(@id, "recordLink")]');
	for (var i = 0; i < rows.length; i++) {
		var href = rows[i].href;
		var title = ZU.trimInternal(rows[i].firstChild.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);
	}
}

async function scrape(doc) {
	var marc = ZU.xpath(doc, '//div[@class="link"]//a[contains(@href, "/about/marcxml")]');
	if (marc.length) {
		var marcUrl = marc[0].href;
		
		let result = await requestText(marcUrl);
		//call MARCXML translator
		let translator = Zotero.loadTranslator("import");
		translator.setTranslator("edd87d07-9194-42f8-b2ad-997c4c7deefd");
		translator.setString(result);
		translator.setHandler("itemDone", (_obj, item) => {
			finalize(doc, item);
			item.complete();
		});
		await translator.translate();
	}
	else {
		Z.debug("No MARC link found --> Use COinS translator");
		
		// call COinS translator
		// eslint-disable-next-line no-redeclare
		let translator = Zotero.loadTranslator("web");
		translator.setTranslator("05d07af9-105a-4572-99f6-a8e231c0daef");
		translator.setDocument(doc);
		translator.setHandler("itemDone", (_obj, item) => {
			finalize(doc, item);
			item.complete();
		});
		await translator.translate();
	}
}


function finalize(doc, item) {
	var toc = ZU.xpath(doc, '//a[contains(@title, "Inhaltsverzeichnis")]');
	if (toc.length) {
		item.attachments.push({
			url: toc[0].href,
			title: "Table of Contents PDF",
			mimeType: "application/pdf"
		});
	}
	
	var abstract = ZU.xpath(doc, '//a[contains(@title, "Inhaltstext")]');
	if (abstract.length) {
		item.attachments.push({
			url: abstract[0].href,
			title: "Abstract",
			mimeType: "text/html"
		});
	}
	
	item.callNumber = "";
}


/** BEGIN TEST CASES **/
var testCases = [
	{
		"type": "web",
		"url": "https://portal.dnb.de/opac.htm?method=simpleSearch&cqlMode=true&query=idn%3D1029203784",
		"items": [
			{
				"itemType": "book",
				"title": "Ausgeplündert, zurückerstattet und entschädigt: Arisierung und Wiedergutmachung in Mannheim",
				"creators": [
					{
						"firstName": "Christiane",
						"lastName": "Fritsche",
						"creatorType": "author"
					},
					{
						"firstName": "Ulrich",
						"lastName": "Nieß",
						"creatorType": "author"
					},
					{
						"firstName": "Stadt",
						"lastName": "Stadt Mannheim",
						"creatorType": "editor"
					},
					{
						"firstName": "Johannes",
						"lastName": "Paulmann",
						"creatorType": "author"
					},
					{
						"firstName": "Susanne",
						"lastName": "Schlösser",
						"creatorType": "editor"
					}
				],
				"date": "2013",
				"ISBN": "9783897357723",
				"edition": "2. Aufl",
				"language": "ger",
				"libraryCatalog": "Deutsche Nationalbibliothek",
				"numPages": "960",
				"place": "Ubstadt-Weiher Heidelberg Neustadt a.d.W. Basel",
				"publisher": "Verl. Regionalkultur",
				"series": "Sonderveröffentlichung des Stadtarchivs Mannheim - Institut für Stadtgeschichte",
				"seriesNumber": "Bd. 39",
				"shortTitle": "Ausgeplündert, zurückerstattet und entschädigt",
				"attachments": [
					{
						"title": "Table of Contents PDF",
						"mimeType": "application/pdf"
					},
					{
						"title": "Abstract",
						"mimeType": "text/html"
					}
				],
				"tags": [
					{
						"tag": "(Produktform)Hardback"
					},
					{
						"tag": "(VLB-WN)1558: Hardcover, Softcover / Geschichte/Regionalgeschichte, Ländergeschichte"
					},
					{
						"tag": "Arisierung"
					},
					{
						"tag": "Baden"
					},
					{
						"tag": "Geschichte 1933-1969"
					},
					{
						"tag": "Heimatgeschichte"
					},
					{
						"tag": "Mannheim"
					},
					{
						"tag": "Nachkriegszeit"
					},
					{
						"tag": "Wiedergutmachung"
					},
					{
						"tag": "Zweiter Weltkrieg"
					}
				],
				"notes": [
					{
						"note": "Literaturangaben"
					}
				],
				"seeAlso": []
			}
		]
	},
	{
		"type": "web",
		"url": "https://portal.dnb.de/opac.htm?method=simpleSearch&cqlMode=true&query=idn%3D1048581292",
		"items": [
			{
				"itemType": "book",
				"title": "Effiziente Entwurfsverfahren zur hardwarebasierten Signalverarbeitung elementarer Funktionen für die drahtlose Kommunikation",
				"creators": [
					{
						"firstName": "Jochen",
						"lastName": "Rust",
						"creatorType": "author"
					}
				],
				"date": "2014",
				"ISBN": "9783844027068",
				"language": "ger",
				"libraryCatalog": "Deutsche Nationalbibliothek",
				"numPages": "151",
				"place": "Aachen",
				"publisher": "Shaker",
				"series": "Forschungsberichte aus dem Institut für Theoretische Elektrotechnik und Mikroelektronik, Arbeitsbereich Kommunikationselektronik, Universität Bremen",
				"seriesNumber": "Bd. 2",
				"attachments": [
					{
						"title": "Table of Contents PDF",
						"mimeType": "application/pdf"
					}
				],
				"tags": [
					{
						"tag": "(Produktform (spezifisch))Unsewn / adhesive bound"
					},
					{
						"tag": "(Produktform)Paperback / softback"
					},
					{
						"tag": "(VLB-WN)1684: Hardcover, Softcover / Technik/Elektronik, Elektrotechnik, Nachrichtentechnik"
					},
					{
						"tag": "(Zielgruppe)Fachpublikum/ Wissenschaft"
					},
					{
						"tag": "Approximationsalgorithmus"
					},
					{
						"tag": "Digitale Signalverarbeitung"
					},
					{
						"tag": "Digitale Signalverarbeitung"
					},
					{
						"tag": "Drahtloses Sensorsystem"
					},
					{
						"tag": "Elementare Funktion"
					},
					{
						"tag": "Hardwareentwurf"
					},
					{
						"tag": "Hochschulschrift"
					},
					{
						"tag": "Kundenspezifische Schaltung"
					},
					{
						"tag": "Mikroelektronik"
					},
					{
						"tag": "Mobilfunk"
					}
				],
				"notes": [
					{
						"note": "Zugl.: Bremen, Univ., Diss., 2014"
					}
				],
				"seeAlso": []
			}
		]
	},
	{
		"type": "web",
		"url": "https://portal.dnb.de/opac.htm?query=smith&method=simpleSearch&cqlMode=true",
		"items": "multiple"
	},
	{
		"type": "web",
		"url": "https://portal.dnb.de/opac.htm?method=simpleSearch&cqlMode=true&query=idn%3D1064805604",
		"items": [
			{
				"itemType": "book",
				"title": "Das Adam-Smith-Projekt: Zur Genealogie der liberalen Gouvernementalität",
				"creators": [
					{
						"firstName": "Bastian",
						"lastName": "Ronge",
						"creatorType": "author"
					}
				],
				"date": "2015",
				"ISBN": "9783658060275",
				"edition": "Aufl. 2015",
				"language": "ger",
				"libraryCatalog": "Deutsche Nationalbibliothek",
				"place": "Wiesbaden",
				"publisher": "Springer Fachmedien Wiesbaden",
				"shortTitle": "Das Adam-Smith-Projekt",
				"attachments": [],
				"tags": [
					{
						"tag": "(BIC Subject Heading)JPA"
					},
					{
						"tag": "(Produktform)Electronic book text"
					},
					{
						"tag": "(Zielgruppe)Fachpublikum/ Wissenschaft"
					},
					{
						"tag": "(Zielgruppe)Professional/practitioner"
					},
					{
						"tag": "Adam Smith"
					},
					{
						"tag": "Foucault, Michel"
					},
					{
						"tag": "Gouvernementalität"
					},
					{
						"tag": "Liberalismus"
					},
					{
						"tag": "Liberalismus"
					},
					{
						"tag": "Macht"
					},
					{
						"tag": "Michel Foucault"
					},
					{
						"tag": "Politische Philosophie"
					},
					{
						"tag": "Rechtsordnung"
					},
					{
						"tag": "Smith, Adam"
					},
					{
						"tag": "Theorie der Moralität"
					},
					{
						"tag": "Wirtschaftsethik"
					}
				],
				"notes": [
					{
						"note": "Lizenzpflichtig"
					}
				],
				"seeAlso": []
			}
		]
	},
	{
		"type": "web",
		"url": "https://portal.dnb.de/opac.htm?method=simpleSearch&cqlMode=true&query=idn%3D950884529",
		"items": [
			{
				"itemType": "book",
				"title": "Der stimmrechtslose GmbH-Geschäftsanteil",
				"creators": [
					{
						"firstName": "Carsten",
						"lastName": "Schäfer",
						"creatorType": "author"
					}
				],
				"date": "1997",
				"ISBN": "9783504646431",
				"language": "ger",
				"libraryCatalog": "Deutsche Nationalbibliothek",
				"numPages": "402",
				"place": "Köln",
				"publisher": "O. Schmidt",
				"series": "Rechtsfragen der Handelsgesellschaften",
				"seriesNumber": "Bd. 91",
				"attachments": [
					{
						"title": "Table of Contents PDF",
						"mimeType": "application/pdf"
					}
				],
				"tags": [
					{
						"tag": "Ausschluss"
					},
					{
						"tag": "Geschäftsanteil"
					},
					{
						"tag": "Gesellschafter"
					},
					{
						"tag": "GmbH"
					},
					{
						"tag": "Hochschulschrift"
					},
					{
						"tag": "Stimmrecht"
					}
				],
				"notes": [
					{
						"note": "Zugl.: Heidelberg, Univ., Diss., 1997"
					}
				],
				"seeAlso": []
			}
		]
	},
	{
		"type": "web",
		"url": "https://portal.dnb.de/opac/simpleSearch?query=test",
		"items": "multiple"
	},
	{
		"type": "web",
		"url": "https://portal.dnb.de/opac/simpleSearch?query=idn%3D1272086992&cqlMode=true",
		"items": [
			{
				"itemType": "book",
				"title": "Den Netten beißen die Hunde: Wie Sie sich Respekt verschaffen, Grenzen setzen und den verdienten Erfolg erlangen - Mit großem \"Bin ich zu nett?\"-Test",
				"creators": [
					{
						"firstName": "Martin",
						"lastName": "Wehrle",
						"creatorType": "author"
					}
				],
				"date": "2024",
				"ISBN": "9783442179046",
				"language": "ger",
				"libraryCatalog": "Deutsche Nationalbibliothek",
				"numPages": "320",
				"place": "München",
				"publisher": "Goldmann",
				"shortTitle": "Den Netten beißen die Hunde",
				"attachments": [
					{
						"title": "Abstract",
						"mimeType": "text/html"
					}
				],
				"tags": [
					{
						"tag": "(Produktform)Paperback / softback"
					},
					{
						"tag": "(VLB-WN)2933: Taschenbuch / Sachbücher/Angewandte Psychologie"
					},
					{
						"tag": "Business"
					},
					{
						"tag": "Büro"
					},
					{
						"tag": "Den Letzten beißen die Hunde"
					},
					{
						"tag": "Durchsetzungsvermögen"
					},
					{
						"tag": "Mental Load"
					},
					{
						"tag": "Nein sagen ohne Schuldgefühle"
					},
					{
						"tag": "Partnerschaft Kommunikation"
					},
					{
						"tag": "Sei einzig nicht artig"
					},
					{
						"tag": "Selbstbewusstsein"
					},
					{
						"tag": "Selbstbewustsein stärken"
					},
					{
						"tag": "Selbstrespekt"
					},
					{
						"tag": "Wenn jeder dich mag nimmt keiner dich ernst"
					},
					{
						"tag": "Wertschätzung"
					},
					{
						"tag": "ausgenutzt werden"
					},
					{
						"tag": "ernst genommen werden"
					},
					{
						"tag": "fehlende Anerkennung"
					},
					{
						"tag": "sich durchsetzen"
					},
					{
						"tag": "spiegel bestseller"
					}
				],
				"notes": [],
				"seeAlso": []
			}
		]
	}
]
/** END TEST CASES **/
