Advertisement
Guest User

Gif Skin Tampermonkey

a guest
Feb 11th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1.  
  2. 1
  3. 2
  4. 3
  5. 4
  6. 5
  7. 6
  8. 7
  9. 8
  10. 9
  11. 10
  12. 11
  13. 12
  14. 13
  15. 14
  16. 15
  17. 16
  18. 17
  19. 18
  20. 19
  21. 20
  22. 21
  23. 22
  24. 23
  25. 24
  26. 25
  27. 26
  28. 27
  29. 28
  30. 29
  31. 30
  32. 31
  33. 32
  34. 33
  35. 34
  36. 35
  37. 36
  38. 37
  39. 38
  40. 39
  41. 40
  42. 41
  43. 42
  44. 43
  45. 44
  46. 45
  47. 46
  48. 47
  49. 48
  50. 49
  51. 50
  52. 51
  53. 52
  54. 53
  55. 54
  56. 55
  57. 56
  58. 57
  59. 58
  60. 59
  61. 60
  62. 61
  63. 62
  64. 63
  65. 64
  66. 65
  67. 66
  68. 67
  69. 68
  70. 69
  71. 70
  72. 71
  73. 72
  74. 73
  75. 74
  76. 75
  77. 76
  78. 77
  79. 78
  80. 79
  81. 80
  82. 81
  83. 82
  84. 83
  85. 84
  86. 85
  87. 86
  88. 87
  89. 88
  90. 89
  91. 90
  92. 91
  93. 92
  94. 93
  95. 94
  96. 95
  97. 96
  98. 97
  99. 98
  100. 99
  101. 100
  102. // ==UserScript==
  103. // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
  104. // @name Gif Skin AgarplusV2
  105. // @namespace v2 Fix
  106. // @version 2.1
  107. // @description Changes your skin in agarplus using imgur album.
  108. // @author master2500 |v2 fix Ezybro
  109. // @match http*://agar.io
  110. // @include http://*agar.io/agarplus.io
  111. // @grant none
  112. // ==/UserScript==
  113.  
  114. //variables
  115. var sideContainer = '.side-container.left-side'; //container to append skin changer menu
  116. var leftContainer = '.forums'; //used to find left container
  117. var loadCheckInterval = 100; //interval to check if container has loaded
  118. var isPlaying = '#overlays'; //to check if player is playing
  119. var customSkin = '#skin_url'; //agarplus skin url field
  120. var playButton = 'button[data-itr="play"]'; //agarplus play button
  121. var skinChangerButton = '#skinChangerButton'; //button start/stop skin chanage
  122. var albumField = '#albumField'; //imgur skin album field
  123. var intervalField = '#intervalField'; //interval (ms)
  124. var imgurClientID = 'Client-ID 3d3ef891ffc63d7' //imgur application authentication id
  125. var current = 0; //current skin
  126. var mainInterval; //skin changer interval
  127.  
  128. //check if page loaded
  129. var ci = setInterval(function()
  130. {
  131. if ($(sideContainer).has(leftContainer).length)
  132. {
  133. clearInterval(ci);
  134. //inject skin changer panel
  135. $(sideContainer).has(leftContainer).append('<div class="agario-panel agario-side-panel agarioProfilePanel level forums"><input id="albumField" type="text" placeholder="Imgur skins album ID" class="form-control"></input><input id="intervalField" type="text" placeholder="Interval (ms)" class="form-control"><button id="skinChangerButton" class="btn btn-primary">Start</button></div>');
  136. //fill fields from storage
  137. $(albumField).val(localStorage.getItem('album'));
  138. $(intervalField).val(localStorage.getItem('interval'));
  139. //add event listener to button
  140. $(skinChangerButton).on('click', this, function()
  141. {
  142. //if start start if stop stop
  143. if ($(skinChangerButton).text() == 'Start')
  144. {
  145. //get images using imgur api
  146. $.ajax(
  147. {
  148. url: 'https://api.imgur.com/3/album/' + $(albumField).val() + '/images',
  149. type: 'GET',
  150. dataType: 'json',
  151. beforeSend: function(xhr)
  152. {
  153. xhr.setRequestHeader('Authorization', imgurClientID);
  154. },
  155. success: function(data)
  156. {
  157. //set to stop
  158. $(skinChangerButton).text('Stop');
  159. $(skinChangerButton).attr('style', 'background-color : red');
  160. //preload images into cache
  161. for (var i = 0; i < data.data.length; i++)
  162. {
  163. var img = new Image();
  164. img.src = data.data.link;
  165. }
  166. //save values to local storage for later use
  167. localStorage.setItem('album', $(albumField).val());
  168. localStorage.setItem('interval', $(intervalField).val());
  169. //set main interval for changing skin
  170. mainInterval = setInterval(function()
  171. {
  172. //loop trough the skins
  173. $(customSkin).val(data.data[current].link);
  174. if ($(isPlaying).css('display') == 'none')
  175. {
  176. $(playButton).trigger('onclick');
  177. }
  178. current++;
  179. if (current == data.data.length)
  180. {
  181. current = 0;
  182. }
  183. }, parseInt($(intervalField).val()));
  184. },
  185. error: function()
  186. {
  187. //log if ajax request fails
  188. console.log('Failed to fetch images from imgur.');
  189. }
  190. });
  191. }
  192. else
  193. {
  194. //set to start
  195. clearInterval(mainInterval);
  196. $(skinChangerButton).text('Start');
  197. $(skinChangerButton).attr('style', '');
  198. }
  199. });
  200. }
  201. }, loadCheckInterval);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement