Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Food Adjustments
- // @namespace http://tampermonkey.net/
- // @version 1.01
- // @description Generate food adjustments table on the Current Round pages
- // @author KK20
- // @match http://www.neopets.com/pirates/foodclub.phtml?type=current*
- // @exclude http://www.neopets.com/pirates/foodclub.phtml?type=current_bets
- // @require https://code.jquery.com/jquery-3.1.0.min.js
- // @grant none
- // ==/UserScript==
- const pirate_names = {
- 1: 'Dan',
- 2: 'Sproggie',
- 3: 'Orvinn',
- 4: 'Lucky',
- 5: 'Edmund',
- 6: 'Peg Leg',
- 7: 'Bonnie',
- 8: 'Puffo',
- 9: 'Stuff',
- 10: 'Squire',
- 11: 'Crossblades',
- 12: 'Stripey',
- 13: 'Ned',
- 14: 'Fairfax',
- 15: 'Gooblah',
- 16: 'Franchisco',
- 17: 'Federismo',
- 18: 'Blackbeard',
- 19: 'Buck',
- 20: 'Tailhook'
- }
- const positive_adjustment = {
- 1: [2,0,0,1,0,1,1,1,0,1,0,2,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0],
- 2: [1,0,0,1,1,1,1,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,0,0,0],
- 3: [0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,1,0,0,1],
- 4: [0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1],
- 5: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,0,0,0,0,1,0,1,0,0,0,0,0,0,1,1,0],
- 6: [0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0],
- 7: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0,1,0,0,0,0,0,0,0,0,0,0,0],
- 11:[1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0],
- 12:[0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0],
- 13:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,0,0,0,0,1,0,1,0,0,0,0,0,0,1,1,0],
- 14:[1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0],
- 15:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0],
- 16:[0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0],
- 17:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0],
- 18:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,0,0,0,0,1,0,1,0,0,0,0,0,0,1,1,0],
- 19:[0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,0,0,0,0,0],
- 20:[0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0]
- }
- function get_pirates_and_food() {
- var pirates = []
- var foods = []
- var id
- $('tr[bgcolor=white] table a').each(function(index) {
- id = $(this).attr('href').match(/\d+$/)[0]
- if (index < 4)
- pirates.push(id)
- else
- foods.push(id)
- })
- create_table(pirates, foods)
- }
- function create_table(pirates, foods) {
- var table = $('<table border="1px solid black" cellpadding="15px">')
- var foods_row = $('<tr>')
- foods_row.append('<td bgcolor="darkgray"><b>Food ID ->')
- $.each(foods, function(i, val) {
- foods_row.append('<td bgcolor="lightgray">' + val + '</td>')
- })
- foods_row.append('<td bgcolor="darkgray"><b>Total</b>')
- table.append(foods_row)
- $.each(pirates, function(i, p_id) {
- var total_score = 0
- var pirates_row = $('<tr>')
- pirates_row.append('<td bgcolor="lightgray">' + pirate_names[p_id])
- $.each(foods, function(j, f_id) {
- var score_text = ''
- var p_score = pos(p_id, f_id)
- var n_score = neg(p_id, f_id)
- if (p_score && n_score)
- score_text = '+' + p_score + ' / ' + '-' + n_score
- else if (!(p_score || n_score))
- score_text = 0
- else
- score_text = p_score ? '+' + p_score : '-' + n_score
- total_score += p_score - n_score
- pirates_row.append('<td ' + score_bg_color(score_text) + '>' + score_text)
- })
- pirates_row.append('<td ' + score_bg_color(total_score) + '>' + total_score)
- table.append(pirates_row)
- })
- $('center:last').prepend( table).prepend('<p>')
- }
- function pos(pirate, food) {
- var score = positive_adjustment[pirate][food-1]
- return score || false
- }
- function neg(pirate, food) {
- var score = negative_adjustment[pirate][food-1]
- return score || false
- }
- function score_bg_color(score) {
- if (score > 0)
- return 'bgcolor="palegreen"'
- else if (score < 0)
- return 'bgcolor="salmon"'
- else
- return ''
- }
- $(get_pirates_and_food)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement