O no, again no lovely Safari one?! But I can see how many ppl appreciate this!! Amazing work and literally so useful ^^
// ==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 :]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); });
Now you can go 'Handle' some more reports, because you are Sr Mod, wait no, your just a wannabeOmg thanks you so much this is awesomeeee!!!
Do not necro-post. Necro-posting is replying on a thread where there wasn't any comment for two weeks.wat do you need to do when clicking on *new* at violentmonkey
Please do not reply to threads older than 2 weeks as it's not allowed.wat do you need to do when clicking on *new* at violentmonkey