Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name (Health Food)
- // @namespace g
- // @version 1.0
- // @description Automatically highlights profitable items in Neopets stores.
- // @author Me
- // @match http://www.neopets.com/objects.phtml?type=shop&obj_type=16
- // @grant none
- // ==/UserScript==
- (function() {
- var patterns = [], classes = [];
- /* The following define the classes of words. If the first
- character of the specification is "=", the match will be
- case-sensitive, otherwise it will be case-insensitive.
- The specification is a regular expression, and should
- contain metacharacters to handle variant spellings and
- plurals. Any grouping within these patterns *must* be done
- with a (?: ... ) specification to avoid messing up the
- capture from the text string.
- You may add additional categories as you wish, but be sure to
- declare their rendering in the style definition below. */
- // Rendering styles for our various word classes
- addGlobalStyle('span.blank { background-color: #ffffff; color: #ffffff } ' +
- 'span.yellow { background-color: #000000; color: #fdff00; border-style: dotted; font-size: 13px; } ' +
- 'span.green { background-color: #FFA500; color: #ffffff; border-style: dotted; border-color: black; font-size: 25px; } ' +
- 'span.red { background-color: #ff1a00; color: #000000; border-style: dotted; font-size: 18px; } ' );
- // BLANK items. Items in this list will appear as white on white and be functionally invisible.
- defwords([
- "Chunky Cauliflower Soup"
- ], "blank");
- // RED words. These items are black background with red text.
- defwords([
- "Golden Carrot",
- "Fresh Sushi Cone",
- "Radish and Cheese",
- "Cone-Shaped Lemon",
- "Fresh Sushi Roll",
- "Broccoli and Mustard Sandwich"
- ],
- "red");
- // YELLOW words. Black background, yellow text.
- defwords([
- "Cone-Shaped Orange",
- "Broccoli Kebab",
- "Baked Apple with Snowberries",
- "Cheesy Broccoli Bite",
- "Asparagus Pie",
- "Radish Meringue",
- "Cone-Shaped Strawberry"
- ],
- "yellow");
- // GREEN words. Black background, green text.
- defwords([
- "Broccoli with Sprinkles",
- "Cheesy Carrots",
- "Tomato Kebab",
- "Inflation Notice Luxury Cabbage Cake",
- "Luxury Cabbage Cake",
- "Artichoke Cupcake",
- "Four Layer Carrot Cake",
- "Cauliflower Lolly",
- "Inflation Notice French Onion Soup",
- "French Onion Soup",
- "Inflation Notice Pickled Cauliflower",
- "Pickled Cauliflower",
- "Cauliflower Soup",
- "Inflation Notice Artichoke and Onion Surprise",
- "Artichoke and Onion Surprise",
- "Inflation Notice Cauliflower Shake",
- "Cauliflower Shake",
- "Inflation Notice Cone-Shaped Cherry",
- "Cone-Shaped Cherry",
- "Inflation Notice Souper Bowl",
- "Souper Bowl",
- "Inflation Notice Artichoke Fondue",
- "Artichoke Fondue",
- "Inflation Notice Asparagus Balls",
- "Asparagus Balls"
- ],
- "green");
- // Add one or more words to the dictionary with a specified class
- function defwords(words, which_class) {
- for (var i = 0; i < words.length; i++) {
- var w = words[i].replace(/^=/, "");
- patterns.push(new RegExp("([^a-zA-Z])(" + w + ")([^a-zA-Z])",
- words[i].match(/^=/) ? "g" : "gi"));
- classes.push(which_class);
- }
- }
- // Quote HTML metacharacters in body text
- function quoteHTML(s) {
- s = s.replace(/&/g, "&");
- s = s.replace(/</g, "<");
- s = s.replace(/>/g, ">");
- return s;
- }
- // Add one or more CSS style rules to the document
- function addGlobalStyle(css) {
- var head, style;
- head = document.getElementsByTagName('head')[0];
- if (!head) {
- return;
- }
- style = document.createElement('style');
- style.type = 'text/css';
- style.innerHTML = css;
- head.appendChild(style);
- }
- // Apply highlighting replacements to a text sequence
- var curpat; // Hidden argument to repmatch()
- var changes; // Number of changes made by repmatch()
- function repmatch(matched, before, word, after) {
- changes++;
- return before + '<span class="' + classes[curpat] + '">' + word + '</span>' + after;
- }
- function highlight(s) {
- s = " " + s;
- for (curpat = 0; curpat < patterns.length; curpat++) {
- s = s.replace(patterns[curpat],
- repmatch);
- }
- return s.substring(1);
- }
- // We only modify HTML/XHTML documents
- if (document.contentType &&
- (!(document.contentType.match(/html/i)))) {
- return;
- }
- // Highlight words in body copy
- var textnodes = document.evaluate("//body//text()", document, null,
- XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
- for (var i = 0; i < textnodes.snapshotLength; i++) {
- var node = textnodes.snapshotItem(i);
- /* Test whether this text node appears within a
- <style>, <script>, or <textarea> container.
- If so, it is not actual body text and must
- be left alone to avoid wrecking the page. */
- if (node.parentNode.tagName != "STYLE" &&
- node.parentNode.tagName != "TEXTAREA" &&
- node.parentNode.tagName != "SCRIPT") {
- /* Many documents have large numbers of empty text nodes.
- By testing for them, we avoid running all of our
- regular expressions over a target which they can't
- possibly match. */
- if (!(node.data.match(/^\s*$/))) {
- var s = " " + node.data + " ";
- changes = 0;
- var d = highlight(quoteHTML(s));
- if (changes > 0) {
- var rep = document.createElement("span");
- rep.innerHTML = d; //.substring(1, d.length - 1);
- node.parentNode.replaceChild(rep, node);
- }
- }
- }
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement