Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name (Choco)
- // @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=14
- // @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([
- "Adorably Pink Lollypop",
- "Inflation Notice Caramel and Custard Drops",
- "Caramel and Custard Drops",
- "Gummy Green Grundo",
- "Milk Chocolate Orange",
- "Pink Quiggle Candy Floss",
- "Angry Candy",
- "Hazelnut Whirl",
- "Striped Cybunny Lollypop",
- "Cloud Kougra Lollypop",
- "Sugar Tonu Skull",
- "Usukicon Y10 Gummies",
- "Orange Blumaroo Lollypop",
- "Yummy Drops",
- "Holiday Bell Chocolate Advent Calendar",
- "Creamy Choccywhip",
- "Scorchio Cotton Candy",
- "Chocolate Dr Sloth",
- "Cherry Meerca Gobstopper",
- "Neopets 8th Birthday Lollypop",
- "Omnipotent Onion Grarrl Gobstopper",
- "Peachpa Easter Negg",
- "Spooky Flying Doughnut",
- "Snowflake Chocolate Advent Calendar",
- "Chocolate Cybunny Negg",
- "Strawberry Swirl Easter Negg",
- "Plushie Mynci Lollypop",
- "Super Spicy Jelly Beans",
- "Fruity Faerie Easter Negg",
- "Combomelon Easter Negg",
- "Dancing Daisy Easter Negg",
- "Draik Sugar Skull",
- "Choccy Corn",
- "Chocolate Peach",
- "Lovely Lime Easter Negg",
- "Chocolate Maractite Coins",
- "Large Swirly Chocolate Cybunny",
- "Lemon Sherbert Easter Negg",
- "Gnorbu Gum",
- "Orange Chocolate Gelert",
- "Cherry Mootix Lollypop",
- "Orange Scoach Lolly",
- "Apple and Custard Drops",
- "King Skarl Candy",
- "Usuki Mints",
- "Usukicon Y9 Hard Candy",
- "Kikopop"
- ],
- "red");
- // YELLOW words. Black background, yellow text.
- defwords([
- "Bullseyes",
- "Mint Chocolate Peophin",
- "Minty Choccywhip",
- "Neopia Lollypop",
- "Jazzmosis Seasonal Candy Cane",
- "Halloween Aisha Fizzbomb",
- "Cherry Aboogala Lolly",
- "Neverending Jar of Jellybeans",
- "Seasonal Dr. Sloth Truffles",
- "Sugar Moehog Skull",
- "Artificially Flavoured Banana Snacks",
- "Banana Jelly Flotsam",
- "Chocolate Jeran",
- "Milk Chocolate Uni",
- "King Altador Pop",
- "Grape Gummy Slorg",
- "Kau Sundae",
- "Miniature Chocolate Chocolate Factory",
- "Kougra Sugar Skull",
- "Dark Chocolate Skeith",
- "Rainbow Twist Lollipop",
- "Gnorbu Lollipop",
- "Lost City Lanes Lime Gobstopper"
- ],
- "yellow");
- // GREEN words. Black background, green text.
- defwords([
- "Lemon and Lime Easter Negg",
- "Rainbow Candy Floss",
- "Pretty Pink Easter Negg",
- "Strawberries and Cream Easter Negg",
- "Apple Moquot Lollypop",
- "Inflation Notice Spotted Easter Negg",
- "Spotted Easter Negg",
- "Chocolate Crown of the Faeries",
- "Luxury Chocolate Easter Negg",
- "Candy Cane Chocolate Advent Calendar",
- "Inflation Notice Chocolate Orange Easter Negg",
- "Chocolate Orange Easter Negg",
- "Deluxe Strawberry Toffee Chokato",
- "Inflation Notice Fishy Delight Grarrl Gobstopper",
- "Fishy Delight Grarrl Gobstopper",
- "Inflation Notice Milk Chocolate Birthday Nova",
- "Milk Chocolate Birthday Nova",
- "Gummy Speckled Scorchio",
- "White Chocolate Birthday Nova",
- "Gummy Robot Mynci",
- "Holly Bonbons",
- "Mega Ultra Strawberry Fondant",
- "Lemon 9th Birthday Lollipop",
- "Marshmallow Plumpy",
- "Gold Shoyru Lollypop",
- "Plushie JubJub Lollypop",
- "Speckled Acara Lollypop",
- "Pink Bruce Lollypop",
- "Plushie Wocky Lollypop",
- "Blueberry 9th Birthday Lollipop",
- "Chocolate Stamp",
- "Usuki Lollypop",
- "ErgyFruit Jelly Beans",
- "Halloween Kacheek Chocolate Lollypop",
- "Chocolate Ruki Kit",
- "Gummy Pink Elephante",
- "Gummy Spotted Cybunny",
- "Neotruffle",
- "Inflation Notice Starry Grundo Lollypop",
- "Starry Grundo Lollypop",
- "Mynci Halloween Caramel Apple",
- "Illusen Jelly Beans",
- "Cinnamon Scorchio Lollypop",
- "Chocolate Crown of Sinsi",
- "Mynci Mallows",
- "Orange Lightmite Lollypop",
- "Grape 9th Birthday Lollipop",
- "Neopets 8th Birthday Candies",
- "Chocolate Advent Calendar"
- ],
- "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