Advertisement
Guest User

Untitled

a guest
May 3rd, 2015
1,179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Agar Server Selector
  3. // @namespace
  4. // @version 1.0
  5. // @description Modifies the agar.io server select page to be useful.
  6. // @author Ununoctium118
  7. // @match http://agar.io
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. // Clear the dialog box
  12. var selector = $('#region');
  13.  
  14. // Load the server list
  15. var selected;
  16.  
  17. var regionTable = {
  18. 'US-Atlanta': 'US East',
  19. 'US-Fremont': 'US West',
  20. 'EU-London': 'Europe',
  21. 'JP-Tokyo': 'Japan',
  22. };
  23.  
  24. $.getJSON('http://m.agar.io/fullInfo', function(serverList) {
  25. var output = [];
  26. serverList.servers.sort(function (a, b) {
  27. var x = regionTable[a.region], y = regionTable[b.region];
  28. return ((x < y) ? - 1 : ((x > y) ? 1 : 0));
  29. });
  30. $.each(serverList.servers, function(index, server) {
  31. output.push('<option value="' + server.ip + '">' + regionTable[server.region] + ' (' + server.ip + ') (' + server.numPlayers + ' players)</option>');
  32. });
  33. selector.html(output.join(''));
  34. });
  35.  
  36.  
  37. // Add our extra onchangelistener
  38. selector.on('change', function() {
  39. selected = selector.val() + ':443';
  40. });
  41.  
  42.  
  43. // Intercept requests for m.agar.io and instead return our data.
  44. var realAjax = $.ajax;
  45. $.ajax = function() {
  46. if(arguments[0] == 'http://m.agar.io/') {
  47. var callback = arguments[1].success;
  48. // The selector callback probably hasn't run yet.
  49. // Really should use a promise or something here.
  50. setTimeout(function() {
  51. callback(selected);
  52. }, 10);
  53. } else {
  54. // Use irl ajax
  55. return realAjax.apply(this, arguments);
  56. }
  57. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement