Advertisement
Guest User

Untitled

a guest
Mar 7th, 2014
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1. /*
  2. // ==UserScript==
  3. // @name addressfinder
  4. // @namespace amDOGE
  5. // @include http*://boards.4chan.org/*
  6. // @version 1
  7. // @grant none
  8. // @run-at document-start
  9. // ==/UserScript==
  10. */
  11.  
  12. (function() {
  13. var $, $$, Main, c, d, tipSize, wait, walletType,
  14. __slice = [].slice;
  15.  
  16. d = document;
  17.  
  18. c = console;
  19.  
  20. $ = function(selector, root) {
  21. if (root == null) {
  22. root = d.body;
  23. }
  24. return root.querySelector(selector);
  25. };
  26.  
  27. $$ = function(selector, root) {
  28. if (root == null) {
  29. root = d.body;
  30. }
  31. return __slice.call(root.querySelectorAll(selector));
  32. };
  33.  
  34.  
  35. /*
  36. Use walletType to configure which wallet(s) to search for. Bitcoin (1), Dogecoin (D), Litecoin (L) and PandaCoin (P) are added by default.
  37. */
  38.  
  39. walletType = '1|D|L|P';
  40.  
  41.  
  42. /*
  43. Use tipSize to set a default amount to tip, ie. P: '1500'
  44. */
  45.  
  46. tipSize = {
  47. 1: '',
  48. D: '',
  49. L: '',
  50. P: ''
  51. };
  52.  
  53.  
  54. /*
  55. GET post size can be configured with x
  56. */
  57.  
  58. Main = {
  59. init: function() {
  60. this.catchAll = RegExp("(" + walletType + ")[A-Za-z0-9]{33}");
  61. this.pastebin = /pastebin\.com\/(?!u\/)(?:raw.php\?i=)?([a-zA-Z0-9]+)/i;
  62. this.thread = $('.thread');
  63. this.nodes = $$('.postContainer', this.thread);
  64. this.wallets = {};
  65. Main.findNodes(this.nodes);
  66. return Main.observe();
  67. },
  68. findNodes: function(nodes) {
  69. var email, emailText, href, key, node, searchable, _i, _len;
  70. for (_i = 0, _len = nodes.length; _i < _len; _i++) {
  71. node = nodes[_i];
  72. searchable = [];
  73. if (email = $('.useremail', node)) {
  74. key = 'email';
  75. href = email.href.trim();
  76. emailText = decodeURIComponent(href) || href;
  77. searchable.push({
  78. key: key,
  79. node: node,
  80. email: email,
  81. emailText: emailText
  82. });
  83. }
  84. Main.node(searchable);
  85. }
  86. },
  87. node: function(searchable) {
  88. var field, handler, id, isPastebin, key, node, text, _i, _len, _ref;
  89. if (!searchable[0]) {
  90. return;
  91. }
  92. for (_i = 0, _len = searchable.length; _i < _len; _i++) {
  93. field = searchable[_i];
  94. key = field.key, node = field.node;
  95. text = field[key + 'Text'];
  96. id = node.id.slice(2);
  97. if (isPastebin = (_ref = text.match(Main.pastebin)) != null ? _ref[1] : void 0) {
  98. Main.getPastebin(isPastebin, id);
  99. handler = isPastebin;
  100. } else {
  101. if (!(handler = Main.parseHandler(text))) {
  102. continue;
  103. }
  104. }
  105. Main.assign(id, handler);
  106. node = field[key];
  107. node.parentNode.parentNode.parentNode.addEventListener('mouseover', Main.swapHandler);
  108. }
  109. },
  110. parseWalletType: function(short) {
  111. var coinType;
  112. coinType = (function() {
  113. switch (short) {
  114. case '1':
  115. return 'bit';
  116. case 'D':
  117. return 'doge';
  118. case 'L':
  119. return 'lite';
  120. case 'P':
  121. return 'panda';
  122. }
  123. })();
  124. return coinType + 'coin';
  125. },
  126. parseHandler: function(text) {
  127. var address, amount, handler, short, walletAddress;
  128. if (!(address = text.match(this.catchAll))) {
  129. return;
  130. }
  131. walletAddress = address[0], short = address[1];
  132. walletType = this.parseWalletType(short);
  133. handler = "" + walletType + ":" + walletAddress;
  134. if (amount = tipSize[short]) {
  135. handler += "?amount=" + amount;
  136. }
  137. return handler;
  138. },
  139. getPastebin: function(paste, id) {
  140. var url, xhr;
  141. url = "http://pastebin.com/raw.php?i=" + paste;
  142. xhr = new XMLHttpRequest();
  143. xhr.open('get', url, true);
  144. id = id;
  145. xhr.onloadend = function() {
  146. var _ref;
  147. if ((_ref = this.status) !== 200 && _ref !== 304) {
  148. return;
  149. }
  150. return Main.assign(id, Main.parseHandler(this.response));
  151. };
  152. return xhr.send(null);
  153. },
  154. assign: function(id, handler) {
  155. return this.wallets[id] = handler;
  156. },
  157. swapHandler: function(e) {
  158. var node, wallet;
  159. wallet = Main.wallets[this.id.slice(1)];
  160. node = $('.useremail', this);
  161. node.href = wallet;
  162. return this.removeEventListener('mouseover', Main.swapHandler);
  163. },
  164. observe: function() {
  165. var config, observer;
  166. Main.observer = observer = new MutationObserver(function(mutations) {
  167. var mutation, node, _i, _len, _ref;
  168. for (_i = 0, _len = mutations.length; _i < _len; _i++) {
  169. mutation = mutations[_i];
  170. if ((node = (_ref = mutation.addedNodes) != null ? _ref[0] : void 0).nodeName !== 'DIV') {
  171. return;
  172. }
  173. Main.findNodes([node]);
  174. }
  175. });
  176. config = {
  177. attributes: true,
  178. childList: true,
  179. characterData: false
  180. };
  181. return observer.observe(Main.thread, config);
  182. }
  183. };
  184.  
  185. (wait = function() {
  186.  
  187. /*
  188. Why does @run-at exist? No one knows.
  189. */
  190. if (d != null ? d.body : void 0) {
  191. return Main.init();
  192. } else {
  193. return setTimeout(wait, 30);
  194. }
  195. })();
  196.  
  197. }).call(this);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement