Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.38 KB | None | 0 0
  1. // ==UserScript==
  2. // @name (Bakery)
  3. // @namespace g
  4. // @version 1.0
  5. // @description Automatically highlights profitable items in Neopets stores.
  6. // @author Me
  7. // @match http://www.neopets.com/objects.phtml?type=shop&obj_type=15
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.  
  13. var patterns = [], classes = [];
  14.  
  15. /* The following define the classes of words. If the first
  16. character of the specification is "=", the match will be
  17. case-sensitive, otherwise it will be case-insensitive.
  18. The specification is a regular expression, and should
  19. contain metacharacters to handle variant spellings and
  20. plurals. Any grouping within these patterns *must* be done
  21. with a (?: ... ) specification to avoid messing up the
  22. capture from the text string.
  23.  
  24. You may add additional categories as you wish, but be sure to
  25. declare their rendering in the style definition below. */
  26.  
  27. // Rendering styles for our various word classes
  28.  
  29. addGlobalStyle('span.blank { background-color: #ffffff; color: #ffffff } ' +
  30. 'span.yellow { background-color: #000000; color: #fdff00; border-style: dotted; font-size: 13px; } ' +
  31. 'span.green { background-color: #FFA500; color: #ffffff; border-style: dotted; border-color: black; font-size: 25px; } ' +
  32. 'span.red { background-color: #ff1a00; color: #000000; border-style: dotted; font-size: 18px; } ' );
  33.  
  34. // BLANK items. Items in this list will appear as white on white and be functionally invisible.
  35.  
  36. defwords([
  37. "x"
  38. ], "blank");
  39.  
  40. // RED words. These items are black background with red text.
  41.  
  42. defwords([
  43. "Doglefox Bread Creature",
  44. "Faerie Aisha Cake",
  45. "Kacheek Fruit Salad Sandwich",
  46. "Electric Wocky Bread",
  47. "Irate Zafara Claw",
  48. "Hula Girl Usuki Cake",
  49. "Bread",
  50. "Kacheek Baby Cabbage Sandwiches",
  51. "Ultimate Grilled Cheese Sandwich",
  52. "Lime Chomby Cake",
  53. "Haiku Dessert",
  54. "Faerie Acara Pretzel",
  55. "Scamander Cookies",
  56. "Inflation Notice Borovan Cupcake",
  57. "Borovan Cupcake",
  58. "Babaa Cake",
  59. "Hostile Quiche",
  60. "Disco Elephante Toaster Cakes",
  61. "Desert Dessert",
  62. "Mini Lemon and Lime Birthday Cake",
  63. "Cloud Usul Iced Buns",
  64. "Mini Raspberry Birthday Cake",
  65. "Kacheek Ombus Fruit Sandwich",
  66. "Sugar Nerkmid Biscuit",
  67. "Angry Cinnamon Roll",
  68. "Slice Of New Year Cake"
  69. ],
  70. "red");
  71.  
  72. // YELLOW words. Black background, yellow text.
  73.  
  74. defwords([
  75. "Snowy Pancakes",
  76. "Mini Blueberry Birthday Cake",
  77. "Cranky Croissant",
  78. "Grey Grundo Muffin",
  79. "Transparaberry Hot Cross Buns",
  80. "Mini Chocolate Birthday Cake",
  81. "Fire Mynci Cake",
  82. "Madeleine Sandwich Cookies",
  83. "Illusen Waffle",
  84. "Carrot Shoyru Muffin",
  85. "Red Velvet Cake",
  86. "Choccy Chip Skeith Biscuit",
  87. "Pink Fyora Gingerbread Castle",
  88. "Chocolate Chip Nerkmid Biscuit",
  89. "Hazelnut Banana Crepe",
  90. "Blue Paint Brush Cookie",
  91. "Blue Paint Brush Cookie",
  92. "Strawberry Shimmer Cake",
  93. "Colourful Cybunny Cookie",
  94. "Red Paint Brush Cookie",
  95. "Massive White Aisha Cake",
  96. "Slice of Neopets Birthday Cake",
  97. "Tiered Neopets 8th Birthday Cake",
  98. "Chocolate Raspberry Ganache Cake",
  99. "Kass Kakes",
  100. "Grilled Cheese Chomby Sandwich",
  101. "Chocolate Orange Ganache Cake",
  102. "Super Deluxe Maraquan Victory Cake",
  103. "Banana Split Swiss Roll",
  104. "Bubble Cake",
  105. "Pteri Seed Cake",
  106. "Snowberry Quiggle Cake",
  107. "Strawberry Skeith Biscuit",
  108. "Grunion Fruit Krawk Cake",
  109. "Toast A La King",
  110. "Minimalist Cake"
  111. ],
  112. "yellow");
  113.  
  114. // GREEN words. Black background, green text.
  115.  
  116. defwords([
  117. "Chia Cake",
  118. "Grapefruit Cake",
  119. "Borovan Layered Cake",
  120. "Inflation Notice Meepit Muffins",
  121. "Meepit Muffins",
  122. "Stack It High Cake",
  123. "Chocolate Cream Biscuit",
  124. "Buttered Juppie Waffle",
  125. "Chokato Deluxe Aisha Cake",
  126. "Dargil Meat Mince Pie",
  127. "Gooseberry Crepe",
  128. "Pterimisu",
  129. "Red Kacheek Cupcake",
  130. "Blueberry Deluxe Cake",
  131. "Chocolate Chip Quiggle Cookie",
  132. "Inflation Notice Minty Eyrie Cookie",
  133. "Minty Eyrie Cookie",
  134. "Inflation Notice Robot Kacheek Cookie",
  135. "Robot Kacheek Cookie",
  136. "Fyora Spider Cake",
  137. "Speckled Scorchio Cookie",
  138. "Spotted Cybunny Cookie",
  139. "Spotted Mynci Sticky Bun",
  140. "Pink Elephante Cookie",
  141. "Disco JubJub Cupcake",
  142. "Strawberry Usul Cake",
  143. "Gold Kyrii Cookie",
  144. "Gold Usul Cookie",
  145. "Green Kacheek Cupcake",
  146. "Gold Blumaroo Cookie",
  147. "Ruler Biscuits",
  148. "Butterlicious Bun",
  149. "Strawberry JubJub Cupcake",
  150. "Cloud Bruce Muffin",
  151. "Fyora Cookies",
  152. "Beach Fun Usuki Cupcakes",
  153. "Chocolate Stuffed Pastry",
  154. "Vionanna Mince Pie"
  155. ],
  156. "green");
  157.  
  158. // Add one or more words to the dictionary with a specified class
  159.  
  160. function defwords(words, which_class) {
  161. for (var i = 0; i < words.length; i++) {
  162. var w = words[i].replace(/^=/, "");
  163. patterns.push(new RegExp("([^a-zA-Z])(" + w + ")([^a-zA-Z])",
  164. words[i].match(/^=/) ? "g" : "gi"));
  165. classes.push(which_class);
  166. }
  167. }
  168.  
  169. // Quote HTML metacharacters in body text
  170.  
  171. function quoteHTML(s) {
  172. s = s.replace(/&/g, "&amp;");
  173. s = s.replace(/</g, "&lt;");
  174. s = s.replace(/>/g, "&gt;");
  175. return s;
  176. }
  177.  
  178. // Add one or more CSS style rules to the document
  179.  
  180. function addGlobalStyle(css) {
  181. var head, style;
  182. head = document.getElementsByTagName('head')[0];
  183. if (!head) {
  184. return;
  185. }
  186. style = document.createElement('style');
  187. style.type = 'text/css';
  188. style.innerHTML = css;
  189. head.appendChild(style);
  190. }
  191.  
  192. // Apply highlighting replacements to a text sequence
  193.  
  194. var curpat; // Hidden argument to repmatch()
  195. var changes; // Number of changes made by repmatch()
  196.  
  197. function repmatch(matched, before, word, after) {
  198. changes++;
  199. return before + '<span class="' + classes[curpat] + '">' + word + '</span>' + after;
  200. }
  201.  
  202. function highlight(s) {
  203. s = " " + s;
  204. for (curpat = 0; curpat < patterns.length; curpat++) {
  205. s = s.replace(patterns[curpat],
  206. repmatch);
  207. }
  208. return s.substring(1);
  209. }
  210.  
  211. // We only modify HTML/XHTML documents
  212. if (document.contentType &&
  213. (!(document.contentType.match(/html/i)))) {
  214. return;
  215. }
  216.  
  217. // Highlight words in body copy
  218.  
  219. var textnodes = document.evaluate("//body//text()", document, null,
  220. XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  221.  
  222. for (var i = 0; i < textnodes.snapshotLength; i++) {
  223. var node = textnodes.snapshotItem(i);
  224. /* Test whether this text node appears within a
  225. <style>, <script>, or <textarea> container.
  226. If so, it is not actual body text and must
  227. be left alone to avoid wrecking the page. */
  228. if (node.parentNode.tagName != "STYLE" &&
  229. node.parentNode.tagName != "TEXTAREA" &&
  230. node.parentNode.tagName != "SCRIPT") {
  231. /* Many documents have large numbers of empty text nodes.
  232. By testing for them, we avoid running all of our
  233. regular expressions over a target which they can't
  234. possibly match. */
  235. if (!(node.data.match(/^\s*$/))) {
  236. var s = " " + node.data + " ";
  237. changes = 0;
  238. var d = highlight(quoteHTML(s));
  239. if (changes > 0) {
  240. var rep = document.createElement("span");
  241. rep.innerHTML = d; //.substring(1, d.length - 1);
  242. node.parentNode.replaceChild(rep, node);
  243. }
  244. }
  245. }
  246. }
  247.  
  248. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement