Etherium

Improve some guild features for Ethereal

目前為 2018-03-20 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Etherium
// @namespace    http://pendoria.net/
// @version      0.1
// @description  Improve some guild features for Ethereal
// @author       Rakky
// @match        http*://pendoria.net/*
// @grant        none
// @require      https://code.jquery.com/ui/1.12.1/jquery-ui.js
// ==/UserScript==

const ALERT_SOUND = new Audio("https://soundbible.com/grab.php?id=1424&type=mp3");

function updatePosition(xcoord, ycoord){
    localStorage.setItem("coordinates", JSON.stringify({'xcoord': xcoord, 'ycoord': ycoord}));
}

function getActiveMembers(){
    $.ajax({
        method: "POST",
        url: "https://pendoria.net/guild/members"
    })
        .done(function(data) {
        let members = countMembers(data);
        $('#active').text(members);
    });
}

function getProgress(){
    $.ajax({
        method: "POST",
        url: "https://pendoria.net/guild/tasks"
    })
        .done(function(data) {
        $('span#seconds').text("60");
        let progress = parseProgress(data);

        $('#progress').text(progress[0].toLocaleString() + " / " + progress[1].toLocaleString());
        let members = parseInt($('#active').text());
        let timestring = secondsToString(progress[0], progress[1], members);
        $('#eta').text(timestring);
        if(progress[0] >= progress[1]){ ALERT_SOUND.play(); }
    });
}

function parseProgress(htmlString){
    let html = $($.parseHTML(htmlString));
    let progressString = html.find('tr:contains("Progress")').children('td:contains("/")').text();
    let progress = progressString.split(" / ");
    progress[0] = parseInt(progress[0].replace(/,/g, ""));
    progress[1] = parseInt(progress[1].replace(/,/g, ""));
    return progress;
}

function getETA(current, total, active){
    return (total - current) / active * 6;
}

function secondsToString(time){
    let days = Math.floor(time/(24*60*60));
    let hours = Math.floor((time - days*24*60*60)/(60*60));
    let minutes = Math.floor((time - days*24*60*60 - hours*60*60)/60);
    let seconds = time - days*24*60*60 - hours*60*60 - minutes*60;
    let timestring = "";
    if(days > 0){ timestring = days + "d"; }
    if(hours > 0){ timestring = timestring + " " +  hours + "h"; }
    if(minutes > 0){ timestring = timestring + " " + minutes + "m"; }
    timestring = timestring + " " + seconds + "s";
    timestring = timestring.trim();
    return timestring;
}

function countMembers(htmlString){
    var html = $($.parseHTML(htmlString));
    return html.find('td.nowrap:contains("a few seconds ago")').length;
}

(function() {
    'use strict';

    let html = "";
    html += '<div id="EtheriumBox" class="ui-widget-content">';
    html += '<p>Members Active: <span id="active">0</span></p>';
    html += '<p>Progress: <span id="progress"></span></p>';
    html += '<p>ETA: <span id="eta"></span></p>';
    html += '<p id="update"><span id="seconds"></span><span id="update"><a id="update">update</a></span></p>';
    html += '</div>';
    $(document.body).append(html);

    $('a#update').on('click', function(){
        $('span#seconds').text("");
        getActiveMembers();
        getProgress();
    });

    $("#EtheriumBox").draggable({
        stop: function(){
            let xcoord = $('#EtheriumBox').css('left');
            let ycoord = $('#EtheriumBox').css('top');
            updatePosition(xcoord, ycoord);
        }
    });
    $("#EtheriumBox").css({'width': '175px',
                         'height': '90px',
                         'padding': '0.5em',
                         'border-style': 'solid',
                         'border-color': 'white',
                         'background-color': 'rgba(0,0,0,0.6)',
                         'color': 'white',
                         'z-index': '2',
                         'font-size': '12px'});
    $("span#update").css({'float': 'right'});


    let coordinates = JSON.parse(localStorage.getItem("coordinates"));
    if(coordinates){
        $("#EtheriumBox").css({'top': coordinates.ycoord,
                             'left': coordinates.xcoord});
    }

    getActiveMembers();
    getProgress();

    setInterval(function(){
        let seconds = parseInt($('span#seconds').text());
        if(seconds <= 1){
            getActiveMembers();
            getProgress();
            $('span#seconds').text("");
        } else {
            seconds--;
            $('span#seconds').text(seconds);
        }
    }, 1000);

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址