Advertisement
Guest User

Untitled

a guest
May 12th, 2021
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Margonem Profile Online
  3. // @version 1.1
  4. // @author Arth/Szemkel
  5. // @match http*://www.margonem.pl/profile/view,*
  6. // @match http*://new.margonem.pl/profile/view,*
  7. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js
  8. // @grant GM_xmlhttpRequest
  9. // @connect margonem.pl
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. var characters = [];
  15. var $statsBody = null;
  16. var worldsOnline = {};
  17.  
  18. var accountOnline = false;
  19.  
  20. var onlineReady = false;
  21. var charactersReady = false;
  22.  
  23. GM_xmlhttpRequest({
  24. method: "GET",
  25. url: "http://www.margonem.pl/stats",
  26. onload: function(response) {
  27. $statsBody = $(response.responseText);
  28. onlineReady = true;
  29. check();
  30. }
  31. });
  32.  
  33. document.addEventListener('DOMContentLoaded', function() {
  34. loadCharacters();
  35. });
  36.  
  37. function loadCharacters() {
  38. var $stats = $('.character-list li.char-row');
  39.  
  40. $stats.each(function(i, e) {
  41. var name = $(e).children('input.chnick')[0].value;
  42. var world = $(e).children('input.chworld')[0].value;
  43. characters.push({
  44. name: name,
  45. world: world,
  46. $e: $(e)
  47. });
  48.  
  49. if (i == $stats.length - 1) {
  50. charactersReady = true;
  51. check();
  52. }
  53. });
  54. }
  55.  
  56. function check() {
  57. if (charactersReady && onlineReady) start();
  58. }
  59.  
  60. function start() {
  61. for (var i in characters) {
  62.  
  63. if (!worldsOnline[characters[i].world]) loadWorldOnline(characters[i].world);
  64.  
  65. if (isCharacterOnline(characters[i].name, characters[i].world)) {
  66. accountOnline = true;
  67. characters[i].$e.find('.char-description .character-name').html(characters[i].name+ ' <span style="color: green; font-weight: bold;">online</span>');
  68. } else {
  69. characters[i].$e.find('.char-description .character-name').html(characters[i].name+ ' <span style="color: gray;">offline</span>');
  70. }
  71. }
  72.  
  73. if (accountOnline) {
  74. $('.profile-header span').html($('.profile-header h2 span').text()+ ' <span style="color: green; float: right;">(online)</span>')
  75.  
  76. }
  77. }
  78.  
  79. function loadWorldOnline(world) {
  80. worldsOnline[world] = $statsBody.find('.'+world.toLowerCase()+'-popup .news-body').text().trim().split(', ');
  81. }
  82.  
  83. function isCharacterOnline(name, world) {
  84. return worldsOnline[world].indexOf(name) >= 0;
  85. }
  86. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement