Advertisement
Guest User

Untitled

a guest
May 1st, 2015
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. javascript:(function(){
  2. // Javascript does not work well with integers greater than 53 bits precision... So we need
  3. // to do our maths using strings.
  4. function getDigit(x, digitIndex) {
  5. return (digitIndex >= x.length) ? "0" : x.charAt(x.length - digitIndex - 1);
  6. }
  7. function prefixZeros(strint, zeroCount) {
  8. var result = strint;
  9. for (var i = 0; i < zeroCount; i++) {
  10. result = "0" + result;
  11. }
  12. return result;
  13. }
  14. //Only works for positive numbers, which is fine in our use case.
  15. function add(x, y) {
  16. var maxLength = Math.max(x.length, y.length);
  17. var result = "";
  18. var borrow = 0;
  19. var leadingZeros = 0;
  20. for (var i = 0; i < maxLength; i++) {
  21. var lhs = Number(getDigit(x, i));
  22. var rhs = Number(getDigit(y, i));
  23. var digit = lhs + rhs + borrow;
  24. borrow = 0;
  25. while (digit >= 10) {
  26. digit -= 10;
  27. borrow++;
  28. }
  29. if (digit === 0) {
  30. leadingZeros++;
  31. } else {
  32. result = String(digit) + prefixZeros(result, leadingZeros);
  33. leadingZeros = 0;
  34. }
  35. }
  36. if (borrow > 0) {
  37. result = String(borrow) + result;
  38. }
  39. return result;
  40. }
  41.  
  42. function getId(friend) {
  43. var steam64identifier = "76561197960265728";
  44. var miniProfileId = friend.attributes.getNamedItem('data-miniprofile').value;
  45. return add(steam64identifier, miniProfileId);
  46. }
  47.  
  48. var friends = [].slice.call(document.querySelectorAll('.friendHolder, .friendBlock'));
  49. var lookup = {};
  50.  
  51. friends.forEach(function(friend) {
  52. var id = getId(friend);
  53. if (!lookup[id]) {
  54. lookup[id] = [];
  55. }
  56. lookup[id].push(friend);
  57. });
  58.  
  59. function setVacation(player) {
  60. var friendElements = lookup[player.SteamId];
  61.  
  62. friendElements.forEach(function(friend) {
  63. var inGameText = friend.querySelector('.linkFriend_in-game');
  64. var span = document.createElement('span');
  65. span.style.fontWeight = 'bold';
  66. span.style.display = 'block';
  67.  
  68. if (inGameText) {
  69. inGameText.innerHTML = inGameText.innerHTML.replace(/<br ?\/?>/, ' - ');
  70. }
  71.  
  72. if (player.NumberOfVACBans || player.NumberOfGameBans) {
  73. var text = '';
  74.  
  75. if (player.NumberOfGameBans) {
  76. text += player.NumberOfGameBans + ' OW bans';
  77. }
  78.  
  79. if (player.NumberOfVACBans) {
  80. text += (text === '' ? '' : ', ') +
  81. player.NumberOfVACBans + ' VAC bans';
  82. }
  83. text += ' ' + player.DaysSinceLastBan + ' days ago.';
  84.  
  85. span.style.color = 'rgb(255, 73, 73)';
  86. span.innerHTML = text;
  87. } else {
  88. span.style.color = 'rgb(43, 203, 64)';
  89. span.innerHTML = 'No Bans for this player.';
  90. }
  91.  
  92. friend.querySelector('.friendSmallText').appendChild(span);
  93. });
  94. }
  95.  
  96. function onData(xmlHttp) {
  97. if (xmlHttp.readyState === XMLHttpRequest.DONE && xmlHttp.status === 200) {
  98. var data = JSON.parse(xmlHttp.responseText);
  99. data.players.forEach(setVacation);
  100. }
  101. }
  102.  
  103. function makeApiCall(ids) {
  104. var xmlHttp = new XMLHttpRequest();
  105. //API only allows 100 steam ids at once.
  106. var endpointRoot = 'https://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=F6F90A461E30D38AB4AE8AADB5AD8658&steamids=';
  107. var endpoint = endpointRoot + ids.join(',');
  108.  
  109. xmlHttp.onreadystatechange = function() { onData(xmlHttp); };
  110. xmlHttp.open('GET', endpoint, true);
  111. xmlHttp.send();
  112. }
  113.  
  114. var ids = Object.keys(lookup);
  115.  
  116. while (ids.length > 0) {
  117. var batch = ids.splice(0, 100);
  118. makeApiCall(batch);
  119. }
  120. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement