MyHeritage Profile Helper

Go to profiles and trees from search results, unlock messages

当前为 2023-05-05 提交的版本,查看 最新版本

// ==UserScript==
// @name         MyHeritage Profile Helper
// @namespace    nikku
// @license      MIT
// @version      0.5
// @description  Go to profiles and trees from search results, unlock messages
// @author       nikku
// @match        https://www.myheritage.am/research*
// @match        https://www.myheritage.am/site-*
// @match        https://www.myheritage.am/member-*
// @match        https://www.myheritage.at/research*
// @match        https://www.myheritage.at/site-*
// @match        https://www.myheritage.at/member-*
// @match        https://www.myheritage.cat/research*
// @match        https://www.myheritage.cat/site-*
// @match        https://www.myheritage.cat/member-*
// @match        https://www.myheritage.cn/research*
// @match        https://www.myheritage.cn/site-*
// @match        https://www.myheritage.cn/member-*
// @match        https://www.myheritage.co.il/research*
// @match        https://www.myheritage.co.il/site-*
// @match        https://www.myheritage.co.il/member-*
// @match        https://www.myheritage.co.in/research*
// @match        https://www.myheritage.co.in/site-*
// @match        https://www.myheritage.co.in/member-*
// @match        https://www.myheritage.co.kr/research*
// @match        https://www.myheritage.co.kr/site-*
// @match        https://www.myheritage.co.kr/member-*
// @match        https://www.myheritage.com.br/research*
// @match        https://www.myheritage.com.br/site-*
// @match        https://www.myheritage.com.br/member-*
// @match        https://www.myheritage.com.hr/research*
// @match        https://www.myheritage.com.hr/site-*
// @match        https://www.myheritage.com.hr/member-*
// @match        https://www.myheritage.com.pt/research*
// @match        https://www.myheritage.com.pt/site-*
// @match        https://www.myheritage.com.pt/member-*
// @match        https://www.myheritage.com.tr/research*
// @match        https://www.myheritage.com.tr/site-*
// @match        https://www.myheritage.com.tr/member-*
// @match        https://www.myheritage.com.ua/research*
// @match        https://www.myheritage.com.ua/site-*
// @match        https://www.myheritage.com.ua/member-*
// @match        https://www.myheritage.com/research*
// @match        https://www.myheritage.com/site-*
// @match        https://www.myheritage.com/member-*
// @match        https://www.myheritage.cz/research*
// @match        https://www.myheritage.cz/site-*
// @match        https://www.myheritage.cz/member-*
// @match        https://www.myheritage.de/research*
// @match        https://www.myheritage.de/site-*
// @match        https://www.myheritage.de/member-*
// @match        https://www.myheritage.dk/research*
// @match        https://www.myheritage.dk/site-*
// @match        https://www.myheritage.dk/member-*
// @match        https://www.myheritage.ee/research*
// @match        https://www.myheritage.ee/site-*
// @match        https://www.myheritage.ee/member-*
// @match        https://www.myheritage.es/research*
// @match        https://www.myheritage.es/site-*
// @match        https://www.myheritage.es/member-*
// @match        https://www.myheritage.fi/research*
// @match        https://www.myheritage.fi/site-*
// @match        https://www.myheritage.fi/member-*
// @match        https://www.myheritage.fr/research*
// @match        https://www.myheritage.fr/site-*
// @match        https://www.myheritage.fr/member-*
// @match        https://www.myheritage.gr/research*
// @match        https://www.myheritage.gr/site-*
// @match        https://www.myheritage.gr/member-*
// @match        https://www.myheritage.hu/research*
// @match        https://www.myheritage.hu/site-*
// @match        https://www.myheritage.hu/member-*
// @match        https://www.myheritage.it/research*
// @match        https://www.myheritage.it/site-*
// @match        https://www.myheritage.it/member-*
// @match        https://www.myheritage.jp/research*
// @match        https://www.myheritage.jp/site-*
// @match        https://www.myheritage.jp/member-*
// @match        https://www.myheritage.lt/research*
// @match        https://www.myheritage.lt/site-*
// @match        https://www.myheritage.lt/member-*
// @match        https://www.myheritage.lv/research*
// @match        https://www.myheritage.lv/site-*
// @match        https://www.myheritage.lv/member-*
// @match        https://www.myheritage.mk/research*
// @match        https://www.myheritage.mk/site-*
// @match        https://www.myheritage.mk/member-*
// @match        https://www.myheritage.nl/research*
// @match        https://www.myheritage.nl/site-*
// @match        https://www.myheritage.nl/member-*
// @match        https://www.myheritage.no/research*
// @match        https://www.myheritage.no/site-*
// @match        https://www.myheritage.no/member-*
// @match        https://www.myheritage.pl/research*
// @match        https://www.myheritage.pl/site-*
// @match        https://www.myheritage.pl/member-*
// @match        https://www.myheritage.ro/research*
// @match        https://www.myheritage.ro/site-*
// @match        https://www.myheritage.ro/member-*
// @match        https://www.myheritage.rs/research*
// @match        https://www.myheritage.rs/site-*
// @match        https://www.myheritage.rs/member-*
// @match        https://www.myheritage.se/research*
// @match        https://www.myheritage.se/site-*
// @match        https://www.myheritage.se/member-*
// @match        https://www.myheritage.si/research*
// @match        https://www.myheritage.si/site-*
// @match        https://www.myheritage.si/member-*
// @match        https://www.myheritage.sk/research*
// @match        https://www.myheritage.sk/site-*
// @match        https://www.myheritage.sk/member-*
// @match        https://www.myheritage.tw/research*
// @match        https://www.myheritage.tw/site-*
// @match        https://www.myheritage.tw/member-*
// @exclude      https://www.myheritage.*/site-family-tree-*
// @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 messageUrl(memberId) {
    var rArr = ['153', '169', '187'];
    var reason = rArr[Math.floor(Math.random() * 3)];
    return window.location.origin + '/inbox/compose/recipient/' + memberId + '/type/1?reason=' + reason;
}

