Advertisement
modernstudboy

Script for tf2outpost.com V2

Jul 7th, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.98 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Backpack.tf prices on Tf2outpost
  3. // @author kléni
  4. // @include http://*.tf2outpost.com/*
  5. // @include http://*.dotaoutpost.com/*
  6. // @require http://code.jquery.com/jquery-2.1.0.min.js
  7. // @updateURL https://raw.githubusercontent.com/klenium/tf2opscript/master/t.user.js
  8. // @grant GM_xmlhttpRequest
  9. // @version 1.4.3
  10. // ==/UserScript==
  11. // Coloring of prices is updated by steamid:76561198029259027
  12.  
  13. var checkReady = function(check, callback)
  14. {
  15. var c = check();
  16. if (c)
  17. callback();
  18. else
  19. window.setTimeout(function() { checkReady(check, callback); }, 100);
  20. };
  21. var zemnmodal =
  22. {
  23. //this script loads earlier than outpost scripts, had to add it
  24. a: $('<div class="zemnmodal" />'),
  25. c: $('<div class="zemncontent" />'),
  26. make: function(b)
  27. {
  28. if (!$("body > .zemnmodal").length)
  29. {
  30. this.a.append(this.c);
  31. $("body").append(this.a);
  32. this.a.click(function(e)
  33. {
  34. if (e.target == this)
  35. zemnmodal.unmake();
  36. });
  37. }
  38. this.c.html(b).css("margin-top", 120 + $(window).scrollTop());
  39. this.a.height($(document).height()).stop(true).fadeIn(200);
  40. },
  41. unmake: function()
  42. {
  43. this.a.stop(true).fadeOut(200);
  44. }
  45. };
  46. var update = function()
  47. {
  48. if (localStorage.apikey === undefined)
  49. {
  50. zemnmodal.make('Get an API key from backpack.tf! <a id="keylink" href="http://backpack.tf/api/register/" target="_blank">Click here</a>, and copy the key!<br />You can type anything in the URL and reason fields, eg. "http://tf2outpost.com", and "price script".');
  51. $("#keylink").click(function()
  52. {
  53. $(this).parent().html('Paste the key here:<br /><input id="keyinput" type="text" style="width: 170px; padding: 13px; border: 0px; background-color: #1C1A17;" />');
  54. $("#keyinput").focus().keyup(function()
  55. {
  56. if (this.value.length == 24)
  57. {
  58. localStorage.apikey = this.value;
  59. zemnmodal.unmake();
  60. process();
  61. }
  62. });
  63. });
  64. }
  65. else
  66. process();
  67. };
  68. var setcookie = function(name, value, time)
  69. {
  70. var expires = "";
  71. if (time)
  72. {
  73. var date = new Date();
  74. date.setTime(date.getTime()+time);
  75. var expires = "; expires="+date.toGMTString();
  76. }
  77. document.cookie = name+"="+value+expires+"; path=/";
  78. }
  79. var getcookie = function(name)
  80. {
  81. var ca = document.cookie.split(";");
  82. for (var i = 0; i < ca.length; i++)
  83. {
  84. var c = ca[i].trim();
  85. if (c.indexOf(name+"=") == 0)
  86. return c.substring(name.length+1, c.length);
  87. }
  88. return null;
  89. }
  90. var process = function()
  91. {
  92. if (getcookie("error"))
  93. return;
  94. GM_xmlhttpRequest({
  95. method: "GET",
  96. url: "http://backpack.tf/api/IGetPrices/v4/?format=json&key="+localStorage.apikey,
  97. onload: function(e)
  98. {
  99. try
  100. {
  101. var data = JSON.parse(e.responseText);
  102. if (data.response.message)
  103. throw data.response.message;
  104. if (!data)
  105. return;
  106. var n = {},
  107. ref = data.response.items["Refined Metal"]["prices"][6]["Tradable"]["Craftable"][0],
  108. key = data.response.items["Mann Co. Supply Crate Key"]["prices"][6]["Tradable"]["Craftable"][0],
  109. bud = data.response.items["Earbuds"]["prices"][6]["Tradable"]["Craftable"][0],
  110. m = ref.value_high ? ((ref.value+ref.value_high)/2) : ref.value,
  111. k = key.value_high ? ((key.value+key.value_high)/2) : key.value,
  112. b = bud.value_high ? ((bud.value+bud.value_high)/2) : bud.value,
  113. utk = m*k,
  114. utb = m*k*b,
  115. date = data.response.current_time,
  116. names = {
  117. metal: 1,
  118. keys: 2,
  119. earbuds: 3,
  120. usd: 4
  121. },
  122. parts = {};
  123. $.each(data.response.items, function(name)
  124. {
  125. var item = this;
  126. if (!item.defindex || !item.prices)
  127. return;
  128. $.each(item.defindex, function()
  129. {
  130. var x = this;
  131. //crates, we don't need 3 defindexs for them
  132. if (x == 5041 || x == 5045)
  133. return;
  134. if (name.indexOf("Strange Part: ") != -1)
  135. parts[name.replace("Strange Part: ", "").replace(/[\s-.']/g, "").replace("\u00dc", "U")] = x;
  136. if (!n[x])
  137. n[x] = {};
  138. n[x].name = name;
  139. $.each(item.prices, function(quality)
  140. {
  141. var quality = parseInt(quality);
  142. if (name.indexOf("Australium") != -1 && name != "Australium Gold")
  143. quality *= -1;
  144. if (!n[x][quality])
  145. n[x][quality] = {};
  146. $.each(this, function(tradable)
  147. {
  148. var tradable = tradable == "Tradable" ? 1 : 0;
  149. if (!n[x][quality][tradable])
  150. n[x][quality][tradable] = {};
  151. $.each(this, function(craftable)
  152. {
  153. var craftable = craftable == "Craftable" ? 1 : 0;
  154. if (!n[x][quality][tradable][craftable])
  155. n[x][quality][tradable][craftable] = {};
  156. $.each(this, function(index)
  157. {
  158. var index = parseInt(index);
  159. var type = this.currency,
  160. l = this.value,
  161. h = this.value_high;
  162. //converting USD values to keys/buds, so we won't need it later
  163. if (quality == 5 && type == "usd")
  164. {
  165. if (l < utb)
  166. {
  167. l = Math.round(l/utk);
  168. if (h)
  169. h = Math.round(h/utk);
  170. type = "keys";
  171. }
  172. else
  173. {
  174. l = (l/utb).toFixed(1);
  175. l = l.substr(-1) == "0" ? l.substr(0, l.length-2) : l;
  176. if (h)
  177. {
  178. h = (h/utb).toFixed(1);
  179. h = h.substr(-1) == "0" ? h.substr(0, h.length-2) : h;
  180. }
  181. type = "earbuds";
  182. }
  183. }
  184. var d = [names[type], date-this.last_update, this.difference, l];
  185. if (h)
  186. d.push(h);
  187. n[x][quality][tradable][craftable][index] = d;
  188. });
  189. });
  190. });
  191. });
  192. });
  193. });
  194. var isdata = localStorage.data === undefined;
  195. localStorage.data = JSON.stringify(n);
  196. localStorage.parts = JSON.stringify(parts);
  197. localStorage.lastupdate = date;
  198. if (isdata)
  199. location.reload();
  200. }
  201. catch(error)
  202. {
  203. var html = "Couldn't update the prices, because:<br />"+error;
  204. zemnmodal.make(html);
  205. if (error == "API key does not exist.")
  206. {
  207. //getting a new key
  208. localStorage.removeItem("apikey");
  209. setTimeout(function()
  210. {
  211. zemnmodal.unmake();
  212. update();
  213. }, 2000);
  214. }
  215. else
  216. {
  217. var c = parseInt(getcookie("error"));
  218. var time = 30000;
  219. if (c)
  220. {
  221. if (btoa(error) == getcookie("errorvalue"))
  222. c++;
  223. else
  224. c = 1;
  225. if (c >= 3)
  226. time = 36000000;
  227. }
  228. setcookie("error", c, time);
  229. setcookie("errorvalue", btoa(error), 36000000);
  230. }
  231. }
  232. }
  233. });
  234. };
  235. var num = function(num1, operator, num2)
  236. {
  237. num1 = parseFloat(num1);
  238. num2 = parseFloat(num2);
  239. var strNum1 = num1 + "",
  240. strNum2 = num2 + "",
  241. dpNum1 = !!(num1 % 1) ? (strNum1.length - strNum1.indexOf(".") - 1) : 0,
  242. dpNum2 = !!(num2 % 1) ? (strNum2.length - strNum2.indexOf(".") - 1) : 0,
  243. multiplier = Math.pow(10, dpNum1 > dpNum2 ? dpNum1 : dpNum2),
  244. tempNum1 = Math.round(num1 * multiplier),
  245. tempNum2 = Math.round(num2 * multiplier);
  246. switch (operator)
  247. {
  248. case "+": return (tempNum1 + tempNum2) / multiplier;
  249. case "-": return (tempNum1 - tempNum2) / multiplier;
  250. case "*": return (tempNum1 * tempNum2) / (multiplier * multiplier);
  251. case "/": return (tempNum1 / tempNum2);
  252. }
  253. }
  254. var getprice = function(defindex, quality, trade, craft, index, output, round, fix)
  255. {
  256. var obj = p[defindex][quality][trade][craft][index],
  257. low = parseFloat(obj[3]),
  258. high = parseFloat(obj[4] ? obj[4] : obj[3]),
  259. k = obj[0],
  260. type = ["ref", "key", "bud", "USD"][k-1];
  261. if (round)
  262. {
  263. low = (low+high)/2;
  264. if (!fix)
  265. low = low.toFixed(2);
  266. low = parseFloat(low);
  267. high = low;
  268. }
  269. if (output)
  270. {
  271. var r = getprice(5002, 6, 1, 1, 0, false, true, true),
  272. k = getprice(5021, 6, 1, 1, 0, false, true),
  273. b = getprice(143, 6, 1, 1, 0, false, true);
  274. switch (type)
  275. {
  276. case "ref" : return num(low, "*", r[0]);
  277. case "key" : return num(low, "*", num(r[0], "*", k[0]));
  278. case "bud" : return num(low, "*", num(r[0], "*", num(k[0], "*", b[0])));
  279. default: return low;
  280. }
  281. }
  282. return [low, high, type, obj[1], obj[2]];
  283. };
  284. var round = function(value, date, diff, name, input, output)
  285. {
  286. var r = getprice(5002, 6, 1, 1, 0, false, true, true)[0],
  287. k = getprice(5021, 6, 1, 1, 0, false, true)[0],
  288. b = getprice(143, 6, 1, 1, 0, false, true)[0],
  289. type = "";
  290. if (output)
  291. return [value, value, "USD", date];
  292. else if (value < r*k || (value == r*k && input == 1))
  293. {
  294. value /= r;
  295. type = "ref";
  296. }
  297. else if (value < r*k*b || (value == r*k*b && input == 2))
  298. {
  299. value /= r*k;
  300. type = "key";
  301. }
  302. else
  303. {
  304. value /= r*k*b;
  305. type = "bud";
  306. }
  307. return [parseFloat(value.toFixed(2)), parseFloat(value.toFixed(2)), type, date, diff, name];
  308. };
  309. var pricetext = function(obj, unusual)
  310. {
  311. var low = obj[0],
  312. high = obj[1],
  313. type = obj[2],
  314. now = Math.round((new Date()).getTime()/1000),
  315. last = parseInt(localStorage.lastupdate),
  316. date = obj[3]+now-last,
  317. o = "";
  318. if ((type == "bud" || type == "key") && ((high == low && low != 1) || (high != low && (low != 1 || high != 1))))
  319. type += "s";
  320. if (date > (60*60*24*30.5*3) && unusual && localStorage.warn === undefined)
  321. o = " <span class='label'>(updated "+(date/60/60/24/30.5).toFixed(1)+" months ago)</span>";
  322. return low+(high != low ? " - "+high : "")+" "+type+o;
  323. };
  324. var item = function(i, replace)
  325. {
  326. if (i.data("attrs"))
  327. return JSON.parse(i.data("attrs"));
  328. if (!i.attr("data-hash"))
  329. return;
  330. var id = i.attr("data-hash").split(",");
  331. if (id[0] != 440)
  332. return;
  333. if (label)
  334. i.find(".equipped, .series_no, .quantity, .medal_no, .craft_no").hide();
  335. var na = [],
  336. a = (i.attr("data-attributes") || "").split("<br>"),
  337. is_unusual = i.hasClass("it_440_5"),
  338. total = 0;
  339. //HHHH and Haunted Metal Scrap aren't unusual hats
  340. if (id[1] == 266 && id[1] == 267)
  341. is_unusual = false;
  342. var paints = {
  343. IndubitablyGreen: 5027,
  344. ZepheniahsGreed: 5028,
  345. NobleHattersViolet: 5029,
  346. ColorNo216190216: 5030,
  347. ADeepCommitmenttoPurple: 5031,
  348. MannCoOrange: 5032,
  349. Muskelmannbraun: 5033,
  350. PeculiarlyDrabTincture: 5034,
  351. RadiganConagherBrown: 5035,
  352. YeOldeRusticColour: 5036,
  353. AustraliumGold: 5037,
  354. AgedMoustacheGrey: 5038,
  355. AnExtraordinaryAbundanceofTinge: 5039,
  356. ADistinctiveLackofHue: 5040,
  357. TeamSpirit: 5046,
  358. PinkasHell: 5051,
  359. AColorSimilartoSlate: 5052,
  360. DrablyOlive: 5053,
  361. TheBitterTasteofDefeatandLime: 5054,
  362. TheColorofaGentlemannsBusinessPants: 5055,
  363. DarkSalmonInjustice: 5056,
  364. AMannsMint: 5076,
  365. AfterEight: 5077,
  366. OperatorsOveralls: 5060,
  367. WaterloggedLabCoat: 5061,
  368. BalaclavasAreForever: 5062,
  369. AnAirofDebonair: 5063,
  370. TheValueofTeamwork: 5064,
  371. CreamSpirit: 5065
  372. },
  373. spells = {
  374. BruisedPurpleFootprints: 8919,
  375. ChromaticCorruption: 8902,
  376. CorpseGrayFootprints: 8916,
  377. DemomansCadaverousCroak: 8910,
  378. DieJob: 8901,
  379. EngineerssGravellyGrowl: 8908,
  380. Exorcism: 8921,
  381. GangreenFootprints: 8915,
  382. GourdGrenades: 8923,
  383. HeadlessHorseshoes: 8920,
  384. HeavysBottomlessBass: 8909,
  385. MedicsBloodcurdlingBellow: 8913,
  386. PutrescentPigmentation: 8900,
  387. PyrosMuffledMoan: 8911,
  388. RottenOrangeFootprints: 8918,
  389. ScoutsSpectralSnarl: 8906,
  390. SentryQuadPumpkins: 8924,
  391. SinisterStaining: 8904,
  392. SnipersDeepDownunderDrawl: 8907,
  393. SoldiersBoomingBark: 8905,
  394. SpectralFlame: 8925,
  395. SpectralSpectrum: 8903,
  396. SpysCreepyCroon: 8912,
  397. SquashRockets: 8922,
  398. TeamSpiritFootprints: 8914,
  399. ViolentVioletFootprints: 8917
  400. },
  401. //some cases outpost uses custom names
  402. parts = $.extend(JSON.parse(localStorage.parts), {
  403. AirborneEnemyKills: 6012,
  404. KillsUnderAFullMoon: 6015,
  405. Dominations: 6016,
  406. Revenges: 6018,
  407. SappersRemoved: 6025,
  408. KillsWhileLowHealth: 6032,
  409. DefendersKilled: 6035,
  410. KillsWhileInvulnUberCharged: 6037,
  411. KillsWhileUbercharged: 6037,
  412. TauntKills: 6051,
  413. SubmergedEnemyKills: 6036,
  414. BurningPlayerKills: 6053,
  415. KillsDuringHalloween: 6033,
  416. KillsduringVictoryTime: 6041
  417. });
  418. for (var x = 0; x < a.length; x++)
  419. {
  420. var attr = $("<span>"+a[x]+"</span>").text();
  421. attr = [attr.substr(0, attr.indexOf(":")), attr.substr(attr.indexOf(":")+2, attr.length-1)];
  422. if (attr[0] && attr[1])
  423. {
  424. if (attr[0] == "Painted")
  425. {
  426. //painted paint? grr
  427. if (i.attr("data-name") == attr[1])
  428. i.find(".paint, .paint_secondary").remove();
  429. else
  430. {
  431. i.get(0).paint = attr[1]; //i.data() doesn't work, nice work Sneeza :P
  432. var n = attr[1].replace(/[\s-.']/g, "");
  433. if (paints[n] && p[paints[n]])
  434. {
  435. if (!is_unusual)
  436. total += getprice(paints[n], 6, 1, 1, 0, true, true)*ppaint;
  437. na.push("<span class='label'>Painted:</span> "+attr[1]+(tooltip ? " <span class='label'>("+pricetext(getprice(paints[n], 6, 1, 1, 0))+")</span>" : ''));
  438. }
  439. }
  440. }
  441. else if (attr[0] == "Real Name")
  442. {
  443. i.get(0).cn = 1;
  444. var cn = i.attr("data-name");
  445. i.data("name", attr[1]).attr("data-name", attr[1]);
  446. na.push("<span class='label'>Custom Name:</span> "+cn.substr(1, cn.length-2)+(tooltip ? " <span class='label'>("+pricetext(getprice(2093, 6, 1, 1, 0))+")</span>" : ''));
  447. }
  448. else if (attr[0] == "Custom Desc")
  449. {
  450. i.get(0).cd = 1;
  451. na.push("<span class='label'>Custom Description:</span> "+attr[1].substr(1, attr[1].length-2)+(tooltip ? " <span class='label'>("+pricetext(getprice(5044, 6, 1, 1, 0))+")</span>" : ''));
  452. }
  453. else if (attr[0] == "Halloween Spell")
  454. {
  455. i.get(0).spell = attr[1];
  456. var n = attr[1].replace(/[\s-\.']/g, "");
  457. if (spells[n] && p[spells[n]])
  458. na.push("<span class='label'>Halloween Spell:</span> "+attr[1]+(tooltip ? " <span class='label'>("+pricetext(getprice(spells[n], 6, 1, 1, 0))+")</span>" : ''));
  459. }
  460. //for unusual taunt, bp.tf uses 30xx IDs which I don't think op will support, and also they don't have background images yet
  461. else if (attr[0] == "Effect")
  462. {
  463. if (is_unusual)
  464. i.get(0).effect = attr[1];
  465. var effect;
  466. if (i.attr("data-name").indexOf("Taunt:") != -1)
  467. {
  468. switch (attr[1])
  469. {
  470. case "Showstopper": effect = 3001; break;
  471. case "Showstopper": effect = 3002; break;
  472. case "Holy Grail": effect = 3003; break;
  473. case "'72": effect = 3004; break;
  474. case "Fountain of Delight": effect = 3005; break;
  475. case "Screaming Tiger": effect = 3006; break;
  476. case "Skill Gotten Gains": effect = 3007; break;
  477. case "Midnight Whirlwind": effect = 3008; break;
  478. case "Silver Cyclone": effect = 3009; break;
  479. case "Mega Strike": effect = 3010; break;
  480. default: effect = null;
  481. }
  482. }
  483. else
  484. effect = null;
  485. na.push(a[x]);
  486. }
  487. else if (attr[0] == "Australium")
  488. {
  489. i.get(0).aust = 1;
  490. if (localStorage.aust !== undefined)
  491. na.push(a[x]);
  492. }
  493. else if (attr[0] == "Gifted By")
  494. {
  495. i.get(0).gifted = 1;
  496. na.push(a[x]);
  497. }
  498. else if (attr[0] == "Sheen")
  499. {
  500. i.get(0).sheen = attr[1];
  501. na.push(a[x]);
  502. }
  503. else if (attr[0] == "Killstreaks")
  504. {
  505. i.get(0).kill = 1;
  506. na.push(a[x]);
  507. }
  508. else if (attr[0] == "Killstreaker")
  509. {
  510. i.get(0).streaker = attr[1];
  511. na.push(a[x]);
  512. }
  513. else
  514. {
  515. var n = attr[0].replace(/[\s-.']/g, "").replace("\u00dc", "U");
  516. if (parts[n])
  517. {
  518. if (i.get(0).parts !== undefined)
  519. i.get(0).parts.push(attr[0]);
  520. else
  521. i.get(0).parts = [attr[0]];
  522. if (!is_unusual)
  523. total += getprice(parts[n], 6, 1, 1, 0, true, true)*pparts;
  524. na.push("<span class='label'>"+attr[0]+":</span> "+attr[1]+(tooltip ? " <span class='label'>("+pricetext(getprice(parts[n], 6, 1, 1, 0))+")</span>" : ''));
  525. }
  526. else
  527. na.push(a[x]);
  528. }
  529. }
  530. }
  531. if (na.length)
  532. {
  533. var itemattr = "<br>"+na.join("<br>");
  534. i.data("attributes", itemattr).attr("data-attributes", itemattr);
  535. }
  536. else if (i.attr("data-attributes"))
  537. i.removeData("attributes").removeAttr("data-attributes");
  538. //Self-made keys
  539. if (id[1] == 5021 && id[2] == 9)
  540. id[1] = 5081;
  541. //crates
  542. if (id[1] == 5041 || id[1] == 5045)
  543. id[1] = 5022;
  544. if (!p[id[1]])
  545. return;
  546. var craft = i.hasClass("uncraftable") ? 0 : 1,
  547. trade = i.hasClass("untradable") ? 0 : 1,
  548. name = i.attr("data-name");
  549. i.get(0).craft = craft;
  550. i.get(0).trade = trade;
  551. if (name.indexOf("Australium") != -1 && name != "Australium Gold")
  552. {
  553. id[2] *= -1;
  554. if (localStorage.aust === undefined)
  555. {
  556. var imgs = {
  557. "Ambassador": "http://backpack.tf/images/440/backpack/weapons/c_models/c_ambassador/parts/c_ambassador_opt_gold.png",
  558. "Axtinguisher": "http://backpack.tf/images/440/backpack/weapons/c_models/c_axtinguisher/c_axtinguisher_pyro_gold.png",
  559. "Black Box": "http://backpack.tf/images/440/backpack/weapons/c_models/c_blackbox/c_blackbox_gold.png",
  560. "Blutsauger": "http://backpack.tf/images/440/backpack/weapons/c_models/c_leechgun/c_leechgun_gold.png",
  561. "Eyelander": "http://backpack.tf/images/440/backpack/weapons/c_models/c_claymore/c_claymore_gold.png",
  562. "Flame Thrower": "http://backpack.tf/images/440/backpack/weapons/c_models/c_flamethrower/c_flamethrower_gold.png",
  563. "Force-A-Nature": "http://backpack.tf/images/440/backpack/weapons/c_models/c_double_barrel_gold.png",
  564. "Frontier Justice": "http://backpack.tf/images/440/backpack/weapons/c_models/c_frontierjustice/c_frontierjustice_gold.png",
  565. "Grenade Launcher": "http://backpack.tf/images/440/backpack/weapons/w_models/w_grenadelauncher_gold.png",
  566. "Knife": "http://backpack.tf/images/440/backpack/weapons/w_models/w_knife_gold.png",
  567. "Medi Gun": "http://backpack.tf/images/440/backpack/weapons/c_models/c_medigun/c_medigun_gold.png",
  568. "Minigun": "http://backpack.tf/images/440/backpack/weapons/w_models/w_minigun_gold.png",
  569. "Rocket Launcher": "http://backpack.tf/images/440/backpack/weapons/w_models/w_rocketlauncher_gold.png",
  570. "Scattergun": "http://backpack.tf/images/440/backpack/weapons/c_models/c_scattergun_gold.png",
  571. "SMG": "http://backpack.tf/images/440/backpack/weapons/w_models/w_smg_gold.png",
  572. "Sniper Rifle": "http://backpack.tf/images/440/backpack/weapons/w_models/w_sniperrifle_gold.png",
  573. "Stickybomb Launcher": "http://backpack.tf/images/440/backpack/weapons/w_models/w_stickybomb_launcher_gold.png",
  574. "Tomislav": "http://backpack.tf/images/440/backpack/weapons/c_models/c_tomislav/c_tomislav_gold.png",
  575. "Wrench": "http://backpack.tf/images/440/backpack/weapons/w_models/w_wrench_gold_large.png"
  576. };
  577. name = name.substr(name.indexOf("Australium")+11, name.length-1);
  578. i.find("img").attr("src", imgs[name]);
  579. }
  580. }
  581. if (!p[id[1]][id[2]])
  582. return;
  583. if (!p[id[1]][id[2]][trade])
  584. return;
  585. if (!p[id[1]][id[2]][trade][craft])
  586. return;
  587. var s = 0;
  588. if (is_unusual)
  589. {
  590. if (effect !== undefined && effect != null)
  591. s = effect;
  592. else
  593. {
  594. var bg = i.css("background-image");
  595. if (bg == "none")
  596. return;
  597. s = parseInt(bg.split("effects/")[1].split(".png")[0]);
  598. }
  599. }
  600. if (i.find(".series_no").length)
  601. s = parseInt(i.find(".series_no").html().substr(1));
  602. //items with Community Sparkle
  603. if (name == "Self-Made Mann Co. Supply Crate Key" || ((id[1] == 294 || id[1] == 160) && i.css("background-image") != "none"))
  604. s = 4;
  605. if (!p[id[1]][id[2]][trade][craft][s])
  606. return;
  607. i.get(0).name = p[id[1]].name;
  608. var itemattr = (i.attr("data-attributes") || "")+(tooltip ? "<br><span class='label'>Suggested value:</span> "+pricetext(getprice(id[1], id[2], trade, craft, s), is_unusual)+"</span>" : '');
  609. i.data("attributes", itemattr).attr("data-attributes", itemattr);
  610. if (localStorage.show !== undefined)
  611. {
  612. t = total+getprice(id[1], id[2], trade, craft, s, true, true);
  613. var item = p[id[1]][id[2]][trade][craft][s],
  614. a = i.find("a.item_summary");
  615. if (!a.length)
  616. a = i.find("> a:eq(0)");
  617. if (a.find("> *").eq(1).length)
  618. a.find("> *").eq(1).before('<div class="equipped">'+pricetext(round(t, item[1], item[2], name, item[0], name == "Refined Metal"))+'</div>');
  619. else
  620. a.append('<div class="equipped">'+pricetext(round(t, item[1], item[2], name, item[0], name == "Refined Metal"))+'</div>');
  621. }
  622. if (localStorage.changes !== undefined)
  623. {
  624. var obj = getprice(id[1], id[2], trade, craft, s),
  625. now = Math.round((new Date()).getTime()/1000),
  626. last = parseInt(localStorage.lastupdate),
  627. date = obj[3]+now-last;
  628. if (date < 60*60*24*(parseFloat(localStorage.days) || 3))
  629. {
  630. if (obj[4] == 0) //Brad and Fiskie are so lazy :-c
  631. var cn = "fa-white fa-certificate";
  632. else if (obj[4] < 0)
  633. var cn = "fa-red fa-arrow-down";
  634. else
  635. {
  636. var b = getprice(143, 6, 1, 1, 0),
  637. k = getprice(5021, 6, 1, 1, 0),
  638. price = 0;
  639. if (obj[2] == "bud")
  640. price = ((obj[0]+obj[1])/2)*((b[0]+b[1])/2)*((k[0]+k[1])/2);
  641. else if (obj[2] == "key")
  642. price = ((obj[0]+obj[1])/2)*((k[0]+k[1])/2);
  643. if (price == obj[4])
  644. var cn = "fa-white fa-certificate";
  645. else
  646. var cn = "fa-green fa-arrow-up";
  647. }
  648. i.find("a.item_summary").append('<div class="fa '+cn+'"></div>');
  649. }
  650. }
  651. var d = [p[id[1]][id[2]][trade][craft][s], total];
  652. i.data("attrs", JSON.stringify(d));
  653. return d;
  654. }
  655. var p = JSON.parse(localStorage.data || "[]"),
  656. label = localStorage.label !== undefined,
  657. tooltip = localStorage.tooltip === undefined,
  658. ppaint = parseFloat(localStorage.ppaint)/100 || 0.5,
  659. pparts = parseFloat(localStorage.pparts)/100 || 0.8;
  660. $(function()
  661. {
  662. //only in the main window, otherwise it would run 4 times (other scripts)
  663. if (window.top != window.self)
  664. return;
  665. if (localStorage.data === undefined)
  666. return update();
  667. if (localStorage.lastupdate !== undefined && parseInt(localStorage.lastupdate) < ((new Date()).getTime()/1000)-(60*60*24*(parseFloat(localStorage.update) || 1)))
  668. update();
  669. if (/backpack/.test(location.href) && localStorage.links === undefined)
  670. $(".navigation_bar .left").append('<li><a href="http://www.tf2outpost.com/user/'+($(".user_info strong").html() == "—" ? $(".user_info").html().split("</span> ")[1] : $(".user_info strong").html())+'/resolve/backpack.tf">BP.TF Profile</a></li>');
  671. checkReady(function()
  672. {
  673. //for invertories and new trade page
  674. return !(($("body#backpack").length || $("body#new").length) && !$("#p1").length);
  675. },
  676. function()
  677. {
  678. $("#main_nav").append('<li><a href="#" id="script_settings"><span class="icon_settings"></span>Prices</a></li>');
  679. var style = '<style>';
  680. style += '.icon_tick.checkbox { color: #504A46; margin-right: 6px; cursor: pointer; }';
  681. style += '.icon_tick.checkbox.checked { color: #52BB0C; }';
  682. style += '.zemnmodal .input { margin: 0px 2px; padding: 0px 3px; border: 2px solid #2A2725; background: #1C1A17; }';
  683. style += '.zemnmodal .button { padding: 5px; min-width: inherit; }';
  684. style += 'input.d { width: 17px; }';
  685. style += '.fa-green { color: #44CC44; }';
  686. style += '.fa-red { color: #CC4444; }';
  687. style += '.fa-white { color: #BEBEBE; }';
  688. style += '.fa { position: absolute; top: 4px; left: 4px; font-size: 16px; }';
  689. style += '</style>';
  690. $("head").append(style);
  691. $("head").append('<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">');
  692. if (localStorage.links === undefined)
  693. {
  694. if (/user/.test(location.href))
  695. $(".navigation_bar .left").append('<li><a href="http://www.tf2outpost.com/user/'+($(".user_info strong").html() == "—" ? $(".user_info").html().split("</span> ")[1] : $(".user_info strong").html())+'/resolve/backpack.tf">BP.TF Profile</a></li>');
  696. $(".item_summary").click(function()
  697. {
  698. checkReady(function()
  699. {
  700. //waiting for the AJAX response
  701. return $("#item_summary").length && $(".links").length;
  702. },
  703. function()
  704. {
  705. if (!$(".links .bptf").length)
  706. {
  707. var i = $("#item_summary .item");
  708. if (!i.attr("data-hash"))
  709. return;
  710. var id = i.attr("data-hash").split(",");
  711. if (id[0] != 440)
  712. return;
  713. var is_unusual = i.hasClass("it_440_5") && id[1] != 266 && id[1] != 267;
  714. if (id[1] == 5021 && id[2] == 9)
  715. id[1] = 5081;
  716. if (id[1] == 5041 || id[1] == 5045)
  717. id[1] = 5022;
  718. if (!p[id[1]])
  719. return;
  720. var craft = i.hasClass("uncraftable") ? "Non-Craftable" : "Craftable",
  721. trade = i.hasClass("untradable") ? "Non-Tradable" : "Tradable",
  722. name = i.attr("data-name");
  723. if (name.indexOf("Australium") != -1 && name != "Australium Gold")
  724. id[2] *= -1;
  725. var s = 0;
  726. if (is_unusual)
  727. {
  728. var bg = i.css("background-image");
  729. if (bg == "none")
  730. return;
  731. s = parseInt(bg.split("effects/")[1].split(".png")[0]);
  732. }
  733. if (i.find(".series_no").length)
  734. s = parseInt(i.find(".series_no").html().substr(1));
  735. if (name == "Self-Made Mann Co. Supply Crate Key" || ((id[1] == 294 || id[1] == 160) && i.css("background-image") != "none"))
  736. s = 4;
  737. var quality = "";
  738. switch (id[2])
  739. {
  740. case "0": quality = "Normal"; break;
  741. case "1": quality = "Genuine"; break;
  742. case "3": quality = "Vintage"; break;
  743. case "5": quality = "Unusual"; break;
  744. case "6": quality = "Unique"; break;
  745. case "9": quality = "Self-Made"; break;
  746. case "11": case -11: quality = "Strange"; break;
  747. case "13": quality = "Haunted"; break;
  748. case "14": quality = "Collector's"; break;
  749. }
  750. var link = "http://backpack.tf/stats/"+quality+"/"+(id[2] == -11 ? "Australium " : "")+p[id[1]].name+"/"+craft+"/"+trade+(s == 0 ? "" : "/"+s);
  751. $(".links").append('<li class="bptf"><a href="'+link+'" target="_blank"><span class="icon_trades"></span> Stats on BP.TF</a></li>');
  752. link = "http://backpack.tf/item/"+$("#item_summary .grid .row:eq(1) .white").html();
  753. $(".links").append('<li><a href="'+link+'" target="_blank"><span class="icon_search"></span> History on BP.TF</a></li>');
  754. }
  755. });
  756. });
  757. }
  758. $("#script_settings").click(function()
  759. {
  760. var html = '';
  761. html += '<a href="http://forums.backpack.tf/index.php?/topic/10248-script-for-tf2outpostcom/" target="_blank">Suggestions, bug reports</a><br /><br />';
  762. html += '<button class="button" type="button" id="update">Update prices now</button><br /><br />';
  763. html += 'Your backpack.tf API key: <input type="text" class="input" value="'+localStorage.apikey+'" /> <a href="http://backpack.tf/api/register/" target="_blank" id="changekey">Change</a><br />';
  764. html += 'Update prices automatically on every <input type="text" class="input d" data-name="update" value="'+(parseFloat(localStorage.update) || 1)+'" /> days<br />';
  765. html += '<span data-name="show" class="checkbox icon_tick'+(localStorage.show !== undefined ? ' checked' : '')+'"></span>Show the price of items on their icon, included';
  766. html += '<input class="input d" type="text" data-name="ppaint" value="'+(parseFloat(localStorage.ppaint) || 50)+'" />% of paint, and ';
  767. html += '<input class="input d" type="text" data-name="pparts" value="'+(parseFloat(localStorage.pparts) || 80)+'" />% of strange parts<br />';
  768. html += '<span data-name="tooltip" class="n checkbox icon_tick'+(localStorage.tooltip === undefined ? ' checked' : '')+'"></span>Show prices on the tooltip of items<br />';
  769. html += '<span data-name="changes" class="checkbox icon_tick'+(localStorage.changes !== undefined ? ' checked' : '')+'"></span>Show changes in the last <input data-name="days" type="text" class="input d" value="'+(parseFloat(localStorage.days) || 3)+'" /> days<br />';
  770. html += '<span data-name="warn" class="n checkbox icon_tick'+(localStorage.warn === undefined ? ' checked' : '')+'"></span>Show a warning if an unusual hat was updated more than 3 months<br />';
  771. html += '<span data-name="aust" class="n checkbox icon_tick'+(localStorage.aust === undefined ? ' checked' : '')+'"></span>Replace images of australium weapons to the images that backpack.tf uses<br />';
  772. html += '<span data-name="label" class="checkbox icon_tick'+(localStorage.label !== undefined ? ' checked' : '')+'"></span>Remove crate #, craft #, medal #, quantity, and equipped labels from the box of items<br />';
  773. html += '<span data-name="links" class="n checkbox icon_tick'+(localStorage.links === undefined ? ' checked' : '')+'"></span><span class="c">Add links to the user\'s backpack.tf profile and the stats page of items<br />';
  774. html += '<span data-name="text" class="n checkbox icon_tick'+(localStorage.text === undefined ? ' checked' : '')+'"></span>On the new trade page, when you select an item, add it\'s <span>';
  775. html += '<span class="tp checkbox icon_tick'+((localStorage.tp !== undefined && localStorage.tp == 1) ? ' checked' : '')+'"></span>low ';
  776. html += '<span class="tp checkbox icon_tick'+((localStorage.tp === undefined || localStorage.tp == 2) ? ' checked' : '')+'"></span>mid ';
  777. html += '<span class="tp checkbox icon_tick'+((localStorage.tp !== undefined && localStorage.tp == 3) ? ' checked' : '')+'"></span>high</span> price to the textarea<br />';
  778. html += '<br /><button class="button" type="button" id="save">Save</button>';
  779. zemnmodal.make(html);
  780. $("#update").click(function()
  781. {
  782. $(this).attr("disabled", "true");
  783. localStorage.removeItem("data");
  784. update();
  785. });
  786. $("#changekey").click(function()
  787. {
  788. $(this).prev().val("");
  789. });
  790. $("#save").click(function()
  791. {
  792. location.reload();
  793. });
  794. $(".zemnmodal .checkbox").click(function()
  795. {
  796. if ($(this).hasClass("tp"))
  797. {
  798. $(".tp.checkbox").removeClass("checked");
  799. $(this).addClass("checked");
  800. var index = $(this).index()+1;
  801. localStorage.tp = index;
  802. }
  803. else
  804. {
  805. $(this).toggleClass("checked");
  806. var checked = $(this).hasClass("checked");
  807. if ($(this).hasClass("n"))
  808. checked = !checked;
  809. localStorage[checked ? "setItem" : "removeItem"]($(this).attr("data-name"), "1");
  810. }
  811. });
  812. $(".zemnmodal input[data-name][type='text']").keyup(function()
  813. {
  814. var v = Math.min(100, Math.max(0, parseInt(this.value)));
  815. if (isNaN(v))
  816. return;
  817. localStorage.setItem($(this).attr("data-name"), v);
  818. });
  819. });
  820. $(".item").each(function()
  821. {
  822. item($(this));
  823. });
  824. if ($("body#new").length)
  825. {
  826. $("#backpack .item").click(function()
  827. {
  828. var i = item($(this));
  829. if (!i)
  830. {
  831. $("#new_form textarea").get(0).value += ($("#new_form textarea").get(0).value != "" ? "\n" : "")+$(this).attr("data-name")+": ";
  832. return;
  833. }
  834. var tp = parseInt(localStorage.tp || 2),
  835. pt = [],
  836. b = getprice(143, 6, 1, 1, 0, true, true),
  837. k = getprice(5021, 6, 1, 1, 0, true, true),
  838. r = getprice(5002, 6, 1, 1, 0, true, true, true),
  839. h = $(this).attr("data-hash").split(",");
  840. if (tp == 1)
  841. var price = parseFloat(i[0][3]);
  842. else if (tp == 2)
  843. var price = (i[0][4] ? (parseFloat(i[0][3])+parseFloat(i[0][4]))/2 : parseFloat(i[0][3]));
  844. else if (tp == 3)
  845. var price = parseFloat(i[0][4] || i[0][3]);
  846. if (i[0][0] == 3)
  847. price *= b;
  848. else if (i[0][0] == 2)
  849. price *= k;
  850. else if (i[0][0] == 1)
  851. price *= r;
  852. price += i[1];
  853. var dp = price;
  854. if (num(price, "/", b) > 1)
  855. {
  856. var bud = Math.floor(num(price, "/", b));
  857. pt.push(bud+" bud"+(bud > 1 ? "s" : ""));
  858. price -= bud*b;
  859. }
  860. if (h[1] != 5021 && num(price, "/", k) >= 1)
  861. {
  862. var key = Math.floor(num(price, "/", k));
  863. pt.push(key+" key"+(key > 1 ? "s" : ""));
  864. price -= key*k;
  865. }
  866. if (i[1] < b*2 && num(price, "/", r) >= 0.11)
  867. {
  868. var ref = num(price, "/", r),
  869. rs = ref.toFixed(2);
  870. ref = parseFloat(rs);
  871. if (rs.indexOf(".") != -1 && rs.substr(rs.indexOf(".")+1, 1) != rs.substr(rs.indexOf(".")+2, 1))
  872. {
  873. var r1 = parseInt(rs.substr(0, rs.indexOf("."))),
  874. r2 = parseInt(rs.substr(rs.indexOf(".")+1, 1)),
  875. rd = parseFloat(rs);
  876. if (rd > parseFloat(r1+"."+r2+r2))
  877. ref = r1+"."+(++r2)+r2;
  878. else if (rd-0.05 < parseFloat(r1+"."+r2+r2))
  879. ref = r1+"."+(--r2)+r2;
  880. else
  881. ref = r1+"."+r2+r2;
  882. }
  883. pt.push(ref+" ref");
  884. price -= parseFloat(ref)*r;
  885. }
  886. if (price > 0 && dp < r && num(price, "/", r) <= 0.05)
  887. {
  888. var ptr = num(price, "/", r);
  889. if (ptr == 0.05)
  890. pt.push("1 weapon");
  891. else
  892. pt.push(parseFloat((0.05/ptr).toFixed(1))+" for a weapon");
  893. }
  894. var q = "";
  895. switch (h[2])
  896. {
  897. case "0": q = "[color=yellow]Normal "; break;
  898. case "1": q = "[color=green]Genuine "; break;
  899. case "3": q = "[color=blue]Vintage "; break;
  900. case "5": q = "[color=violet]Unusual "; break;
  901. case "7": q = "[color=lime]Community "; break;
  902. case "9": q = "[color=pink]Self-Made "; break;
  903. case "11": q = "[color=coral]Strange "; break;
  904. case "13": q = "[color=purple]Haunted "; break;
  905. case "14": q = "[color=red]Collector's "; break;
  906. }
  907. if (this.aust !== undefined)
  908. q = "[color=gold]Australium ";
  909. var paint = (this.paint !== undefined && h[2] != 5) ? " painted "+this.paint : "",
  910. ef = (this.effect !== undefined && h[2] == 5) ? this.effect+" " : "",
  911. craft = !this.craft ? "[color=grey]Uncraftable " : "",
  912. trade = !this.trade ? "Untradable " : "",
  913. parts = this.parts !== undefined ? "[/color][color=orange] with "+this.parts.join(", ")+" strange part"+(this.parts.length > 1 ? "s" : "") : "",
  914. noprice = false,
  915. craftno = "",
  916. gift = this.gifted !== undefined ? "[color=red]Gifted " : "",
  917. killstreak = [],
  918. kill = "",
  919. cn = $(this).find(".craft_no");
  920. if (cn.length && parseInt(cn.html().substr(1)) <= 100)
  921. {
  922. noprice = true;
  923. craftno = "[color=cyan]Craft "+cn.html()+" ";
  924. }
  925. if (this.sheen !== undefined)
  926. killstreak.push(this.sheen);
  927. if (this.streaker !== undefined)
  928. killstreak.push(this.streaker);
  929. if (this.kill !== undefined)
  930. kill = "Killstreak ";
  931. if (killstreak.length)
  932. kill += "("+killstreak.join(", ")+") ";
  933. $("#new_form textarea").get(0).value += ($("#new_form textarea").get(0).value != "" ? "\n" : "")+gift+trade+craft+q+kill+ef+craftno+this.name.replace("The ", "")+parts+paint+": [/color]"+(noprice ? "" : pt.join(" + "));
  934. });
  935. }
  936. });
  937. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement