Last active
March 18, 2018 19:05
-
-
Save hymccord/0e56b93fe7cb81715783418d3e8d2ca8 to your computer and use it in GitHub Desktop.
FHRV Cloudtrax Info Highlighter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name FHRV Cloudtrax Extra Info | |
// @namespace http://github.com/InKahootz/ | |
// @version 0.6 | |
// @description Highlights users based on voucher info and data usage for the selected time period | |
// @author Hank McCord | |
// @match https://ct4.cloudtrax.com/monitor/clients* | |
// @match https://ct4.cloudtrax.com/monitor/vouchers* | |
// @require http://code.jquery.com/jquery-latest.js | |
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js | |
// @grant GM_addStyle | |
// @grant GM_getValue | |
// @grant GM_setValue | |
// @updateURL https://gist.github.com/InKahootz/0e56b93fe7cb81715783418d3e8d2ca8/raw/cloudtraxScriptUpdater.user.js | |
// @downloadURL https://gist.github.com/InKahootz/0e56b93fe7cb81715783418d3e8d2ca8/raw/fhrvcloudtrax.user.js | |
// ==/UserScript== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name FHRV Cloudtrax Extra Info | |
// @namespace http://github.com/InKahootz/ | |
// @version 0.6 | |
// @description Highlights users based on voucher info and data usage for the selected time period | |
// @author Hank McCord | |
// @match https://ct4.cloudtrax.com/monitor/clients* | |
// @match https://ct4.cloudtrax.com/monitor/vouchers* | |
// @require http://code.jquery.com/jquery-latest.js | |
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js | |
// @grant GM_addStyle | |
// @grant GM_getValue | |
// @grant GM_setValue | |
// @updateURL https://gist.github.com/InKahootz/0e56b93fe7cb81715783418d3e8d2ca8/raw/cloudtraxScriptUpdater.user.js | |
// @downloadURL https://gist.github.com/InKahootz/0e56b93fe7cb81715783418d3e8d2ca8/raw/fhrvcloudtrax.user.js | |
// ==/UserScript== | |
var myList = {}; | |
var myListObj = GM_getValue ("FHRVActiveUsers", ""); | |
if (myListObj) { | |
myList = JSON.parse (myListObj); | |
} | |
//-- DEBUG: List items to console. | |
/* | |
console.log ("There are ", Object.keys (myList).length, " items in the list."); | |
for (var myItem in myList) { | |
if (myList.hasOwnProperty && myList.hasOwnProperty (myItem) ) { | |
console.log (myItem + " : ", myList[myItem]); | |
} | |
} | |
*/ | |
var storeVouchers = false; | |
if (/monitor\/vouchers/.test (location.href) ) { | |
storeVouchers = true; | |
} | |
/* | |
(function() { | |
'use strict'; | |
// Your code here... | |
})(); | |
*/ | |
waitForKeyElements ("select#period", selectTimePeriod); | |
waitForKeyElements ("tr.odd, tr.even", actionFunction); | |
waitForKeyElements ("thead.headers tr", addClientsTableColumn); | |
var usersArray = {}; | |
function actionFunction (jNode) { | |
if (storeVouchers) | |
{ | |
if (jNode.data('status') == "active") | |
{ | |
var voucherLength = jNode.data("duration"); | |
var usersString = jNode.children("td.users").contents().filter(function() { | |
return this.nodeType == 3;}); | |
jQuery.each(usersString, function() { | |
usersArray[$(this).text()] = voucherLength; | |
}); | |
} | |
} | |
if (!storeVouchers) | |
{ | |
var mac = jNode.data('mac'); | |
if (typeof(mac) == "undefined") return; | |
mac = mac.toUpperCase(); | |
colorRowByVoucher(jNode, mac); | |
colorDataColumnsByPeriod(jNode); | |
addVoucherColumn(jNode, mac); | |
} | |
} | |
function colorRowByVoucher(jNode, mac) | |
{ | |
if (mac in myList) | |
{ | |
jNode.css ("background", "lawngreen"); // example | |
} | |
} | |
function colorDataColumnsByPeriod(jNode) | |
{ | |
var download = jNode.data('traffic_down'); | |
var upload = jNode.data('traffic_up'); | |
var total = download + upload; | |
if (total) // Check if valid number | |
{ | |
var GBs = total / 1E9; | |
var color; | |
switch (timePeriod) { | |
case "2hours": | |
if (GBs < 1) { | |
} | |
else if (GBs > 1 && GBs < 2) { | |
color = "Orange"; | |
} | |
else if (GBs > 2) { | |
color = "Red"; | |
} | |
break; | |
case "day": | |
if (GBs < 1) { | |
} | |
else if (GBs > 1 && GBs < 2) { | |
color = "Orange"; | |
} | |
else if (GBs > 2) { | |
color = "Red"; | |
} | |
break; | |
case "week": | |
if (GBs < 2.5) { | |
} | |
else if (GBs > 2.5 && GBs < 5) { | |
color = "Orange"; | |
} | |
else if (GBs > 5) { | |
color = "Red"; | |
} | |
break; | |
case "month": | |
if (GBs < 10) { | |
} | |
else if (GBs > 10 && GBs < 12.5) { | |
color = "Orange"; | |
} | |
else if (GBs > 12.5) { | |
color = "Red"; | |
} | |
break; | |
} | |
if (color !== null) | |
{ | |
jNode.children("td.traffic_down, td.traffic_up").css("background", color); | |
} | |
} | |
} | |
function addVoucherColumn(jNode, mac){ | |
var strToAdd = ""; | |
if (myList[mac]){ | |
strToAdd = myList[mac] + "hrs"; | |
} | |
$(jNode).find('td').eq(-2).after("<td>" + strToAdd + "</td>"); | |
} | |
var timePeriod; | |
function selectTimePeriod(jNode) { | |
timePeriod = $("option:selected", jNode).val(); | |
$(jNode).change(function() { | |
timePeriod = $("select#period option:selected").val(); | |
}); | |
} | |
function addClientsTableColumn(jNode) { | |
$(jNode).find('th').eq(-2).after("<th style='width: 150px'>Voucher<br />Length</th>"); | |
} | |
$(window).on("beforeunload", function(){ | |
if (storeVouchers) | |
{ | |
GM_setValue("FHRVActiveUsers", JSON.stringify(usersArray)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment