HH Club Contributions

Save and compare checkpoints for how much members have contributed.

Від 14.09.2019. Дивіться остання версія.

// ==UserScript==
// @name         HH Club Contributions
// @namespace    hentaiheroes.com
// @version      0.1
// @description  Save and compare checkpoints for how much members have contributed.
// @author       Qweqwe
// @match        https://www.hentaiheroes.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    if (window.top === window.self || window.location.pathname.indexOf('clubs') === -1) {
        return;
    }

    var $ = window.$;

    function saveContributionCheckpoint() {
        $('#members tr').each(function() {
            var $this = $(this);
            var $contribTD = $this.find('td:nth-child(4)');
            var name = $this.find('td:nth-child(2)').get(0).childNodes[2].textContent.trim();
            var contrib = parseFloat($contribTD.get(0).childNodes[0].textContent.replace(',', ''));

            window.localStorage.setItem('contribution_checkpoint_' + encodeURIComponent(name), contrib);
        });

        compareContributionCheckpoint();
    }

    function compareContributionCheckpoint() {
        $('#members tr').each(function() {
            var $this = $(this);
            var $contribTD = $this.find('td:nth-child(4)');
            var name = $this.find('td:nth-child(2)').get(0).childNodes[2].textContent.trim()
            var contrib = parseFloat($contribTD.get(0).childNodes[0].textContent.replace(',', ''));

            if ($contribTD.get(0).childNodes[2]) {
                $contribTD.get(0).removeChild($contribTD.get(0).childNodes[2]);
            }

            var prevContrib = window.localStorage.getItem('contribution_checkpoint_' + encodeURIComponent(name), contrib);
            if (prevContrib) {
                $contribTD.append('(+' + (contrib - prevContrib) + ')');
            }
        });
    }

    compareContributionCheckpoint();

    var $button = $('<button />')
        .addClass('orange_text_button')
        .css({ 'z-index': '3', position: 'absolute', right: '65px', top: '12px', display: 'inline-block', height: '26px', 'line-height': '26px', padding: '0 5px' })
        .append('Checkpoint')
        .click(saveContributionCheckpoint);

    $('.club-container.club_dashboard')
        .prepend($button);
})();