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
24
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

Apparently I hack IN PARKOUR LOLOLOL
IMG_6919.png

😂🤣

After uttering those 3 words, the dude left and gave me a free win xD
A picture of my cat sleeping having kitty dreams
1000053259.jpg
kfccaleb wrote on WayneX4's profile.
You can now have a follow after I played with you!
How do you make spoilers with a name?
Top Bottom