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 posts

Latest profile posts

AnolTongi wrote on Hqteful's profile.
Genuinely thank you for everything you've done, you're very much appreciated. Hope to see you around!
LorilambtheWcubecraftian wrote on Hqteful's profile.
Thanks for all ur help as mod! Enjoy your ccg retirement!! 💛
Kazwa wrote on Hqteful's profile.
Thanks for everything!
iTz1Hamood wrote on Hqteful's profile.
Thanks for everything, Mika. It honestly won’t be the same without you. I’m wishing you all the best in whatever comes next!! You truly deserve all the good things in life 🤍 I’ll always be grateful to you. You accepted my helper app, got me here.. and that meant alooot for me. Will miss you so much!! You’ve had such a positive impact on so many of us. Take care and stay amazing 💙
llvqs wrote on Hqteful's profile.
Thanks for everything and good luck with everything! 💙🧡
Top Bottom