MyHeritage Profile Helper

Go to profiles and trees from search results

目前為 2023-04-21 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         MyHeritage Profile Helper
// @namespace    nikku
// @license      MIT
// @version      0.2
// @description  Go to profiles and trees from search results
// @author       nikku
// @match        https://www.myheritage.am/research*
// @match        https://www.myheritage.at/research*
// @match        https://www.myheritage.cat/research*
// @match        https://www.myheritage.cn/research*
// @match        https://www.myheritage.co.il/research*
// @match        https://www.myheritage.co.in/research*
// @match        https://www.myheritage.co.kr/research*
// @match        https://www.myheritage.com.br/research*
// @match        https://www.myheritage.com.hr/research*
// @match        https://www.myheritage.com.pt/research*
// @match        https://www.myheritage.com.tr/research*
// @match        https://www.myheritage.com.ua/research*
// @match        https://www.myheritage.com/research*
// @match        https://www.myheritage.cz/research*
// @match        https://www.myheritage.de/research*
// @match        https://www.myheritage.dk/research*
// @match        https://www.myheritage.ee/research*
// @match        https://www.myheritage.es/research*
// @match        https://www.myheritage.fi/research*
// @match        https://www.myheritage.fr/research*
// @match        https://www.myheritage.gr/research*
// @match        https://www.myheritage.hu/research*
// @match        https://www.myheritage.it/research*
// @match        https://www.myheritage.jp/research*
// @match        https://www.myheritage.lt/research*
// @match        https://www.myheritage.lv/research*
// @match        https://www.myheritage.mk/research*
// @match        https://www.myheritage.nl/research*
// @match        https://www.myheritage.no/research*
// @match        https://www.myheritage.pl/research*
// @match        https://www.myheritage.ro/research*
// @match        https://www.myheritage.rs/research*
// @match        https://www.myheritage.se/research*
// @match        https://www.myheritage.si/research*
// @match        https://www.myheritage.sk/research*
// @match        https://www.myheritage.tw/research*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=myheritage.com
// @grant        none
// ==/UserScript==

function personId(item) {
    return item[1] * 1000000 + parseInt(item[2]);
}

function createUrl(coll, item, name, link) {
    switch (coll) {
        case '1':
            return '/person-' + personId(item) + ('_' + item[0]).repeat(2) + '/';
        case '2':
            return '/site-' + item + '/';
        case '3':
            return '/member-' + item + '_1/';
        default:
            return link;
    }
}

function processData(data) {
    data.forEach(function(rec) {
        var coll = rec.record.collection.id.split('-')[1];
        var item = rec.record.id.split('-')[2].split('_');
        var name = rec.record.name;
        var link = rec.user_info.link;
        var newUrl = createUrl(coll, item, name, link);

        if (link != newUrl) {
            rec.user_info.link = newUrl;
            rec.record.name = '✨ ' + rec.record.name;
            if (coll == '1') {
                var parts = rec.record.collection.name.split(',');
                if (parts.length > 1) {
                    var tree = '<b><a onclick="event.stopPropagation();" href="/site-family-tree-' + item[0] + '/tree?rootIndivudalID=' + personId(item) + '&familyTreeID=' + item[1] + '">🌳 Tree</a></b>';
                    var website = '<span class="sub"><b><a onclick="event.stopPropagation();" href="/site-' + item[0] + '/">' + parts[0] + '</a></b></span>';
                    var admin = parts[1].replace(/(.*) (\S+ \S+)/, '$1 <b>$2</b>').replace('администрирует', 'адм.');
                    rec.record.collection.name = tree + website + ',' + admin;
                }
            }
        }

        if (coll == '40000') {
            rec.record.collection.name = '🌀 ' + rec.record.collection.name;
        }

        if (coll == '40001') {
            rec.record.collection.name = '🌱 ' + rec.record.collection.name;
        }
    });
}

(function(open) {
    XMLHttpRequest.prototype.open = function() {
        if (arguments[1].includes('search_in_historical_records')) {
            this.addEventListener('load', function() {
                var json = JSON.parse(this.responseText);
                var res = json.data.search_query_upload.response.results;
                if (res.data) {
                    processData(res.data);
                    Object.defineProperty(this, 'responseText', {writable: true});
                    this.responseText = JSON.stringify(json);
                }
            }, false);
        }
        open.apply(this, arguments);
    };
})(XMLHttpRequest.prototype.open);