Skip to content

Instantly share code, notes, and snippets.

@omkelderman
Created July 20, 2016 10:36
Show Gist options
  • Save omkelderman/004b6f79d5d5a4462b6f98278f482b22 to your computer and use it in GitHub Desktop.
Save omkelderman/004b6f79d5d5a4462b6f98278f482b22 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Hidden files checker
// @namespace https://github.com/omkelderman/
// @version 1.0
// @description See if there are any hidden files on your HDD (local or on remote server, including clan server)
// @author Olle Kelderman
// @match *://legacy.hackerexperience.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var $hdUsageText = $('.hd-usage-text');
// check if its a hdd-page
if($hdUsageText.length === 0) return;
//var multipliers = {
// B: 1,
// KB: 1024,
// MB: 1024*1024,
// GB: 1024*1024*1024,
// TB: 1024*1024*1024*1024
//};
var multipliers = {
B: 1,
KB: 1000,
MB: 1000*1000,
GB: 1000*1000*1000,
TB: 1000*1000*1000*1000
};
var sizeTextRegex = /([0-9\.]+) ?([a-zA-Z]+)/;
function fromTextToSize(text) {
var m = sizeTextRegex.exec(text);
if(m === null) return null;
var multiplierText = m[2].toUpperCase();
if(!multipliers[multiplierText]) return null;
//var num = parseInt(m[1]);
var num = m[1];
var multiplier = multipliers[multiplierText];
console.log('entry: %s * %d = %d', num, multiplier, num*multiplier);
return Math.round(num * multiplier, 0);
}
// probably the table containing the software-list
var $table = $('table').first();
var $rows = $table.find('tbody tr');
var total = 0;
$rows.each(function(i, el) {
var $sizeTd = $(el).find('td').eq(3);
var sizeText = $sizeTd.text().trim();
var size = fromTextToSize(sizeText);
if(size === null) {
console.warn('Invalid size identifier detected!!!');
return;
}
total += size;
});
console.log('total:', total);
// actual total
var $usageSpan = $hdUsageText.first().next();
var actualTotal = fromTextToSize($usageSpan.children().first().text());
var $newDiv = $('<div>').text('HDD usage in bytes: ' + actualTotal);
$usageSpan.after($newDiv);
var $newNewDiv = $('<div>').text('visible software size in bytes: ' + total);
$newDiv.after($newNewDiv);
var $newNewNewDiv = $('<div>').text('difference: ' + (actualTotal - total));
$newNewDiv.after($newNewNewDiv);
console.log('actual total', actualTotal);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment