From ec55cd8030bba6c93e59d75b0099d05294c32b84 Mon Sep 17 00:00:00 2001 From: Sebastian Karcher Date: Mon, 3 Sep 2018 20:48:53 -0400 Subject: [PATCH] Eastview: Fix after sited redesign (#1732) fix Eastview after redesign; improve attachments --- Eastview.js | 145 ++++++++++++++++++++++++---------------------------- 1 file changed, 66 insertions(+), 79 deletions(-) diff --git a/Eastview.js b/Eastview.js index 900a23ba47..b4e1c83c95 100644 --- a/Eastview.js +++ b/Eastview.js @@ -9,7 +9,7 @@ "inRepository": true, "translatorType": 4, "browserSupport": "gcsibv", - "lastUpdated": "2018-07-15 20:34:03" + "lastUpdated": "2018-09-02 23:10:00" } /* @@ -36,13 +36,31 @@ */ function detectWeb(doc, url) { if (url.includes("/search/simple/articles?") || url.includes("/search/advanced/articles") || url.search(/browse\/(favorites|issue)/) != -1) { - Z.monitorDOMChanges(doc.getElementById("container"), {childList: true}); - if (ZU.xpath(doc, '//td[contains(@class, "title-cell")]/a').length) return "multiple"; + Z.monitorDOMChanges(doc.getElementById("articleSearchContainer"), { + childList: true + }); + if (getSearchResults(doc, true)) return "multiple"; } else { return "newspaperArticle" } } +function getSearchResults(doc, checkOnly) { + var items = {}; + var found = false; + var rows = ZU.xpath(doc, '//div[@id="articleSearchContainer"]//a[@class="Link" and contains(@href, "doc?")]'); + + for (var i = 0; i < rows.length; i++) { + var href = rows[i].href; + var title = ZU.trimInternal(rows[i].textContent); + if (!href || !title) continue; + if (checkOnly) return true; + found = true; + items[href] = title; + } + return found ? items : false; +} + var typeMap = { "Argumenty i fakty": "magazineArticle", "Argumenty nedeli": "magazineArticle", @@ -79,13 +97,18 @@ var typeMap = { function permaLink(URL) { var id = URL.match(/id=(\d+)/); - if (id) return "http://dlib.eastview.com/browse/doc/" + id[1]; - else return URL + if (id) return "/browse/doc/" + id[1]; + else return URL; } +function pdfLink(URL) { + var id = URL.match(/id=(\d+)/); + if (id) return "/browse/pdf-download?articleid=" + id[1]; + else return URL; +} function scrape(doc, url) { - Z.debug(url); + //Z.debug(url); var item = new Zotero.Item("newspaperArticle"); var publication = ZU.xpathText(doc, '//a[@class="path" and contains(@href, "browse/publication")]'); item.publicationTitle = publication; @@ -98,11 +121,11 @@ function scrape(doc, url) { } var database = ZU.xpathText(doc, '//a[@class="path" and contains(@href, "browse/udb")]'); if (database) item.libraryCatalog = database.replace(/\(.+\)/, "") + "(Eastview)"; - if (doc.getElementById('metatable')) { + if (ZU.xpathText(doc, '//table[@class="table table-condensed Table Table-noTopBorder"]//td[contains(text(), "Article")]')) { //we have the metadata in a table - var metatable = doc.getElementById('metatable'); - var title = ZU.xpathText(metatable, './/td[@class="hdr" and contains(text(), "Article")]/following-sibling::td[@class="val"]'); - var source = ZU.xpathText(metatable, './/td[@class="hdr" and contains(text(), "Source")]/following-sibling::td[@class="val"]'); + var metatable = ZU.xpath(doc, '//table[tbody/tr/td[contains(text(), "Article")]]'); + var title = ZU.xpathText(metatable, './/td[contains(text(), "Article")]/following-sibling::td'); + var source = ZU.xpathText(metatable, './/td[contains(text(), "Source")]/following-sibling::td'); if (source) { var date = source.match(/(January|February|March|April|May|Juni|July|August|September|October|November|December)\s+(\d{1,2},\s+)?\d{4}/); if (date) item.date = ZU.trimInternal(date[0]); @@ -114,28 +137,28 @@ function scrape(doc, url) { } } if (!item.publicationTitle) { - item.publicationTitle = ZU.xpathText(metatable, './/td[@class="hdr" and text()="Title"]/following-sibling::td[@class="val"]'); + item.publicationTitle = ZU.xpathText(metatable, './/td[text()="Title"]/following-sibling::td'); } if (!item.pages) { - var pagesOnly = ZU.xpathText(metatable, './/td[@class="hdr" and contains(text(), "Page(s)")]/following-sibling::td[@class="val"]'); + var pagesOnly = ZU.xpathText(metatable, './/td[contains(text(), "Page(s)")]/following-sibling::td'); item.pages = pagesOnly; } - var author = ZU.xpathText(metatable, './/td[@class="hdr" and contains(text(), "Author(s)")]/following-sibling::td[@class="val"]'); + var author = ZU.xpathText(metatable, './/td[contains(text(), "Author(s)")]/following-sibling::td'); if (author) { //Z.debug(author) authors = author.trim().split(/\s*,\s*/); - for (var i=0; i