I got bored yesterday, here's another forum addon which may be usefull to some people..
What the script does:
(Got the idea from https://www.cubecraft.net/threads/suggestion-report-a-player-sidebar.177726/ )
How to install
Chrome - Click
Firefox - Click
Opera - Click
(Just create a new file for each script of the 3 scripts, to use the script made by @MagnificentSpam install Tampermonkey instead of Violentmonkey)
After I posted this @MagnificentSpam made an adaption of my script which works way better, I would recommend using his solution.
Greasyfork links:
https://greasyfork.org/en/scripts/32219-cubecraft-report-statistics
https://greasyfork.org/en/scripts/32222-cubecraft-var-retreiver
https://greasyfork.org/en/scripts/32223-reports-updater
(all 3 are required)
It saves the statistics in cookies and tries to update the statistics on page load or if the browser tab is not in focus. If the statistics have been updated in the past 30 minutes it will not update them automatically. You can use the "update now" to update the statistics manually.
Updating the script opens up the report site in a new tab, you then get redirected, after that the tab closes. (if your internet doesnt manage to open 2 links in 3 seconds it might open another tab and try again)
(Make sure you're logged into the report site, else it wont work)
If you're interested in how the script works:
When you open up "https://cubecraft.net/" or "https://cubecraft.net/forums" it checks if you have cookies with the required data to fill in the menu. If you have the data required, it checks if the data has been updated in the past 30 minutes. If the data hasnt been updated the past 30 minutes or you don't have the cookies required, it opens up a new tab "https://reports.cubecraft.net/report?refresh", the "?refresh" part is what the third script requires to be activated, it get's the amount of successful reports and counts how many open reports you have. It will then redirect you to "https://cubecraft.net/?7;2", 7 being the amount of successful reports, 2 being the amount of open reports. Thanks to "?" script 2 activates and creates the cookies required for script 1, tab gets closed after the creation of the cookies & the original tab get's refreshed.
the setCookie() & getCookie functions are not written by me. Got them from W3schools
(I don't have acces to any database to get the data from so I have to do it this way instead..)
If you have an idea of what I could make the next time I get bored, please let me know :3
What the script does:
(Got the idea from https://www.cubecraft.net/threads/suggestion-report-a-player-sidebar.177726/ )
How to install
Chrome - Click
Firefox - Click
Opera - Click
(Just create a new file for each script of the 3 scripts, to use the script made by @MagnificentSpam install Tampermonkey instead of Violentmonkey)
After I posted this @MagnificentSpam made an adaption of my script which works way better, I would recommend using his solution.
Code:
// ==UserScript==
// @name Cubecraft Report Statistics
// @namespace Landviz' scripts
// @grant none
// @match https://www.cubecraft.net/
// @match https://www.cubecraft.net/forums/
// ==/UserScript==
function getCookie(cname) { // A function to eaasily check cookies
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
var updateTime = 30; // Time before the report stats try to update again in minutes
var reportsOpen = Number(getCookie('openReports'));
if(reportsOpen > 9) {
reportsOpen = "9+";
}
if(getCookie('handledReports') != "") {
var date = new Date();
var time = date.getTime();
document.querySelector('.styliumMainSidebar').innerHTML += '<div class="section widget_ForumStats" 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>' + getCookie('handledReports') + '</dd></dl><dl class="messageCount"><dt>Open reports:</dt><dd>' + reportsOpen + '</dd></dl><dl class="mostCount"><dt>Last update:</dt><dd>' + timeConverter(getCookie('updateTime')/1000) + '</dd></dl><dl><dd><a href="https://reports.cubecraft.net/report?refresh" target="_blank" onclick="setTimeout(function(){ location.reload(); }, 3000);">Update now</a></dd></dl></div></div></div>';
var timeDifference = time - getCookie('updateTime');
var updateTimeConv = updateTime*60*1000;
if(timeDifference > updateTimeConv) {
updateStats();
}
setInterval(function() {
if(!document.hasFocus()) {
location.reload();
}
}, 300000);
} else {
updateStats();
}
function timeConverter(UNIX_timestamp){ // Unix to normal time
var a = new Date(UNIX_timestamp * 1000);
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var year = a.getFullYear();
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;
}
var time = hour + ':' + min + ':' + sec + ', ' + month + ' ' + date;
return time;
}
function updateStats() {
window.open('https://reports.cubecraft.net/report?refresh', '_blank');
setTimeout(function(){ location.reload(); }, 3000);
}
Code:
// ==UserScript==
// @name Cubecraft Var Retreiver
// @namespace Landviz' scripts
// @grant none
// @match https://www.cubecraft.net/?*
// ==/UserScript==
var input = window.location.href.substring(27).split(';');
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
var date = new Date();
var time = date.getTime();
setCookie('handledReports', input[0], 365);
setCookie('openReports', input[1], 365);
setCookie('updateTime', time, 365);
window.close();
Code:
// ==UserScript==
// @name Reports Updater
// @namespace Landviz' scripts
// @grant none
// @match https://reports.cubecraft.net/report?refresh
// ==/UserScript==
var reports = document.querySelector('span.handled').innerHTML;
var reportsOpen = document.querySelectorAll('span[style="color: #FFA500"]').length;
console.log(reportsOpen);
var newUrl = "https://www.cubecraft.net/?" + reports + ";" + reportsOpen;
window.location.href = newUrl;
Greasyfork links:
https://greasyfork.org/en/scripts/32219-cubecraft-report-statistics
https://greasyfork.org/en/scripts/32222-cubecraft-var-retreiver
https://greasyfork.org/en/scripts/32223-reports-updater
(all 3 are required)
It saves the statistics in cookies and tries to update the statistics on page load or if the browser tab is not in focus. If the statistics have been updated in the past 30 minutes it will not update them automatically. You can use the "update now" to update the statistics manually.
Updating the script opens up the report site in a new tab, you then get redirected, after that the tab closes. (if your internet doesnt manage to open 2 links in 3 seconds it might open another tab and try again)
(Make sure you're logged into the report site, else it wont work)
If you're interested in how the script works:
When you open up "https://cubecraft.net/" or "https://cubecraft.net/forums" it checks if you have cookies with the required data to fill in the menu. If you have the data required, it checks if the data has been updated in the past 30 minutes. If the data hasnt been updated the past 30 minutes or you don't have the cookies required, it opens up a new tab "https://reports.cubecraft.net/report?refresh", the "?refresh" part is what the third script requires to be activated, it get's the amount of successful reports and counts how many open reports you have. It will then redirect you to "https://cubecraft.net/?7;2", 7 being the amount of successful reports, 2 being the amount of open reports. Thanks to "?" script 2 activates and creates the cookies required for script 1, tab gets closed after the creation of the cookies & the original tab get's refreshed.
the setCookie() & getCookie functions are not written by me. Got them from W3schools
(I don't have acces to any database to get the data from so I have to do it this way instead..)
Use the Tampermonkey addon & create a new script. Enter the following:
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);
});
If you have an idea of what I could make the next time I get bored, please let me know :3
Last edited: