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

Team online

Latest profile posts

Guys, with the release of 1.21.80 update on Bedrock, sharpness particles are now officially added to the game! You no longer need a custom texture pack to see them. Simply get a weapon with sharpness (or the relevant enchants for mobs) and hit them. And if you ask, yes it's also on CubeCraft (tested it a few mins ago)
Zawuri wrote on Fjackp14_'s profile.
Happy birthday!!
Zawuri wrote on Eli's profile.
Feliz cumpleaños!!
Working on something 😍😏🤔🤫
CCG_ga1.jpeg
chernoo wrote on Eli's profile.
Happy Birthday Eli
Top Bottom