Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.08 KB | None | 0 0
  1. // ==UserScript==
  2. // @name (Choco)
  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=14
  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. "Adorably Pink Lollypop",
  44. "Inflation Notice Caramel and Custard Drops",
  45. "Caramel and Custard Drops",
  46. "Gummy Green Grundo",
  47. "Milk Chocolate Orange",
  48. "Pink Quiggle Candy Floss",
  49. "Angry Candy",
  50. "Hazelnut Whirl",
  51. "Striped Cybunny Lollypop",
  52. "Cloud Kougra Lollypop",
  53. "Sugar Tonu Skull",
  54. "Usukicon Y10 Gummies",
  55. "Orange Blumaroo Lollypop",
  56. "Yummy Drops",
  57. "Holiday Bell Chocolate Advent Calendar",
  58. "Creamy Choccywhip",
  59. "Scorchio Cotton Candy",
  60. "Chocolate Dr Sloth",
  61. "Cherry Meerca Gobstopper",
  62. "Neopets 8th Birthday Lollypop",
  63. "Omnipotent Onion Grarrl Gobstopper",
  64. "Peachpa Easter Negg",
  65. "Spooky Flying Doughnut",
  66. "Snowflake Chocolate Advent Calendar",
  67. "Chocolate Cybunny Negg",
  68. "Strawberry Swirl Easter Negg",
  69. "Plushie Mynci Lollypop",
  70. "Super Spicy Jelly Beans",
  71. "Fruity Faerie Easter Negg",
  72. "Combomelon Easter Negg",
  73. "Dancing Daisy Easter Negg",
  74. "Draik Sugar Skull",
  75. "Choccy Corn",
  76. "Chocolate Peach",
  77. "Lovely Lime Easter Negg",
  78. "Chocolate Maractite Coins",
  79. "Large Swirly Chocolate Cybunny",
  80. "Lemon Sherbert Easter Negg",
  81. "Gnorbu Gum",
  82. "Orange Chocolate Gelert",
  83. "Cherry Mootix Lollypop",
  84. "Orange Scoach Lolly",
  85. "Apple and Custard Drops",
  86. "King Skarl Candy",
  87. "Usuki Mints",
  88. "Usukicon Y9 Hard Candy",
  89. "Kikopop"
  90. ],
  91. "red");
  92.  
  93. // YELLOW words. Black background, yellow text.
  94.  
  95. defwords([
  96. "Bullseyes",
  97. "Mint Chocolate Peophin",
  98. "Minty Choccywhip",
  99. "Neopia Lollypop",
  100. "Jazzmosis Seasonal Candy Cane",
  101. "Halloween Aisha Fizzbomb",
  102. "Cherry Aboogala Lolly",
  103. "Neverending Jar of Jellybeans",
  104. "Seasonal Dr. Sloth Truffles",
  105. "Sugar Moehog Skull",
  106. "Artificially Flavoured Banana Snacks",
  107. "Banana Jelly Flotsam",
  108. "Chocolate Jeran",
  109. "Milk Chocolate Uni",
  110. "King Altador Pop",
  111. "Grape Gummy Slorg",
  112. "Kau Sundae",
  113. "Miniature Chocolate Chocolate Factory",
  114. "Kougra Sugar Skull",
  115. "Dark Chocolate Skeith",
  116. "Rainbow Twist Lollipop",
  117. "Gnorbu Lollipop",
  118. "Lost City Lanes Lime Gobstopper"
  119. ],
  120. "yellow");
  121.  
  122. // GREEN words. Black background, green text.
  123.  
  124. defwords([
  125. "Lemon and Lime Easter Negg",
  126. "Rainbow Candy Floss",
  127. "Pretty Pink Easter Negg",
  128. "Strawberries and Cream Easter Negg",
  129. "Apple Moquot Lollypop",
  130. "Inflation Notice Spotted Easter Negg",
  131. "Spotted Easter Negg",
  132. "Chocolate Crown of the Faeries",
  133. "Luxury Chocolate Easter Negg",
  134. "Candy Cane Chocolate Advent Calendar",
  135. "Inflation Notice Chocolate Orange Easter Negg",
  136. "Chocolate Orange Easter Negg",
  137. "Deluxe Strawberry Toffee Chokato",
  138. "Inflation Notice Fishy Delight Grarrl Gobstopper",
  139. "Fishy Delight Grarrl Gobstopper",
  140. "Inflation Notice Milk Chocolate Birthday Nova",
  141. "Milk Chocolate Birthday Nova",
  142. "Gummy Speckled Scorchio",
  143. "White Chocolate Birthday Nova",
  144. "Gummy Robot Mynci",
  145. "Holly Bonbons",
  146. "Mega Ultra Strawberry Fondant",
  147. "Lemon 9th Birthday Lollipop",
  148. "Marshmallow Plumpy",
  149. "Gold Shoyru Lollypop",
  150. "Plushie JubJub Lollypop",
  151. "Speckled Acara Lollypop",
  152. "Pink Bruce Lollypop",
  153. "Plushie Wocky Lollypop",
  154. "Blueberry 9th Birthday Lollipop",
  155. "Chocolate Stamp",
  156. "Usuki Lollypop",
  157. "ErgyFruit Jelly Beans",
  158. "Halloween Kacheek Chocolate Lollypop",
  159. "Chocolate Ruki Kit",
  160. "Gummy Pink Elephante",
  161. "Gummy Spotted Cybunny",
  162. "Neotruffle",
  163. "Inflation Notice Starry Grundo Lollypop",
  164. "Starry Grundo Lollypop",
  165. "Mynci Halloween Caramel Apple",
  166. "Illusen Jelly Beans",
  167. "Cinnamon Scorchio Lollypop",
  168. "Chocolate Crown of Sinsi",
  169. "Mynci Mallows",
  170. "Orange Lightmite Lollypop",
  171. "Grape 9th Birthday Lollipop",
  172. "Neopets 8th Birthday Candies",
  173. "Chocolate Advent Calendar"
  174. ],
  175. "green");
  176.  
  177. // Add one or more words to the dictionary with a specified class
  178.  
  179. function defwords(words, which_class) {
  180. for (var i = 0; i < words.length; i++) {
  181. var w = words[i].replace(/^=/, "");
  182. patterns.push(new RegExp("([^a-zA-Z])(" + w + ")([^a-zA-Z])",
  183. words[i].match(/^=/) ? "g" : "gi"));
  184. classes.push(which_class);
  185. }
  186. }
  187.  
  188. // Quote HTML metacharacters in body text
  189.  
  190. function quoteHTML(s) {
  191. s = s.replace(/&/g, "&amp;");
  192. s = s.replace(/</g, "&lt;");
  193. s = s.replace(/>/g, "&gt;");
  194. return s;
  195. }
  196.  
  197. // Add one or more CSS style rules to the document
  198.  
  199. function addGlobalStyle(css) {
  200. var head, style;
  201. head = document.getElementsByTagName('head')[0];
  202. if (!head) {
  203. return;
  204. }
  205. style = document.createElement('style');
  206. style.type = 'text/css';
  207. style.innerHTML = css;
  208. head.appendChild(style);
  209. }
  210.  
  211. // Apply highlighting replacements to a text sequence
  212.  
  213. var curpat; // Hidden argument to repmatch()
  214. var changes; // Number of changes made by repmatch()
  215.  
  216. function repmatch(matched, before, word, after) {
  217. changes++;
  218. return before + '<span class="' + classes[curpat] + '">' + word + '</span>' + after;
  219. }
  220.  
  221. function highlight(s) {
  222. s = " " + s;
  223. for (curpat = 0; curpat < patterns.length; curpat++) {
  224. s = s.replace(patterns[curpat],
  225. repmatch);
  226. }
  227. return s.substring(1);
  228. }
  229.  
  230. // We only modify HTML/XHTML documents
  231. if (document.contentType &&
  232. (!(document.contentType.match(/html/i)))) {
  233. return;
  234. }
  235.  
  236. // Highlight words in body copy
  237.  
  238. var textnodes = document.evaluate("//body//text()", document, null,
  239. XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  240.  
  241. for (var i = 0; i < textnodes.snapshotLength; i++) {
  242. var node = textnodes.snapshotItem(i);
  243. /* Test whether this text node appears within a
  244. <style>, <script>, or <textarea> container.
  245. If so, it is not actual body text and must
  246. be left alone to avoid wrecking the page. */
  247. if (node.parentNode.tagName != "STYLE" &&
  248. node.parentNode.tagName != "TEXTAREA" &&
  249. node.parentNode.tagName != "SCRIPT") {
  250. /* Many documents have large numbers of empty text nodes.
  251. By testing for them, we avoid running all of our
  252. regular expressions over a target which they can't
  253. possibly match. */
  254. if (!(node.data.match(/^\s*$/))) {
  255. var s = " " + node.data + " ";
  256. changes = 0;
  257. var d = highlight(quoteHTML(s));
  258. if (changes > 0) {
  259. var rep = document.createElement("span");
  260. rep.innerHTML = d; //.substring(1, d.length - 1);
  261. node.parentNode.replaceChild(rep, node);
  262. }
  263. }
  264. }
  265. }
  266.  
  267. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement