Advertisement
Guest User

Untitled

a guest
Jul 29th, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.67 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Punch-a-user
  3. // @namespace Manishearth
  4. // @description Allow you to summon Commander Keen and have him punch users
  5. // @include http://stackoverflow.com/*
  6. // @include http://serverfault.com/*
  7. // @include http://superuser.com/*
  8. // @include http://meta.stackoverflow.com/*
  9. // @include http://meta.serverfault.com/*
  10. // @include http://meta.superuser.com/*
  11. // @include http://stackapps.com/*
  12. // @include http://*.stackexchange.com/*
  13. // @include http://askubuntu.com/*
  14. // @include http://meta.askubuntu.com/*
  15. // @include http://answers.onstartups.com/*
  16. // @include http://meta.answers.onstartups.com/*
  17. // @include http://mathoverflow.net/*
  18. // @include http://area51.stackexchange.com/proposals/*
  19. // @exclude http://chat.*/*
  20. // @author Manish Goregaokar
  21.  
  22. // ==/UserScript==
  23. // Thanks to Shog9 for this idea for making the script work in both
  24. // Chrome and Firefox:
  25. // http://meta.stackoverflow.com/46562
  26.  
  27. // Heavily modified version of http://userscripts.org/scripts/review/70678. Thanks, balpha.
  28.  
  29.  
  30. function with_jquery(f) {
  31. var script = document.createElement("script");
  32. script.type = "text/javascript";
  33. script.textContent = "(" + f.toString() + ")(jQuery)";
  34. document.body.appendChild(script);
  35. };
  36.  
  37. with_jquery(function($) {
  38. sprites = {
  39. keen_l_fall: { "background-position": "0 0", width: "44px", height: "62px" } ,
  40. keen_l_fall_shoot: { "background-position": "0 -112px", width: "64px", height: "62px" } ,
  41. keen_l_pogo: { "background-position": "0 -224px", width: "32px", height: "58px" } ,
  42. keen_moon_0: { "background-position": "0 -332px", width: "32px", height: "64px" } ,
  43. keen_moon_1: { "background-position": "0 -446px", width: "40px", height: "64px" } ,
  44. keen_r_fall: { "background-position": "0 -560px", width: "48px", height: "62px" } ,
  45. keen_r_walk_0: { "background-position": "0 -672px", width: "34px", height: "64px" } ,
  46. keen_r_walk_1: { "background-position": "0 -786px", width: "38px", height: "64px" } ,
  47. keen_r_walk_2: { "background-position": "0 -900px", width: "32px", height: "64px" } ,
  48. keen_r_walk_3: { "background-position": "0 -1014px", width: "40px", height: "64px" }
  49. };
  50. imageurl = "http://i.imgur.com/oGHU0.gif";
  51. never_used_except_to_preload_the_image = $("<img src='" + imageurl + "'>");
  52.  
  53. function make_keen(keen, votecount)
  54. {
  55.  
  56. keen.sprite = function(name) {keen.css(sprites[name]);}
  57. keen.votecount = votecount;
  58. keen.sig = votecount.parents('.user-info,.gravatar');
  59.  
  60. keen.step = 0;
  61. keen.walking = false;
  62. keen.walk = function()
  63. {
  64. if (keen.walking)
  65. {
  66. keen.sprite("keen_r_walk_" + keen.step);
  67. keen.step = (keen.step + 1) % 4;
  68. setTimeout(keen.walk, 250);
  69. }
  70.  
  71. };
  72. keen.shot = $("<div></div>").addClass("shot").css(
  73. {"position": "absolute", "top": "100px", "left": "200px",
  74. "background": "url(" + imageurl + ") no-repeat top left",
  75. "width": "32px", "height": "32px", "z-index": 1234}
  76. ).prependTo($("#content")).hide();
  77. keen.shot.stage = function(i)
  78. {
  79. x = 0;
  80. y = -(70 + 110*i + ((i < 3) ? 0 : 15));
  81. keen.shot.css({"background-position": x + " " + y + "px"})
  82. keen.shot.curstage = i
  83. }
  84. keen.shot.explode = function(i)
  85. {
  86. if (keen.shot.curstage < 5)
  87. {
  88. keen.shot.stage(keen.shot.curstage + 1)
  89. setTimeout(keen.shot.explode, 100)
  90. }
  91. else
  92. {
  93. keen.shot.hide()
  94. }
  95. }
  96.  
  97. keen.fall_in = function()
  98. {
  99. keen.sprite("keen_l_fall");
  100. keen.css({top: keen.y_of(keen.votecount) - 600, left: keen.x_of(keen.votecount) + 750});
  101. keen.show();
  102. keen.animate({top: keen.y_of(keen.votecount) + 300, left: keen.x_of(keen.votecount) + 650}, 2000, "linear", keen.fall_pogo);
  103. };
  104. keen.fall_pogo = function()
  105. {
  106. keen.sprite("keen_l_pogo");
  107. keen.animate({top: keen.y_of(keen.votecount) + 525, left: keen.x_of(keen.votecount) + 625}, 500, "linear", keen.jump_pogo);
  108. };
  109. keen.jump_pogo = function()
  110. {
  111. keen.sprite("keen_l_pogo");
  112. keen.animate({top: keen.y_of(keen.votecount) - 35, left: keen.x_of(keen.votecount) + 200}, 1000, "swing", keen.fall_to_bottom);
  113. setTimeout(function() {keen.sprite("keen_l_fall_shoot");}, 500);
  114. };
  115. keen.shoot = function()
  116. {
  117. keen.shot.stage(0);
  118. keen.shot.css({"top": keen.position().top, "left": keen.position().left - 20});
  119. keen.shot.animate({left: keen.x_of(keen.votecount) + 5}, 300, "linear", keen.shot.explode);
  120. keen.shot.show()
  121.  
  122. }
  123. keen.fall_to_bottom = function()
  124. {
  125. keen.shoot()
  126. keen.sprite("keen_l_fall");
  127. keen.animate({top: keen.y_of(keen.sig) + keen.sig.height() - keen.height() + 5 , left: keen.x_of(keen.votecount) + 175}, 1000, "swing", keen.walk_to_sig);
  128. };
  129. keen.walk_to_sig = function()
  130. {
  131. keen.walking = true;
  132. keen.walk();
  133. keen.animate({left: keen.x_of(keen.sig) - 50}, 2000, "linear", keen.moon_0);
  134. };
  135. keen.moon_0 = function()
  136. {
  137. keen.walking = false;
  138. keen.sprite("keen_moon_0");
  139. setTimeout(keen.moon_1, 500);
  140. };
  141. keen.moon_1 = function()
  142. {
  143. keen.walking = false;
  144. keen.sprite("keen_moon_1");
  145. setTimeout(keen.moon_2, 1000);
  146. };
  147. keen.moon_2 = function()
  148. {
  149. keen.walking = false;
  150. keen.sprite("keen_moon_0");
  151. setTimeout(keen.walk_away, 500)
  152. };
  153. keen.walk_away = function()
  154. {
  155. keen.walking = true;
  156. keen.walk();
  157. keen.animate({left: keen.x_of(keen.sig) + keen.sig.width() + 20}, 1500, "linear", keen.fall_out);
  158. };
  159. keen.fall_out = function()
  160. {
  161. keen.walking = false;
  162. keen.sprite("keen_l_fall");
  163. keen.animate({top: keen.y_of(keen.sig) + 2000}, 2000, "swing", keen.done);
  164. };
  165. keen.done = function() {keen.hide()}
  166.  
  167. keen.y_of = function(elem)
  168. {
  169. return elem.offset().top - keen.offset().top + keen.position().top
  170. };
  171. keen.x_of = function(elem)
  172. {
  173. return elem.offset().left - keen.offset().left + keen.position().left
  174. };
  175.  
  176. return keen;
  177. }
  178. do_the_deed = function()
  179. {
  180. keen = $("<div></div>").addClass("keen").css(
  181. {"position": "absolute", "top": "100px", "left": "200px",
  182. "background": "url(" + imageurl + ") no-repeat top left",
  183. "width": 48, "height": 64, "z-index": 1234}
  184. ).prependTo($("#content")).hide();
  185. keen = make_keen(keen, $(this))
  186. keen.fall_in()
  187. };
  188. $('<br>').appendTo('[class^=gravatar]:has(img) div:first');
  189. $('<a href="javascript:void(0)">Punch</a>').click(do_the_deed).mouseover(function(){return false;}).appendTo('[class^=user-gravatar]:has(img),[class^=gravatar]:has(img) div:first')
  190.  
  191.  
  192.  
  193. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement