Advertisement
Guest User

Untitled

a guest
Dec 15th, 2016
4,101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Restocking Profit Highlighter (STORE)
  3. // @namespace http://www.neocodex.us/
  4. // @version 1.0
  5. // @description Automatically highlights profitable items in Neopets stores.
  6. // @author MediaTriggerWords, modified by ayyylmao on NeoCodex
  7. // @match STORE URL GOES HERE
  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.red { background-color: #000000; color: #ff1a00; } ' +
  30. 'span.yellow { background-color: #000000; color: #fdff00;} ' +
  31. 'span.green { background-color: #000000; color: #23ea11;} ' +
  32. 'span.blank { background-color: #ffffff; color: #ffffff} ' );
  33.  
  34. // BLANK items. Items in this list will appear as white on white and be functionally invisible.
  35.  
  36. defwords([
  37. ""
  38. ], "blank");
  39.  
  40. // RED words. These items are black background with red text.
  41.  
  42. defwords([
  43. ""
  44. ],
  45. "red");
  46.  
  47. // YELLOW words. Black background, yellow text.
  48.  
  49. defwords([
  50. ""
  51. ],
  52. "yellow");
  53.  
  54. // GREEN words. Black background, green text.
  55.  
  56. defwords([
  57. ""
  58. ],
  59. "green");
  60.  
  61. // Add one or more words to the dictionary with a specified class
  62.  
  63. function defwords(words, which_class) {
  64. for (var i = 0; i < words.length; i++) {
  65. var w = words[i].replace(/^=/, "");
  66. patterns.push(new RegExp("([^a-zA-Z])(" + w + ")([^a-zA-Z])",
  67. words[i].match(/^=/) ? "g" : "gi"));
  68. classes.push(which_class);
  69. }
  70. }
  71.  
  72. // Quote HTML metacharacters in body text
  73.  
  74. function quoteHTML(s) {
  75. s = s.replace(/&/g, "&amp;");
  76. s = s.replace(/</g, "&lt;");
  77. s = s.replace(/>/g, "&gt;");
  78. return s;
  79. }
  80.  
  81. // Add one or more CSS style rules to the document
  82.  
  83. function addGlobalStyle(css) {
  84. var head, style;
  85. head = document.getElementsByTagName('head')[0];
  86. if (!head) {
  87. return;
  88. }
  89. style = document.createElement('style');
  90. style.type = 'text/css';
  91. style.innerHTML = css;
  92. head.appendChild(style);
  93. }
  94.  
  95. // Apply highlighting replacements to a text sequence
  96.  
  97. var curpat; // Hidden argument to repmatch()
  98. var changes; // Number of changes made by repmatch()
  99.  
  100. function repmatch(matched, before, word, after) {
  101. changes++;
  102. return before + '<span class="' + classes[curpat] + '">' + word + '</span>' + after;
  103. }
  104.  
  105. function highlight(s) {
  106. s = " " + s;
  107. for (curpat = 0; curpat < patterns.length; curpat++) {
  108. s = s.replace(patterns[curpat],
  109. repmatch);
  110. }
  111. return s.substring(1);
  112. }
  113.  
  114. // We only modify HTML/XHTML documents
  115. if (document.contentType &&
  116. (!(document.contentType.match(/html/i)))) {
  117. return;
  118. }
  119.  
  120. // Highlight words in body copy
  121.  
  122. var textnodes = document.evaluate("//body//text()", document, null,
  123. XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  124.  
  125. for (var i = 0; i < textnodes.snapshotLength; i++) {
  126. var node = textnodes.snapshotItem(i);
  127. /* Test whether this text node appears within a
  128. <style>, <script>, or <textarea> container.
  129. If so, it is not actual body text and must
  130. be left alone to avoid wrecking the page. */
  131. if (node.parentNode.tagName != "STYLE" &&
  132. node.parentNode.tagName != "TEXTAREA" &&
  133. node.parentNode.tagName != "SCRIPT") {
  134. /* Many documents have large numbers of empty text nodes.
  135. By testing for them, we avoid running all of our
  136. regular expressions over a target which they can't
  137. possibly match. */
  138. if (!(node.data.match(/^\s*$/))) {
  139. var s = " " + node.data + " ";
  140. changes = 0;
  141. var d = highlight(quoteHTML(s));
  142. if (changes > 0) {
  143. var rep = document.createElement("span");
  144. rep.innerHTML = d.substring(1, d.length - 1);
  145. node.parentNode.replaceChild(rep, node);
  146. }
  147. }
  148. }
  149. }
  150.  
  151. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement