Guest User

mkonji

a guest
Jan 23rd, 2010
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           HentaiVerse Equipment
  3. // @namespace      HV_EQUIP
  4. // @description    Creates BBCode formatted list of your unequipped items from wherever item stats are listed
  5. // @include        http://hentaiverse.org/?s=Bazaar&ss=es*
  6. // @include        http://hentaiverse.org/?s=Character&ss=eq*
  7. // @include        http://hentaiverse.org/pages/showequip.php*
  8. // @include        http://hv.e-hentai.org/pages/showequip.php*
  9. // ==/UserScript==
  10.  
  11. var SELL_MODIFIER = 5;
  12. working_j = -1;
  13.  
  14. var factor_data = [
  15.   ["Attack Damage Multiplier", 100, "ADmg", 0.308],
  16.   ["Magic Damage Multiplier", 100, "MDmg", 0.302],
  17.   ["Attack Accuracy Bonus", 2000, "AAcc", 0.8],
  18.   ["Magic Accuracy Bonus", 2000, "MAcc", 0.997],
  19.   ["Attack Critical Bonus", 2000, "ACrit", 0.21],
  20.   ["Magic Critical Bonus", 2000, "MCrit", 0.228],
  21.   ["Physical Absorption", 20, "PAbs", 0.029],
  22.   ["Physical Mitigation", 400, "PMit", 0.104],
  23.   ["Magical Absorption", 20, "MAbs", 0.031],
  24.   ["Magical Mitigation", 400, "MMit", 0.101],
  25.   ["Parry Chance", 400, "Parry", 0.495],
  26.   ["Block Chance", 400, "Block", 0.998],
  27.   ["Evade Chance", 400, "Evade", 0.25],
  28.   ["Resist Chance", 400, "Resist", 0.505],
  29.   ["Burden", 400, "Brdn", 1],
  30.   ["Interference", 400, "Intr", 1],
  31.   ["Crushing", 400, "Crush", 0.08],
  32.   ["Slashing", 400, "Slash", 0.08],
  33.   ["Piercing", 400, "Pierce", 0.08],
  34.   ["Elemental", 50, "Ele_P", 0.306],
  35.   ["Deprecating", 50, "Dep_P", 0.306],
  36.   ["Supportive", 50, "Sup_P", 0.306],
  37.   ["Curative", 50, "Cur_P", 0.306],
  38.   ["Divine", 50, "Div_P", 0.306],
  39.   ["Forbidden", 50, "For_P", 0.306],
  40.   ["Fire", 50, "Fire", 1],
  41.   ["Cold", 50, "Cold", 1],
  42.   ["Elec", 50, "Elec", 1],
  43.   ["Wind", 50, "Wind", 1],
  44.   ["Holy", 50, "Holy", 1],
  45.   ["Dark", 50, "Dark", 1],
  46.   ["Soul", 50, "Soul", 1],
  47.   ["Strength", 10, "Str", 0.03],
  48.   ["Dexterity", 10, "Dex", 0.03],
  49.   ["Agility", 10, "Agi", 0.03],
  50.   ["Endurance", 10, "End", 0.03],
  51.   ["Wisdom", 10, "Wis", 0.03],
  52.   ["Intelligence", 10, "Int", 0.03]];
  53.  
  54. var w_i = 0;
  55. var w_str = "";
  56. var working_array = new Array();
  57.  
  58. // _root = The node to look for the items inside (to avoid grabbing items the Bazaar is selling)
  59. // _class = The class name the equipment goes by in the HTML ('eqde' for equipped items in the Character Equipment page, 'eqdp' for everything else)
  60. function get_equipment_bbcode( _root, _class)
  61. {
  62.   if( _root == null) return;
  63.  
  64.   var equips = _root.getElementsByClassName( _class);
  65.   var list = "";
  66.  
  67.   for( var _inc = 0; _inc < equips.length; _inc++)
  68.   {
  69.     var _str = equips[_inc].getAttribute('onmouseover');
  70.    
  71.     // Find the Level
  72.     var _t = _str.indexOf("Level ");
  73.     var c_LVL = _str.substring( _t + 6, _str.indexOf(" ", _t + 6));
  74.    
  75.     // Find the Item Name
  76.     _t = _str.indexOf("'", _str.indexOf("'", _str.indexOf("'", _str.indexOf("show_popup_box")) + 1) + 1);
  77.     var c_NAME = _str.substring( _t + 1, _str.indexOf("'",_t + 1));
  78.    
  79.     // Find the EID and Key
  80.     _t = _str.lastIndexOf( "set_equipmentcopy(");
  81.     var c_EID = _str.substring( _t + 18, _str.indexOf(",", _t + 18));
  82.     _t = _str.indexOf("'", _t + 18);
  83.     var c_KEY =  _str.substring( _t + 1, _str.indexOf("'", _t + 1));
  84.    
  85.     // Find the Sell Value (if sell value is listed on the given page)
  86.     var c_SELL = "";
  87.     _str = equips[_inc].getAttribute('onclick');
  88.     if( _str != null)
  89.     {
  90.       _t = _str.indexOf( "set_selected_item");
  91.       if( _t > -1)
  92.       {
  93.         _t = _str.indexOf(",", _str.indexOf(",", _str.indexOf(",", _t + 16) + 1) + 1);
  94.         c_SELL = "Bazaar Price: " + parseInt(_str.substring( _t + 1, _str.indexOf( ',', _t + 1)))*SELL_MODIFIER + "cp\n";
  95.       }
  96.     }
  97.      
  98.     list += "[b][url=http://hentaiverse.org/pages/showequip.php?eid=" + c_EID + "&key=" + c_KEY + "]" + c_NAME + "[/url][/b](Level: " + c_LVL + ")\n" + c_SELL + "\n";
  99.   }
  100.  
  101.   if( list != "")
  102.   {
  103.     // Create Text Box in lower left to copy text from
  104.     var newElement = document.createElement('div');
  105.     newElement.setAttribute( 'style', "position:absolute; left:10px; bottom:10px; z-index:999;");
  106.     newElement.innerHTML = "Equip Link BBCode:<br /><textarea cols='40' rows='0'>"+list+"</textarea>";
  107.  
  108.     var entry_point = document.getElementsByTagName( 'body')[0];
  109.     entry_point.insertBefore( newElement, entry_point.firstChild);
  110.   }
  111. }
  112.  
  113. function format_all_items()
  114. {
  115.   // Find all relevant equipment
  116.   var _equip = document.getElementsByClassName( 'eqdp');
  117.   if( _equip == null) return;
  118.  
  119.   for( _inc = 0; _inc <   _equip.length; _inc++)
  120.   {  
  121.     var old_str = _equip[_inc].getAttribute('onmouseover');
  122.     var new_str = old_str.match(/show_popup_box.+?<table>/im)[0].replace("<table>","");
  123.    
  124.     // Find the Item Name and EID
  125.     _t = old_str.indexOf("'", old_str.indexOf("'", old_str.indexOf("'", old_str.indexOf("show_popup_box")) + 1) + 1);
  126.     var c_NAME = old_str.substring( _t + 1, old_str.indexOf("'",_t + 1));
  127.     _t = old_str.lastIndexOf( "set_equipmentcopy(");
  128.     var c_EID = old_str.substring( _t + 18, old_str.indexOf(",", _t + 18));
  129.    
  130.     working_array = new Array();
  131.    
  132. //    if( c_NAME.match(/ of /img) == null)
  133.     {
  134.  
  135.       // Make sure the EID is recorded so you don't double-note items
  136.       go = 1;
  137.       for( i = 0; i < EID_array.length; i++)
  138.         if( EID_array[i] == c_EID) go = 0;
  139.  
  140.       if( go)
  141.       {
  142.         working_array = new Array();
  143.         w_i = 2;
  144.         EID_array[ EID_array.length] = c_EID;
  145.  
  146.        
  147.         var tt = c_NAME.match(/Flimsy|Crude|Fair|Average|Fine|Superior|Exquisite|Magnificent/img);
  148.         if( tt == null) alert( "Quality Mismatch: " + c_NAME);
  149.         working_array[0] = tt[0];  // Item Quality
  150.        
  151.         // THE NEXT LINE SHALL PIERCE THE HEAVENS!!!!
  152.         var tt = c_NAME.match(/Axe|Club|Dagger|Rapier|Shortsword|Sword Chucks|Wakizashi|Estoc|Longsword|Mace|Scythe|Katana|Ebony|Redwood|Willow|Oak|Katalox|Buckler|Kite Shield|Tower Shield|Cotton Cap|Silk Cap|Gossamer Cap|Phase Cap|Cotton Robe|Silk Robe|Gossamer Robe|Phase Robe|Cotton Gloves|Silk Gloves|Gossamer Gloves|Phase Gloves|Cotton Pants|Silk Pants|Gossamer Pants|Phase Pants|Cotton Shoes|Silk Shoes|Gossamer Shoes|Phase Shoes|Leather Helmet|Dragon Hide Helmet|Kevlar Helmet|Leather Breastplate|Dragon Hide Breastplate|Kevlar Breastplate|Leather Gauntlets|Dragon Hide Gauntlets|Kevlar Gauntlets|Leather Leggings|Dragon Hide Leggings|Kevlar Leggings|Leather Boots|Dragon Hide Boots|Kevlar Boots|Chainmail Coif|Plate Helmet|Chainmail Hauberk|Plate Cuirass|Chainmail Mitons|Plate Gauntlets|Chainmail Chausses|Plate Greaves|Chainmail Boots|Plate Sabatons/img);
  153.         if( tt == null) alert( "Type Mismatch: " + c_NAME);
  154.         working_array[1] = tt[0]; // Item Type
  155.         //Axe|Club|Dagger|Rapier|Shortsword|Sword Chucks|Wakizashi
  156.         //Estoc|Longsword|Mace|Scythe|Katana
  157.         //Ebony|Redwood|Willow|Oak|Katalox
  158.         //Buckler|Kite Shield|Tower Shield
  159.        
  160.         //Cotton Cap|Silk Cap|Gossamer Cap|Phase Cap
  161.         //Cotton Robe|Silk Robe|Gossamer Robe|Phase Robe
  162.         //Cotton Gloves|Silk Gloves|Gossamer Gloves|Phase Gloves
  163.         //Cotton Pants|Silk Pants|Gossamer Pants|Phase Pants
  164.         //Cotton Shoes|Silk Shoes|Gossamer Shoes|Phase Shoes
  165.        
  166.         //Leather Helmet|Dragon Hide Helmet|Kevlar Helmet
  167.         //Leather Breastplate|Dragon Hide Breastplate|Kevlar Breastplate
  168.         //Leather Gauntlets|Dragon Hide Gauntlets|Kevlar Gauntlets
  169.         //Leather Leggings|Dragon Hide Leggings|Kevlar Leggings
  170.         //Leather Boots|Dragon Hide Boots|Kevlar Boots
  171.        
  172.         //Chainmail Coif|Plate Helmet
  173.         //Chainmail Hauberk|Plate Cuirass
  174.         //Chainmail Mitons|Plate Gauntlets
  175.         //Chainmail Chausses|Plate Greaves
  176.         //Chainmail Boots|Plate Sabatons
  177.       }
  178.     }
  179.    
  180.    
  181.    
  182.     new_str = new_str.replace(/320/, 380);  // Increase the width to accomidate the new stats
  183.     new_str += format_item_table( old_str.match(/<table.+<\/table>/img)[0], parseInt(old_str.match(/Level \d+?\s/)[0].replace("Level ","")));
  184.     new_str += old_str.substring( old_str.lastIndexOf("</table>")+8);
  185.    
  186.     _equip[_inc].setAttribute('onmouseover',new_str);
  187.    
  188.     if( working_array.length != 0)
  189.       w_str += working_array.join(';') + "\n";
  190.   }
  191. }
  192.  
  193. // Takes the item table and reformats it with Base values
  194. // c_LVL = item's current level
  195. function format_item_table( table_str, c_LVL)
  196. {
  197.   var return_str = "<table>";
  198.  
  199.   // Remove the Sub-attribute tables so they don't interfere
  200.   var sub_str = table_str.match(/<table class="eqat">.+?<\/table>/img);
  201.   table_str = table_str.replace(/<table class="eqat">.+?<\/table>/img,"");
  202.  
  203.   // Go through each <tr></tr>
  204.   var _t = table_str.match(/<tr>.+?<\/?tr>/img);
  205.   for( i = 0; i < _t.length; i++)
  206.   {
  207.     var line_str = _t[i]; // String to be intered (working edit)
  208.    
  209.     if( line_str.match(/<td/img).length > 3)  // Make sure it's not a line
  210.     {
  211.       // Find the attribute of the current row
  212.       var att_str = line_str.match(/<td.+?<\/td>/im)[0].replace("<td>","").replace("&nbsp;</td>","");
  213.       // Add width attribute to the first row to make the table pretty
  214.       if( i == 0) line_str = line_str.replace(/<td/, "<td style=\"width:200px\"");
  215.      
  216.       // Match the scaling factor with the attribute name
  217.       for( j = 0; j < factor_data.length; j++)
  218.       {
  219.         if( att_str == factor_data[j][0])
  220.         {
  221.  
  222.           // Add to working array
  223.           if( working_array.length != 0)
  224.           {
  225.             working_array[w_i] = factor_data[j][2];
  226.             w_i++;
  227.           }
  228.             working_j = j;
  229.        
  230.           // Calculate base stat from found stats and add them to row.
  231.           var stats = line_str.match(/\d+?\.\d\d/img);
  232.           if( stats != null)
  233.             line_str = line_str.replace(/<\/tr>/img, "<td style=\"text-align:center;width:80px;font-weight:bold;color:rgb(63,63,160);\">"+ calculate_base_stats( stats, c_LVL,factor_data[j][1], factor_data[j][3]) +"&nbsp;</td></tr>");
  234.           j = factor_data.length;
  235.         }
  236.       }
  237.     }
  238.     return_str += line_str;
  239.   }
  240.  
  241.   // Go through each of the sub attribute trees
  242.   if( sub_str != null)
  243.   {
  244.     for( i = 0; i < sub_str.length; i++)
  245.     {
  246.       // Remove width limitations imposed by the "eqat" class to make the attribute table pretty
  247.       sub_str[i] = sub_str[i].replace("table class=\"eqat\"","table style=\"margin:-1px auto;\"");
  248.      
  249.       //Go through each sub attribute
  250.       var _start = sub_str[i].indexOf( "class=\"eqak\"");
  251.       while( _start != -1)
  252.       {
  253.         // Attribute string
  254.         att_str = sub_str[i].substring( _start + 13, sub_str[i].indexOf("&nbsp;", _start + 13));
  255.         for( var j = 0; j < factor_data.length; j++)
  256.           if( att_str == factor_data[j][0])
  257.           {
  258.             // Add to working array
  259.             if( working_array.length != 0)
  260.             {
  261.               working_array[w_i] = factor_data[j][2];
  262.               w_i++;
  263.             }
  264.            
  265.             working_j = j;
  266.            
  267.             var stats = new Array();
  268.             // Stat scaled to item's level
  269.             var _start2 = sub_str[i].indexOf("\"eqav1\">", _start + 13);
  270.             stats[0] = parseFloat( sub_str[i].substring(_start2 + 9, sub_str[i].indexOf("&nbsp;", _start2 + 9)));
  271.             // Stat scaled to player's level
  272.             _start2 = sub_str[i].indexOf("\"eqav2\">", _start2 + 9);
  273.             var __test = parseFloat( sub_str[i].substring(_start2 + 10, sub_str[i].indexOf("&nbsp;", _start2 + 10)-1));
  274.             if( !isNaN(__test)) stats[1] = __test;
  275.             // Insert Base Stat
  276.             _start2 = sub_str[i].indexOf("</td>", _start2 + 9);
  277.             sub_str[i] = sub_str[i].substring(0, _start2) + "<td style=\"text-align:center;font-weight:bold;color:rgb(63,63,160);\">" + calculate_base_stats( stats, c_LVL, factor_data[j][1], factor_data[j][3]) +"&nbsp;</td>" + sub_str[i].substring(_start2);
  278.           }
  279.        
  280.         // Find next attribute
  281.         _start = sub_str[i].indexOf( "class=\"eqak\"", _start + 1);
  282.       }
  283.     }
  284.    
  285.     // Calculate Bleeding Wounds
  286.     var _start = return_str.indexOf("per tick");
  287.     if( _start != -1)
  288.     {
  289.      
  290.     }
  291.  
  292.     // Re-insert table data into the main string
  293.     _start = return_str.indexOf("<td colspan=\"5\">");
  294.     for( i = 0; i < sub_str.length && _start != -1; i++)
  295.     {
  296.       return_str = return_str.substring(0,_start) + "<td colspan=\"6\">" + sub_str[i] + return_str.substring(_start+16);
  297.       _start = return_str.indexOf("<td colspan=\"5\">", _start);
  298.     }
  299.   }
  300.  
  301.   return_str = return_str + "</table>"
  302.   return return_str;
  303. }
  304.  
  305. // Calculates Base stat string from an array of one or two float strings, the item's level, and a scaling factor
  306. function calculate_base_stats( stats, c_LVL, _factor, _factor2)
  307. {
  308.   _factor2 = 1;
  309.  
  310.   // Stats scaled to item's level
  311.   var max_stat = parseFloat(stats[0]);
  312.   var base_stat_min = (max_stat - 0.005) / (1 + c_LVL / _factor);
  313.   var base_stat_max = (max_stat + 0.005) / (1 + c_LVL / _factor);
  314.  
  315.   if( stats.length > 1)
  316.     stats_data[working_j] += stats[1] + ";";
  317.   if( stats.length > 1 && p_LVL != -1)
  318.   {
  319.     // Stats scaled to player's level
  320.     var cur_stat = parseFloat(stats[1]);
  321.     base_stat_min = Math.max( base_stat_min, (cur_stat - 0.005) / (1 + p_LVL / _factor));
  322.     base_stat_max = Math.min( base_stat_max, (cur_stat + 0.005) / (1 + p_LVL / _factor));
  323.   }
  324.  
  325.   // Round the average and error to two decimals
  326.   var base_stat = Math.round( (base_stat_min + base_stat_max) / 2 * 100) / 100;
  327.   var base_diff = Math.round( (base_stat_max - base_stat_min) / 2 * 100) / 100;
  328.   if( base_diff == 0) base_diff = "";
  329.   else base_diff = "&plusmn;" + base_diff;
  330.  
  331.   // Add to working array
  332.   if( working_array.length != 0)
  333.   {
  334.     working_array[w_i] = base_stat;
  335.     w_i++;
  336.   }
  337.  
  338.   if( _factor2 != 1)
  339.     base_stat = Math.round( base_stat/_factor2);
  340.   return "" + base_stat + base_diff;
  341. }
  342.  
  343. function get_level()
  344. {
  345.   return -1;
  346. }
  347.  
  348. {
  349.   // Parse all the equipments in the leftpane
  350. //  get_equipment_bbcode(document.getElementById('leftpane'),'eqdp');  // Non-equipped items
  351. //  get_equipment_bbcode(document.getElementById('leftpane'),'eqde');  // Equipped items
  352.  
  353.   var p_LVL = get_level();
  354.   var EID_array = new Array();
  355.   var stats_data = new Array();
  356.  
  357.   for( i = 0; i < factor_data.length; i++)
  358.     stats_data[i] = factor_data[i][2] + ";";
  359.  
  360.   EID_array = GM_getValue("EID_array","").split(';');
  361.  
  362.   format_all_items();
  363.  
  364.   GM_setValue("EID_array",EID_array.join(';'));
  365.  
  366.   var equipmentroot = document.getElementById('equipment');
  367.  
  368.   if(equipmentroot != null)
  369.   {
  370.     equipmentroot.setAttribute('style', equipmentroot.getAttribute('style').replace("width: 320px", "width: 380px"));
  371.     var eHTML = equipmentroot.innerHTML
  372.     equipmentroot.innerHTML = eHTML.replace(/<table.+<\/table>/img,format_item_table(eHTML.match(/<table.+<\/table>/img)[0], parseInt(eHTML.match(/Level \d+?\s/)[0].replace("Level ",""))));
  373.   }
  374.  
  375. //    if( list != "")
  376.   {
  377.     // Create Text Box in lower left to copy text from
  378.     var newElement = document.createElement('div');
  379.     newElement.setAttribute( 'style', "position:absolute; left:10px; bottom:10px; z-index:999;");
  380.    
  381.     // NOTE: w_str was something before this.  I don't care right now, but I might care later
  382.     w_str = "";
  383.     for( i = 0; i < factor_data.length; i++)
  384.       w_str += stats_data[i] + "\n";
  385.    
  386.     newElement.innerHTML = "Equip Link BBCode:<br /><textarea cols='40' rows='0'>"+w_str+"</textarea>";
  387.  
  388.     var entry_point = document.getElementsByTagName( 'body')[0];
  389.     entry_point.insertBefore( newElement, entry_point.firstChild);
  390.   }
  391. }
Advertisement
Add Comment
Please, Sign In to add comment