Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name (Bakery)
- // @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=15
- // @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([
- "x"
- ], "blank");
- // RED words. These items are black background with red text.
- defwords([
- "Doglefox Bread Creature",
- "Faerie Aisha Cake",
- "Kacheek Fruit Salad Sandwich",
- "Electric Wocky Bread",
- "Irate Zafara Claw",
- "Hula Girl Usuki Cake",
- "Bread",
- "Kacheek Baby Cabbage Sandwiches",
- "Ultimate Grilled Cheese Sandwich",
- "Lime Chomby Cake",
- "Haiku Dessert",
- "Faerie Acara Pretzel",
- "Scamander Cookies",
- "Inflation Notice Borovan Cupcake",
- "Borovan Cupcake",
- "Babaa Cake",
- "Hostile Quiche",
- "Disco Elephante Toaster Cakes",
- "Desert Dessert",
- "Mini Lemon and Lime Birthday Cake",
- "Cloud Usul Iced Buns",
- "Mini Raspberry Birthday Cake",
- "Kacheek Ombus Fruit Sandwich",
- "Sugar Nerkmid Biscuit",
- "Angry Cinnamon Roll",
- "Slice Of New Year Cake"
- ],
- "red");
- // YELLOW words. Black background, yellow text.
- defwords([
- "Snowy Pancakes",
- "Mini Blueberry Birthday Cake",
- "Cranky Croissant",
- "Grey Grundo Muffin",
- "Transparaberry Hot Cross Buns",
- "Mini Chocolate Birthday Cake",
- "Fire Mynci Cake",
- "Madeleine Sandwich Cookies",
- "Illusen Waffle",
- "Carrot Shoyru Muffin",
- "Red Velvet Cake",
- "Choccy Chip Skeith Biscuit",
- "Pink Fyora Gingerbread Castle",
- "Chocolate Chip Nerkmid Biscuit",
- "Hazelnut Banana Crepe",
- "Blue Paint Brush Cookie",
- "Blue Paint Brush Cookie",
- "Strawberry Shimmer Cake",
- "Colourful Cybunny Cookie",
- "Red Paint Brush Cookie",
- "Massive White Aisha Cake",
- "Slice of Neopets Birthday Cake",
- "Tiered Neopets 8th Birthday Cake",
- "Chocolate Raspberry Ganache Cake",
- "Kass Kakes",
- "Grilled Cheese Chomby Sandwich",
- "Chocolate Orange Ganache Cake",
- "Super Deluxe Maraquan Victory Cake",
- "Banana Split Swiss Roll",
- "Bubble Cake",
- "Pteri Seed Cake",
- "Snowberry Quiggle Cake",
- "Strawberry Skeith Biscuit",
- "Grunion Fruit Krawk Cake",
- "Toast A La King",
- "Minimalist Cake"
- ],
- "yellow");
- // GREEN words. Black background, green text.
- defwords([
- "Chia Cake",
- "Grapefruit Cake",
- "Borovan Layered Cake",
- "Inflation Notice Meepit Muffins",
- "Meepit Muffins",
- "Stack It High Cake",
- "Chocolate Cream Biscuit",
- "Buttered Juppie Waffle",
- "Chokato Deluxe Aisha Cake",
- "Dargil Meat Mince Pie",
- "Gooseberry Crepe",
- "Pterimisu",
- "Red Kacheek Cupcake",
- "Blueberry Deluxe Cake",
- "Chocolate Chip Quiggle Cookie",
- "Inflation Notice Minty Eyrie Cookie",
- "Minty Eyrie Cookie",
- "Inflation Notice Robot Kacheek Cookie",
- "Robot Kacheek Cookie",
- "Fyora Spider Cake",
- "Speckled Scorchio Cookie",
- "Spotted Cybunny Cookie",
- "Spotted Mynci Sticky Bun",
- "Pink Elephante Cookie",
- "Disco JubJub Cupcake",
- "Strawberry Usul Cake",
- "Gold Kyrii Cookie",
- "Gold Usul Cookie",
- "Green Kacheek Cupcake",
- "Gold Blumaroo Cookie",
- "Ruler Biscuits",
- "Butterlicious Bun",
- "Strawberry JubJub Cupcake",
- "Cloud Bruce Muffin",
- "Fyora Cookies",
- "Beach Fun Usuki Cupcakes",
- "Chocolate Stuffed Pastry",
- "Vionanna Mince Pie"
- ],
- "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