Skip to content

Commit

Permalink
Added old version to support group members page until it's overhauled
Browse files Browse the repository at this point in the history
  • Loading branch information
ge-ku committed Jun 14, 2018
1 parent a0c6af3 commit fe58f92
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 2 deletions.
135 changes: 135 additions & 0 deletions checkbans-old.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// Javascript does not work well with integers greater than 53 bits precision... So we need
// to do our maths using strings.
function getDigit(x, digitIndex) {
return (digitIndex >= x.length) ? "0" : x.charAt(x.length - digitIndex - 1);
}
function prefixZeros(strint, zeroCount) {
var result = strint;
for (var i = 0; i < zeroCount; i++) {
result = "0" + result;
}
return result;
}
//Only works for positive numbers, which is fine in our use case.
function add(x, y) {
var maxLength = Math.max(x.length, y.length);
var result = "";
var borrow = 0;
var leadingZeros = 0;
for (var i = 0; i < maxLength; i++) {
var lhs = Number(getDigit(x, i));
var rhs = Number(getDigit(y, i));
var digit = lhs + rhs + borrow;
borrow = 0;
while (digit >= 10) {
digit -= 10;
borrow++;
}
if (digit === 0) {
leadingZeros++;
} else {
result = String(digit) + prefixZeros(result, leadingZeros);
leadingZeros = 0;
}
}
if (borrow > 0) {
result = String(borrow) + result;
}
return result;
}

function getId(friend) {
var steam64identifier = "76561197960265728";
var miniProfileId = friend.attributes.getNamedItem('data-miniprofile').value;
return add(steam64identifier, miniProfileId);
}

var friends = [].slice.call(document.querySelectorAll('#memberList .member_block, #memberManageList .member_block, .friendHolder, .friendBlock '));
var lookup = {};

friends.forEach(function(friend) {
var id = getId(friend);
if (!lookup[id]) {
lookup[id] = [];
}
lookup[id].push(friend);
});

function setVacation(player) {
var friendElements = lookup[player.SteamId];

friendElements.forEach(function(friend) {
var inGameText = friend.querySelector('.linkFriend_in-game');
var span = document.createElement('span');
span.style.fontWeight = 'bold';
span.style.display = 'block';

if (inGameText) {
var inGameTextSeparator = document.createTextNode(' - ');
inGameText.replaceChild(inGameTextSeparator, inGameText.querySelector('br'));
}

if (player.NumberOfVACBans || player.NumberOfGameBans) {
var text = '';

if (player.NumberOfGameBans) {
text += player.NumberOfGameBans + ' OW ban' + (player.NumberOfGameBans > 1 ? 's' : '');
}

if (player.NumberOfVACBans) {
text += (text === '' ? '' : ', ') + player.NumberOfVACBans + ' VAC ban' + (player.NumberOfVACBans > 1 ? 's' : '');
}
text += ' ' + player.DaysSinceLastBan + ' day' + (player.DaysSinceLastBan > 1 ? 's' : '') + ' ago.';

span.style.color = 'rgb(255, 73, 73)';
span.textContent = text;
} else if (greentext){
span.style.color = 'rgb(43, 203, 64)';
span.textContent = 'No Bans for this player.';
}

friend.querySelector('.friendSmallText').appendChild(span);
});
}

function onData(xmlHttp) {
if (xmlHttp.readyState === XMLHttpRequest.DONE && xmlHttp.status === 200) {
var data = JSON.parse(xmlHttp.responseText);
data.players.forEach(setVacation);
}
}

function makeApiCall(ids, apikey) {
var xmlHttp = new XMLHttpRequest();
//API only allows 100 steam ids at once.
var endpointRoot = 'https://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key='+apikey+'&steamids=';
var endpoint = endpointRoot + ids.join(',');

xmlHttp.onreadystatechange = function() { onData(xmlHttp); };
xmlHttp.open('GET', endpoint, true);
xmlHttp.send();
}

var defaultkeys = ["5DA40A4A4699DEE30C1C9A7BCE84C914",
"5970533AA2A0651E9105E706D0F8EDDC",
"2B3382EBA9E8C1B58054BD5C5EE1C36A"];
var greentext = true;
chrome.storage.sync.get(["customapikey", "greentext"], function(data) {
if (typeof data['greentext'] == 'undefined'){
chrome.storage.sync.set({
'greentext': true
});
} else {
greentext = data['greentext'];
}
if (typeof data['customapikey'] == 'undefined'){
var apikey = defaultkeys[Math.floor(Math.random() * 3)];
}else{
var apikey = data['customapikey'];
}
var ids = Object.keys(lookup);
while (ids.length > 0) {
var batch = ids.splice(0, 100);
makeApiCall(batch, apikey);
}
});
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Ban Checker for Steam",
"description": "Automatically check bans of people you recently played with, your friends, and group members.",
"version": "1.1.8.1",
"version": "1.2.0",
"icons": { "16": "icons/ow16.png",
"48": "icons/ow48.png",
"128": "icons/ow128.png" },
Expand All @@ -25,7 +25,7 @@
"matches": [ "*://steamcommunity.com/id/*/friends*", "*://steamcommunity.com/profiles/*/friends*" ]
},
{
"js": [ "checkbans.js"],
"js": [ "checkbans-old.js"],
"run_at": "document_end",
"matches": [ "*://steamcommunity.com/groups/*/members*" ]
},
Expand Down

0 comments on commit fe58f92

Please sign in to comment.