function messageHtml(memberId, style) {
    var tr = document.createElement('tr');
    var url = messageUrl(memberId);
    style = style || 'border-top: 1px solid #e8e8e8; padding-top: 5px;';
    tr.innerHTML = '<td colspan="2" style="' + style + '">✨&nbsp;&nbsp;<a href="' + url + '">Unlock Messages</a></td>';
    return tr;
}

(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);

(function() {
    'use strict';
    var isMember = window.location.pathname.startsWith('/member-');
    var isSite = window.location.pathname.startsWith('/site-');
    var memberId;

    if (isMember) {
        memberId = window.location.pathname.replace(/\/member-(\d+).*/i, '$1');
    }

    if (isSite) {
        var webmaster = document.getElementById('NavigationBoxWebmaster');
        var feedMember = document.body.querySelector('.NewsFeedMemberLink');

        if (webmaster) {
            memberId = webmaster.onclick.toString().replace(/[\s\S]+viainbox\((\d+)\)[\s\S]+/i, '$1');
        } else if (feedMember) {
            memberId = feedMember.href.replace(/.*?member-(\d+).*/i, '$1');
        }
    }

    if (isMember || isSite) {
        var navBox = document.querySelector('.NavigationBoxContainer > tbody');
        var profileBox = document.getElementById('profileNavigationBox');
        if (/^\d+$/.test(memberId)) {
            if (navBox) {
                navBox.appendChild(messageHtml(memberId));
            } else if (profileBox) {
                var table = document.createElement('table');
                table.classList.add('RoundedPanel', 'GrayRoundedPanel');
                table.setAttribute('style', 'width: 100%');
                table.appendChild(messageHtml(memberId, 'padding: 5px;'));
                profileBox.appendChild(table);
            }
        }
    }
})();