Advertisement
KK20

Food Adjustments

Sep 28th, 2019
751
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Food Adjustments
  3. // @namespace    http://tampermonkey.net/
  4. // @version      1.01
  5. // @description  Generate food adjustments table on the Current Round pages
  6. // @author       KK20
  7. // @match        http://www.neopets.com/pirates/foodclub.phtml?type=current*
  8. // @exclude      http://www.neopets.com/pirates/foodclub.phtml?type=current_bets
  9. // @require      https://code.jquery.com/jquery-3.1.0.min.js
  10. // @grant        none
  11. // ==/UserScript==
  12.  
  13. const pirate_names = {
  14.     1: 'Dan',
  15.     2: 'Sproggie',
  16.     3: 'Orvinn',
  17.     4: 'Lucky',
  18.     5: 'Edmund',
  19.     6: 'Peg Leg',
  20.     7: 'Bonnie',
  21.     8: 'Puffo',
  22.     9: 'Stuff',
  23.     10: 'Squire',
  24.     11: 'Crossblades',
  25.     12: 'Stripey',
  26.     13: 'Ned',
  27.     14: 'Fairfax',
  28.     15: 'Gooblah',
  29.     16: 'Franchisco',
  30.     17: 'Federismo',
  31.     18: 'Blackbeard',
  32.     19: 'Buck',
  33.     20: 'Tailhook'
  34. }
  35.  
  36. const positive_adjustment = {
  37.     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],
  38.     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],
  39.     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],
  40.     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],
  41.     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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,0,0,1,0,0,0,0,0,2,1,1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1,2],
  54.     18:[0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,1,1,0,1,1,0,1,1,0,0,0,1,0,0,0,0,0,0],
  55.     19:[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],
  56.     20:[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]
  57. }
  58.  
  59. const negative_adjustment = {
  60.     1: [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],
  61.     2: [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],
  62.     3: [0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0],
  63.     4: [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,0,0,1],
  64.     5: [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],
  65.     6: [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],
  66.     7: [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],
  67.     8: [1,0,0,1,0,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0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,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]
  80. }
  81.  
  82. function get_pirates_and_food() {
  83.     var pirates = []
  84.     var foods = []
  85.     var id
  86.     $('tr[bgcolor=white] table a').each(function(index) {
  87.         id = $(this).attr('href').match(/\d+$/)[0]
  88.         if (index < 4)
  89.             pirates.push(id)
  90.         else
  91.             foods.push(id)
  92.     })
  93.     create_table(pirates, foods)
  94. }
  95.  
  96. function create_table(pirates, foods) {
  97.     var table = $('<table border="1px solid black" cellpadding="15px">')
  98.  
  99.     var foods_row = $('<tr>')
  100.     foods_row.append('<td bgcolor="darkgray"><b>Food ID ->')
  101.     $.each(foods, function(i, val) {
  102.         foods_row.append('<td bgcolor="lightgray">' + val + '</td>')
  103.     })
  104.     foods_row.append('<td bgcolor="darkgray"><b>Total</b>')
  105.     table.append(foods_row)
  106.  
  107.  
  108.     $.each(pirates, function(i, p_id) {
  109.         var total_score = 0
  110.         var pirates_row = $('<tr>')
  111.         pirates_row.append('<td bgcolor="lightgray">' + pirate_names[p_id])
  112.         $.each(foods, function(j, f_id) {
  113.             var score_text = ''
  114.             var p_score = pos(p_id, f_id)
  115.             var n_score = neg(p_id, f_id)
  116.  
  117.             if (p_score && n_score)
  118.                 score_text = '+' + p_score + ' / ' + '-' + n_score
  119.             else if (!(p_score || n_score))
  120.                 score_text = 0
  121.             else
  122.                 score_text = p_score ? '+' + p_score : '-' + n_score
  123.  
  124.             total_score += p_score - n_score
  125.             pirates_row.append('<td ' + score_bg_color(score_text) + '>' + score_text)
  126.         })
  127.         pirates_row.append('<td ' + score_bg_color(total_score) + '>' + total_score)
  128.         table.append(pirates_row)
  129.     })
  130.  
  131.     $('center:last').prepend( table).prepend('<p>')
  132. }
  133.  
  134. function pos(pirate, food) {
  135.     var score = positive_adjustment[pirate][food-1]
  136.     return score || false
  137. }
  138.  
  139. function neg(pirate, food) {
  140.     var score = negative_adjustment[pirate][food-1]
  141.     return score || false
  142. }
  143.  
  144. function score_bg_color(score) {
  145.     if (score > 0)
  146.         return 'bgcolor="palegreen"'
  147.     else if (score < 0)
  148.         return 'bgcolor="salmon"'
  149.     else
  150.         return ''
  151. }
  152.  
  153. $(get_pirates_and_food)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement