Minecraft PC IP: play.cubecraft.net
Status
Not open for further replies.

MagnificentSpam

Forum Expert
Mar 16, 2016
2,306
2,239
298
You can use GM_xmlhttpRequest for this, but I think that doesn't work on opera either.
Code:
// ==UserScript==
// @name Cubecraft Report Thing
// @namespace de.rasmusantons
// @require https://www.cubecraft.net/js/jquery/jquery-1.11.0.min.js
// @include https://www.cubecraft.net/
// @include https://www.cubecraft.net/forums/
// @version 1
// @description Adaption of https://www.cubecraft.net/threads/reporting-statistics.195329/
// @grant GM_xmlhttpRequest
// ==/UserScript==

var UPDATE_INTERVAL = 5; // Time before the report stats try to update again in minutes

function timeConverter(UNIX_timestamp){ // Unix to normal time
    var a = new Date(UNIX_timestamp);
    var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
    var month = months[a.getMonth()];
    var date = a.getDate();
    var hour = a.getHours();
    if(hour < 10)
        hour = "0" + hour;
    var min = a.getMinutes();
    if(min < 10)
        min = "0" + min;
    var sec = a.getSeconds();
    if(sec < 10)
        sec = "0" + sec;
    return hour + ':' + min + ':' + sec + ', ' + month + ' ' + date;
}

function drawWidget(handledReports, openReports, updateTime) {
    document.querySelectorAll('.widget_ReportStats').forEach(function(e) {e.remove()});
    if(openReports > 9)
        openReports = "10+";
    $('.styliumMainSidebar').append('<div class="section widget_ForumStats widget_ReportStats" id="widget_4">'
            + '<div class="secondaryContent statsList" style="background:#ffffff;">'
            + '<h3>Reporting Statistics</h3><div class="pairsJustified">'
            + '<dl class="discussionCount"><dt>Successful reports:</dt><dd>' + handledReports + '</dd></dl>'
            + '<dl class="messageCount"><dt>Open reports:</dt><dd>' + openReports + '</dd></dl>'
            + '<dl class="mostCount"><dt>Last update:</dt><dd>' + timeConverter(updateTime) + '</dd></dl>'
            + '<dl><dd><a id="updateStatsLink">Update now</a></dd></dl>'
            + '</div></div></div>');
    $('#updateStatsLink').click(updateStats);
}

function updateStats() {
    GM_xmlhttpRequest({
        method: "GET",
        url: "https://reports.cubecraft.net/report",
        onload: function(response) {
            var handledReports = response.responseText.match(/<span class="handled">(\d+)<\/span>/)[1];
            var openReports = (response.responseText.match(/<span style="color: #FFA500">/g) || []).length;
            drawWidget(handledReports, openReports, new Date().getTime());
        }
    });
}

$(document).ready(function() {
    updateStats();
    setInterval(updateStats, UPDATE_INTERVAL * 60 * 1000);
});
 
  • Like
Reactions: Max ♠

Max ♠

Forum Expert
Feb 20, 2016
1,420
2,940
344
25
North pole
You can use GM_xmlhttpRequest for this, but I think that doesn't work on opera either.
Code:
// ==UserScript==
// @name Cubecraft Report Thing
// @namespace de.rasmusantons
// @require https://www.cubecraft.net/js/jquery/jquery-1.11.0.min.js
// @include https://www.cubecraft.net/
// @include https://www.cubecraft.net/forums/
// @version 1
// @description Adaption of https://www.cubecraft.net/threads/reporting-statistics.195329/
// @grant GM_xmlhttpRequest
// ==/UserScript==

var UPDATE_INTERVAL = 5; // Time before the report stats try to update again in minutes

function timeConverter(UNIX_timestamp){ // Unix to normal time
    var a = new Date(UNIX_timestamp);
    var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
    var month = months[a.getMonth()];
    var date = a.getDate();
    var hour = a.getHours();
    if(hour < 10)
        hour = "0" + hour;
    var min = a.getMinutes();
    if(min < 10)
        min = "0" + min;
    var sec = a.getSeconds();
    if(sec < 10)
        sec = "0" + sec;
    return hour + ':' + min + ':' + sec + ', ' + month + ' ' + date;
}

function drawWidget(handledReports, openReports, updateTime) {
    document.querySelectorAll('.widget_ReportStats').forEach(function(e) {e.remove()});
    if(openReports > 9)
        openReports = "10+";
    $('.styliumMainSidebar').append('<div class="section widget_ForumStats widget_ReportStats" id="widget_4">'
            + '<div class="secondaryContent statsList" style="background:#ffffff;">'
            + '<h3>Reporting Statistics</h3><div class="pairsJustified">'
            + '<dl class="discussionCount"><dt>Successful reports:</dt><dd>' + handledReports + '</dd></dl>'
            + '<dl class="messageCount"><dt>Open reports:</dt><dd>' + openReports + '</dd></dl>'
            + '<dl class="mostCount"><dt>Last update:</dt><dd>' + timeConverter(updateTime) + '</dd></dl>'
            + '<dl><dd><a id="updateStatsLink">Update now</a></dd></dl>'
            + '</div></div></div>');
    $('#updateStatsLink').click(updateStats);
}

function updateStats() {
    GM_xmlhttpRequest({
        method: "GET",
        url: "https://reports.cubecraft.net/report",
        onload: function(response) {
            var handledReports = response.responseText.match(/<span class="handled">(\d+)<\/span>/)[1];
            var openReports = (response.responseText.match(/<span style="color: #FFA500">/g) || []).length;
            drawWidget(handledReports, openReports, new Date().getTime());
        }
    });
}

$(document).ready(function() {
    updateStats();
    setInterval(updateStats, UPDATE_INTERVAL * 60 * 1000);
});
Works perfectly using Tampermonkey in Chrome, Firefox & Opera :]

Added to originalpost :3
 
Status
Not open for further replies.
Members Online

Latest profile posts

thank you flxen you are the best cubecrafter
sebasxd12 wrote on Flxen's profile.
mis condolencias hermano
day #7 on the way to #100
1751326464917.png
Minor server update: CubeCraft replaced the emote stand with how to play in all game lobbies. Very nice QoL change for Bedrock. It's also added to the hotbar when you join the game, so now new players can walk up to it or use it while waiting for game to start to learn the game
HoppyFrog wrote on Flxen's profile.
Aww :(, sorry I'm late. Thanks for everything Flxen :despair:
Top Bottom