From 89622b7cbae48ac93c1b8d664577da45f314efba Mon Sep 17 00:00:00 2001 From: Guy Khmelnitsky Date: Tue, 28 May 2024 09:09:04 +0300 Subject: [PATCH 1/2] - Fix YadVaShem new design - Remove `addEvent` and share code --- buildform.js | 21 +++ collections/bezikaron.js | 24 +-- collections/billiongraves.js | 19 --- collections/findagrave.js | 18 --- collections/gravez.js | 21 --- collections/toldot.js | 21 --- collections/yadVaShem.js | 141 ----------------- collections/yadvashem.js | 290 +++++++++++++++++++++++++++++++++++ popup.html | 2 +- 9 files changed, 313 insertions(+), 244 deletions(-) delete mode 100644 collections/yadVaShem.js create mode 100644 collections/yadvashem.js diff --git a/buildform.js b/buildform.js index c2fa7d7..d7d1acd 100644 --- a/buildform.js +++ b/buildform.js @@ -2070,6 +2070,27 @@ function getLocation(data) { } } +function addEvent(profiledata, event, dateval, eventlocation) { + data = [] + + dateval = cleanDate(dateval.replace("/","-")); + if (dateval !== "unknown" && dateval !== "") { + dt = moment(dateval, "DD-MM-YYYY", true); + if (dt.isValid()) { + dateval = dt.format('MMMM D, YYYY'); + } + data.push({date: dateval}); + } + if (eventlocation !== "") { + data.push({id: geoid, location: eventlocation}); + geoid++; + } + if (!$.isEmptyObject(data)) { + profiledata[event] = data; + } + return profiledata; +} + function emptyEvent(data) { if (exists(data)) { if (exists(data.date)) { diff --git a/collections/bezikaron.js b/collections/bezikaron.js index e04d189..0f41faf 100644 --- a/collections/bezikaron.js +++ b/collections/bezikaron.js @@ -155,26 +155,4 @@ registerCollection({ updateGeo(); } return profiledata; - } - - function addEvent(profiledata, event, dateval, eventlocation) { - data = [] - - dateval = cleanDate(dateval.replace("/","-")); - if (dateval !== "unknown" && dateval !== "") { - dt = moment(dateval, "DD-MM-YYYY", true); - if (dt.isValid()) { - dateval = dt.format('MMMM D, YYYY'); - } - data.push({date: dateval}); - } - if (eventlocation !== "") { - data.push({id: geoid, location: eventlocation}); - geoid++; - } - if (!$.isEmptyObject(data)) { - profiledata[event] = data; - } - return profiledata; - } - \ No newline at end of file + } \ No newline at end of file diff --git a/collections/billiongraves.js b/collections/billiongraves.js index 166cbfe..0cb937e 100644 --- a/collections/billiongraves.js +++ b/collections/billiongraves.js @@ -114,22 +114,3 @@ function parseBillionGraves(htmlstring, familymembers, relation) { } return profiledata; } - -function addEvent(profiledata, event, dateval, eventlocation) { - data = [] - if (exists(dateval) && dateval.contains(" (")) { - dateval = dateval.split(" (")[0]; - } - dateval = cleanDate(dateval); - if (dateval !== "unknown" && dateval !== "") { - data.push({date: dateval}); - } - if (eventlocation !== "") { - data.push({id: geoid, location: eventlocation}); - geoid++; - } - if (!$.isEmptyObject(data)) { - profiledata[event] = data; - } - return profiledata; -} diff --git a/collections/findagrave.js b/collections/findagrave.js index 2adc9ae..8cb5acc 100644 --- a/collections/findagrave.js +++ b/collections/findagrave.js @@ -273,24 +273,6 @@ function getFindAGraveName(focusperson) { return focusperson; } -function addEvent(profiledata, event, dateval, eventlocation) { - data = [] - if (exists(dateval) && dateval.contains(" (")) { - dateval = dateval.split(" (")[0]; - } - dateval = cleanDate(dateval); - if (dateval !== "unknown" && dateval !== "") { - data.push({date: dateval}); - } - if (eventlocation !== "") { - data.push({id: geoid, location: eventlocation}); - geoid++; - } - if (!$.isEmptyObject(data)) { - profiledata[event] = data; - } - return profiledata; -} function getFAGID(url) { let fagid = url.substring(url.lastIndexOf('memorial/') + 9).replace("#", ""); diff --git a/collections/gravez.js b/collections/gravez.js index 7318161..b75a2d5 100644 --- a/collections/gravez.js +++ b/collections/gravez.js @@ -133,24 +133,3 @@ function parseGravezMe(htmlstring, familymembers, relation) { return profiledata; } -function addEvent(profiledata, event, dateval, eventlocation) { - data = [] - - dateval = cleanDate(dateval.replace("/","-")); - if (dateval !== "unknown" && dateval !== "") { - dt = moment(dateval, "DD-MM-YYYY", true); - if (dt.isValid()) { - dateval = dt.format('MMMM D, YYYY'); - } - data.push({date: dateval}); - } - if (eventlocation !== "") { - data.push({id: geoid, location: eventlocation}); - geoid++; - } - if (!$.isEmptyObject(data)) { - profiledata[event] = data; - } - return profiledata; -} - diff --git a/collections/toldot.js b/collections/toldot.js index d096169..8172d1c 100644 --- a/collections/toldot.js +++ b/collections/toldot.js @@ -100,25 +100,4 @@ function parseToldotRu(htmlstring, familymembers, relation) { updateGeo(); } return profiledata; -} - -function addEvent(profiledata, event, dateval, eventlocation) { - data = [] - - dateval = cleanDate(dateval.replace("/","-")); - if (dateval !== "unknown" && dateval !== "") { - dt = moment(dateval, "DD-MM-YYYY", true); - if (dt.isValid()) { - dateval = dt.format('MMMM D, YYYY'); - } - data.push({date: dateval}); - } - if (eventlocation !== "") { - data.push({id: geoid, location: eventlocation}); - geoid++; - } - if (!$.isEmptyObject(data)) { - profiledata[event] = data; - } - return profiledata; } \ No newline at end of file diff --git a/collections/yadVaShem.js b/collections/yadVaShem.js deleted file mode 100644 index ac4f98a..0000000 --- a/collections/yadVaShem.js +++ /dev/null @@ -1,141 +0,0 @@ -// Parse YadVaShem.me Records -registerCollection({ - "reload": false, - "recordtype": "YadVaShem record", - "prepareUrl": function(url) { - if (startsWithHTTP(url,"https://yvng.yadvashem.org/nameDetails.html")) { - url = updateUrlParam(url, "language", "en"); - } - return url; - }, - "collectionMatch": function(url) { - return startsWithHTTP(url,"https://yvng.yadvashem.org/nameDetails.html") && getUrlParam(url, "itemId"); - }, - "parseData": function(url) { - if (startsWithHTTP(url,"https://yvng.yadvashem.org/nameDetails.html") && getUrlParam(url, "itemId")) { - focusURLid = getUrlParam(url, "itemId"); - getPageCode(); - } else { - document.querySelector('#loginspinner').style.display = "none"; - setMessage(warningmsg, 'Please select one of the Profile pages on this site.'); - } - }, - "loadPage": function(request) { - var parsed = $(request.source.replace(/]*>/ig, "")); - focusname = parsed.find("#title").first().text().trim(); - }, - "parseProfileData": parseYadVaShem -}); - - -// Parse FindAGrave -function parseYadVaShem(htmlstring, familymembers, relation) { - var parsed = $(htmlstring.replace(/]*>/ig, "")); + focusname = parsed.find(".header_title").first().text().trim(); + }, + parseProfileData: parseYadVaShem +}); + +const yadvashemAPIurl = "https://yv360.yadvashem.org/api/Names/GetSingleFullDetails?source=Page%20of%20Testemony"; + +function getItemIdStr() { + const lang = getLang(); + switch (lang) { + case "en": + return EN_TRANSLATIONS.get(item_id_str); + case "he": + return HE_TRANSLATIONS.get(item_id_str); + case "ru": + return RU_TRANSLATIONS.get(item_id_str); + case "es": + return ES_TRANSLATIONS.get(item_id_str); + case "de": + return DE_TRANSLATIONS.get(item_id_str); + case "fr": + return FR_TRANSLATIONS.get(item_id_str); + default: + return "Item ID"; + } +} + +const item_id_str = "item_id"; +const EN_TRANSLATIONS = new Map([ + [item_id_str, "Item ID"] +]); + +const HE_TRANSLATIONS = new Map([ + [item_id_str, "מספר פריט"] +]); + +const RU_TRANSLATIONS = new Map([ + [item_id_str, "Идентификационный номер"] +]); + +const ES_TRANSLATIONS = new Map([ + [item_id_str, "Número de registro"] +]); + +const DE_TRANSLATIONS = new Map([ + [item_id_str, "Datensatznummer"] +]); + +const FR_TRANSLATIONS = new Map([ + [item_id_str, "Numéro identifiant"] +]); + + +function parseYadVaShemJson(ys_person, focusperson, familymembers, relation) { + let focusdaterange = ""; + let genderval = "unknown"; + + let genderField = ys_person.gender; + if (genderField) { + genderval = genderField.toLowerCase(); + } + + if (relation === "") { + focusgender = genderval; + } else if (exists(relation.genderval) && genderval === "unknown") { + genderval = relation.genderval + } + + let name = focusperson; + if (ys_person.firstName && ys_person.lastName) { + name = ys_person.firstName + " " + ys_person.lastName; + if (ys_person.maidenName) { + name += " (" + ys_person.maidenName + ")"; + } + } + let profiledata = {name: name, gender: genderval, status: relation.title, url: tablink}; + + let famid = 0; + if (familymembers) { + loadGeniData(); + } + + // ---------------------- Profile Data -------------------- + if (focusdaterange !== "") { + profiledata["daterange"] = focusdaterange; + } + + if (exists(ys_person.dateOfBirth)) { + let placeOfBirth = ys_person.placeOfBirth; + profiledata = addEvent(profiledata, "birth", cleanDate(ys_person.dateOfBirth), placeOfBirth); + } + + if (exists(ys_person.dateOfDeath)) { + let placeOfDeath = ys_person.placeOfDeath; + profiledata = addEvent(profiledata, "death", cleanDate(ys_person.dateOfBirth), placeOfDeath); + } + + if (exists(ys_person.fathersFirstName)) { + let fm_title = "father"; + let fm_name = ys_person.fathersFirstName + " " + ys_person.lastName; + let fm_gender = "male"; + + addFamilyMember(fm_name, fm_gender, fm_title, famid) + + famid++; + } + + if (exists(ys_person.mothersFirstName)) { + let fm_title = "mother"; + let fm_name = ys_person.mothersFirstName + " " + ys_person.mothersMaidenName; + let fm_gender = "female"; + + addFamilyMember(fm_name, fm_gender, fm_title, famid) + + famid++; + } + + if (exists(ys_person.spoucesFirstName)) { + + let fm_name = ys_person.spoucesFirstName; + if (exists(ys_person.spoucesMaidenName)) { + fm_name += " " + ys_person.spoucesMaidenName; + } else { + fm_name += " " + ys_person.lastName; + } + + let fm_gender; + let fm_title; + if (genderval === "male") { + fm_gender = "female"; + fm_title = "wife"; + } else { + fm_gender = "male"; + fm_title = "husband"; + } + + addFamilyMember(fm_name, fm_gender, fm_title, famid) + + famid++; + } + + return profiledata; +} + +function addFamilyMember(name, gender, title, famid) { + let subdata = {name: name, title: title}; + subdata["url"] = tablink; + subdata["itemId"] = ""; + subdata["profile_id"] = famid; + + parentlist.push(famid); + + let familyMember = {name: name, gender: gender, status: title, alive: false} + familyMember = updateInfoData(familyMember, subdata); + + if (!exists(alldata["family"][title])) { + alldata["family"][title] = []; + } + alldata["family"][title].push(familyMember); +} + +function parseYadVaShem(htmlstring, familymembers, relation) { + let parsed = $(htmlstring.replace(/= 0; i--) { + if (records[i].getElementsByClassName("names_details_title")[0].innerText === itemIdStr) { + record_id = records[i].getElementsByClassName("names_details")[0].innerText; + break; + } + } + + let url = yadvashemAPIurl; + url = updateUrlParam(url, "lang", getLang()); + url = updateUrlParam(url, "id", record_id); + + let profiledata = {}; + + familystatus.push("about"); + chrome.runtime.sendMessage({ + method: "GET", + action: "xhttp", + url: url + }, function (response) { + + let json_obj = JSON.parse(response.source); + + const ys_person = json_obj.details.reduce((acc, detail) => { + // Take first value for each field + if (acc[fieldNameToLabelMap.get(detail.id)]) { + return acc; + } + + acc[fieldNameToLabelMap.get(detail.id)] = detail.value; + return acc; + }, {}); + + profiledata = parseYadVaShemJson(ys_person, focusperson, familymembers, relation); + + alldata["profile"] = profiledata; + alldata["scorefactors"] = smscorefactors; + updateGeo(); + + familystatus.pop(); + // let person = parseFindAGrave(response.source, familymembers, response.variable); + // person = updateInfoData(person, arg); + // databyid[arg.profile_id] = person; + // alldata["family"][arg.title].push(person); + // familystatus.pop(); + }); + + + + // ---------------------- Profile Continued -------------------- + + return profiledata; +} + +const urlRegex = /\/([a-z]{2})\/names\/(\d+)/; + +function getLang() { + const match = tablink.match(urlRegex); + if (match) { + return match[1]; + } + return null; +} + +function getYadVaShemUrlItemId(url) { + const match = url.match(urlRegex); + + if (match) { + return match[2]; + } + + return null; +} + +const fieldNameToLabelMap = new Map([ + ["GENDER", "gender"], + ["YSLN", "lastName"], + ["YSFN", "firstName"], + ["YSMN", "maidenName"], + ["AGE", "age"], + ["YSODB", "dateOfBirth"], + ["YSPB", "placeOfBirth"], + ["YSFTHN", "fathersFirstName"], + ["YSMTHN", "mothersFirstName"], + ["YSMMN", "mothersMaidenName"], + ["YSFST", "maritalStatus"], + ["YSSPN", "spoucesFirstName"], + ["YSSMN", "spoucesMaidenName"], + ["YSPLD", "placeOfDeath"], + ["YSDD", "dateOfDeath"], + ["YSPLP", "permanentPlaceOfResidence"], + ["YSPLW", "placeDuringTheWar"], + ["YSSBN", "submitterName"], + ["YSFR", "relationshipToVictim"], + ["PROF", "profession"], + ["LIF_391", "causeOfDeath"], + ["LIF_676", "statusAccordingToSource"] +]); \ No newline at end of file diff --git a/popup.html b/popup.html index 7fe56b7..41cb18d 100644 --- a/popup.html +++ b/popup.html @@ -953,7 +953,7 @@ - + From 132a26d53f6a41a6e384ab2bd0b8fae682194f22 Mon Sep 17 00:00:00 2001 From: Guy Khmelnitsky Date: Tue, 28 May 2024 09:14:00 +0300 Subject: [PATCH 2/2] minor styling fixes --- collections/yadvashem.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/collections/yadvashem.js b/collections/yadvashem.js index 556c5f5..7a44c13 100644 --- a/collections/yadvashem.js +++ b/collections/yadvashem.js @@ -230,17 +230,8 @@ function parseYadVaShem(htmlstring, familymembers, relation) { updateGeo(); familystatus.pop(); - // let person = parseFindAGrave(response.source, familymembers, response.variable); - // person = updateInfoData(person, arg); - // databyid[arg.profile_id] = person; - // alldata["family"][arg.title].push(person); - // familystatus.pop(); }); - - - // ---------------------- Profile Continued -------------------- - return profiledata; }