forked from ilyvion/barter-vg-enhancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.js
More file actions
24 lines (24 loc) · 30.5 KB
/
bundle.js
File metadata and controls
24 lines (24 loc) · 30.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// ==UserScript==
// @name barter-vg-enhancer
// @description Summarizes and compares all attributes in an offer for easy comparison of offer value
// @namespace github.com/ialarmedalien
// @match https://barter.vg/*
// @run-at document-body
// @connect barter.vg
// @connect store.steampowered.com
// @connect api.isthereanydeal.com
// @require https://code.jquery.com/jquery-3.6.3.min.js
// @noframes
// @version 0.6.0
// @homepage https://github.com/ialarmedalien/barter-vg-enhancer#readme
// @author ialarmedalien; Alexander Krivács Schrøder
// @license GPL-3.0
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_listValues
// @grant GM_xmlhttpRequest
// @grant GM_getResourceText
// ==/UserScript==
!function(){"use strict";class e{constructor(e,n,a,t){this._regex=e,this._controller=n,this._action=a,this._predicate=t}get regex(){return this._regex}get controller(){return this._controller}get action(){return this._action}get predicate(){return this._predicate}get hasPredicate(){return null!==this._predicate&&void 0!==this._predicate}}const n="application/json",a=/^\)\]\}',?\n/,t=/^\[|^\{(?!\{)/,i={"[":/]$/,"{":/}$/};function o(e){return"string"==typeof e}function r(e,r){if(!o(e))return e;const s=e.replace(a,"").trim();if(!s)return e;const c=r("Content-Type");var l;return(c&&0===c.indexOf(n)||function(e){const n=e.match(t);return n&&i[n[0]].test(e)}(s))&&(e=o(l=s)?JSON.parse(l):l),e}class s{static getPromise(e){return new Promise(((n,a)=>{GM_xmlhttpRequest({method:"GET",url:e,onload:function(e){const a=function(e){const n={};return e.forEach((e=>{const a=e.trim().split(":",2);a.length<2||(n[a[0].trim()]=a[1].trim())})),function(e){return n[e]||null}}(e.responseHeaders.split("\n"));let t=e.response;t=r(t,a);const i={data:t,status:e.status,headers:a,statusText:e.statusText};n(i)},onerror:function(e){a(e)}})}))}}function c(e){const n=document.implementation.createHTMLDocument("");return n.body.innerHTML=e,[...n.body.childNodes]}function l(e){const n=Object.prototype.toString.call(e);return n.substring(8,n.length-1)}class m{static getTradeRatios(e){if("Object"!==l(e)||!("tradable"in e)||!("wishlist"in e)||"Number"!==l(e.tradable)||"Number"!==l(e.wishlist)||e.tradable<0||e.wishlist<0)return console.error("Invalid input to getTradeRatios:"),console.error(e),null;const n=e.tradable/e.wishlist;return{real:`${e.tradable} : ${e.wishlist}`,index:(e.wishlist/e.tradable).toFixed(1),summary:`${n.toFixed(1)} : 1 (${e.tradable} : ${e.wishlist})`,relativeValue:"price"in e?e.price/100*(1+(e.wishlist-e.tradable)/(e.wishlist+e.tradable)):null}}}const d={games:0,totalTradable:0,totalWishlist:0,averageReviewScore:"N/A",averageWeightedReviewScore:"N/A",zeroReviewGames:0,voteCount:0,positiveVoteCount:0,weightedScoreAccumulator:0,gamesInBundles:0,totalBundles:0};function g(e,n){return e.totalTradable+=n.tradable,e.totalWishlist+=n.wishlist,0===n.user_reviews_total?e.zeroReviewGames++:(e.weightedScoreAccumulator+=n.user_reviews_positive*n.user_reviews_total,e.positiveVoteCount+=n.user_reviews_positive,e.voteCount+=n.user_reviews_total),e.gamesInBundles+=n.bundles_all>0?1:0,e.totalBundles+=n.bundles_all,e.games+=1,e}function p(e){const n=e.reduce(g,{...d});return n.voteCount>0&&(n.averageReviewScore=Number((n.positiveVoteCount/(n.games-n.zeroReviewGames)).toFixed(0)),n.averageWeightedReviewScore=Number((n.weightedScoreAccumulator/n.voteCount).toFixed(0))),n.ratios=m.getTradeRatios({tradable:n.totalTradable,wishlist:n.totalWishlist}),n}function u(e,n){return e.replace(/{(\d+)}/g,((e,a)=>void 0!==n[a]?n[a]:e))}class _{static getValue(e,n){return GM_getValue(e,n)}static setValue(e,n){return GM_setValue(e,n)}static listValues(){return GM_listValues()}static deleteValue(e){return GM_deleteValue(e)}}class h{static getItadGamePlains(e){const n=[],a=new Date;for(const t of Object.values(e)){const e=_.getValue(`itadPlainsCache.${t.item_id}`,"NOT_FOUND");if("NOT_FOUND"===e)n.push(t.item_id);else{const i=JSON.parse(e);null===i&&a-new Date(i.ts)>6048e5?(_.deleteValue(`itadPlainsCache.${t.item_id}`),n.push(t.item_id)):t.itad_id=i.itad_id}}return n}static saveItadGamePlain(e,n=new Date){if("itad_id"in e){const a={itad_id:e.itad_id};null===e.itad_id&&(a.ts=n),_.setValue("itadPlainsCache."+e.item_id,JSON.stringify(a))}}static saveItadGamePlains(e){const n=new Date;for(const a of Object.values(e))this.saveItadGamePlain(a,n)}static getGamePrice(e,n,a=new Date){const t=e.item_id,i=_.getValue(`${n}PriceCache.${t}`,"NOT_FOUND");if("NOT_FOUND"!==i){const o=JSON.parse(i);a-new Date(o.ts)>864e5?_.deleteValue(`${n}PriceCache.${t}`):e[`${n}_price`]=o[`${n}_price`]}}static getGamePrices(e,n){const a=new Date;for(const t in e)this.getGamePrice(e[t],n,a)}static saveGamePrice(e,n,a=new Date){const t=`${n}_price`;if(t in e){const i={ts:a,[t]:e[t]};_.setValue(`${n}PriceCache.${e.item_id}`,JSON.stringify(i))}}static saveGamePrices(e,n){const a=new Date;for(const t in e)this.saveGamePrice(e[t],n,a)}static clearCache(){for(const e of _.listValues())_.deleteValue(e)}}class b{static async getPrices(e){h.getGamePrices(e,"steam");const n={};if(!Object.values(e).filter((e=>"sku"in e&&1===e.platform_id&&!("steam_price"in e)&&(n[e.sku]=e,!0))).length)return new Promise((e=>{e(null)}));const a=Object.keys(n).map((e=>encodeURIComponent(e))).join(","),t=await s.getPromise(`http://store.steampowered.com/api/appdetails/?filters=price_overview&appids=${a}`);if(200===t.status){console.log("Steam prices"),console.log(t.data);for(const e in t.data)if(!0===t.data[e].success)if("Array"===l(t.data[e].data))n[e].steam_price=null;else{const a=t.data[e].data.price_overview;n[e].steam_price={price:a.final/100,price_old:a.initial/100,cut:a.discount_percent,currency:a.currency}}h.saveGamePrices(e,"steam")}return new Promise((e=>{e(t)}))}}const f={css:{style:"\n.small, span {\n font-size: 0.8rem;\n}\n.bve-game-details {\n display: flex;\n flex-direction: column;\n text-align: right;\n font-size: 0.8rem;\n line-height: 1.35;\n}\n.bve-trade-summary {\n width: 100%;\n}\n.bve-information-highlight {\n border-bottom: dotted 1px;\n cursor: help;\n font-size: 16px;\n}\n.ratio, .bundled {\n font-size: 1rem;\n padding: 0.25rem;\n}\n.matchcol li {\n padding: 0.4rem 0;\n}\n.tradables li {\n display: flex;\n border-bottom: 1px dotted dodgerblue;\n}\n.tradables_info {\n max-width: unset;\n flex: 380px 1;\n display: block;\n}\n.price-details img {\n max-height: 0.8rem;\n max-width: 0.8rem;\n}\n.matchcol {\n padding-top: 0;\n}\n.matchcol li {\n border-top: 1px solid #f60;\n}\n.matchcol.matcht li {\n border-color: #09f;\n}\n.game-details {\n display: inline-block;\n}\n.steam_price, .itad_price, .lowest_price {\n padding: 0.2rem;\n margin: 0.2rem;\n}\n"},html:{gameDetails:'<div class="bve-game-details"> <div>H:W Ratio: <span class="bve-game-details__trade-ratio">{0}</span></div> <div>Bundles: <span class="bve-game-details__trade-ratio">{1}</span></div> <div>Steam: <span class="bve-game-details__steam-price">Loading...</span></div> <div>ITAD: <span class="bve-game-details__itad-price">Loading...</span></div> <div>Lowest: <span class="bve-game-details__lowest-price">Loading...</span></div></div>',tradeSummary:'<table class="bve-trade-summary"> <caption>Trade summary:</caption> <tr> <th>Games that have been bundled</th> <td>{1}</td> </tr> <tr> <th>Total bundles</th> <td>{8}</td> </tr> <tr> <th>Average review score <span title="The more reviews it has, the proportionally larger that game\'s impact on the score" class="bve-information-highlight">(weighted)</span> </th> <td>{4}% ({5}%)</td> </tr> <tr> <th>Number of reviews <span title="The binary logarithm of the number of reviews. A difference of +1 means "twice as popular", and -1 means "half as popular"." class="bve-information-highlight">(log<sub>2</sub>)</span> </th> <td>{10} ({11})</td> </tr> <tr> <th>Tradability (H : W)</th> <td>{6} ({9})</td> </tr> <tr> <th>Total price on Steam (ignoring any active discounts)</th> <td id="{12}_total_steam">Loading...</td> </tr> <tr> <th>Average price per game on Steam (ignoring any active discounts)</th> <td id="{12}_average_steam">Loading...</td> </tr> <tr> <th>Best price on ITAD</th> <td id="{12}_total_itad">Loading...</td> </tr></table>'}},v="27ebda8ff1e410917ae5b1f17af235783a9e335a",y="https://api.isthereanydeal.com/";class w{static async getPlainsById(e,n){if("1"===n){const n=h.getItadGamePlains(e),a={},t=n.filter((n=>"sku"in e[n])).map((n=>{const t=`app/${e[n].sku}`;return a[t]=e[n],t})).join(","),i=await s.getPromise(`${y}v01/game/plain/id/?key=${v}&shop=steam&ids=${encodeURIComponent(t)}`);if(200===i.status)for(const e in i.data.data){const n=i.data.data[e];if(null!==n){a[e].itad_id=n;const t=a[e],i=t.title.toLowerCase().replace("&"," and ").replace(/&[a-z]+;/g,"").replace(/([1-9])/g,(e=>{switch(Number(e)){case 1:return"i";case 2:return"ii";case 3:return"iii";case 4:return"iv";case 5:return"v";case 6:return"vi";case 7:return"vii";case 8:return"viii";case 9:return"ix"}})).replace(/(^| )the /g," ").replace(/[^a-z0-9]+/g,"");t.itad_id!==i&&console.log(`${t.title}: plain: ${t.itad_id}, expected ${i}`),h.saveItadGamePlain(t)}}}return new Promise((e=>e()))}static async getPrices(e,n=!1){const a=n?"lowest":"itad",t=n?"v01/game/lowest/":"v01/game/prices/";await w.getPlainsById(e,"1"),h.getGamePrices(e,a);const i={},o=Object.values(e).filter((e=>"itad_id"in e)).map((e=>(i[e.itad_id]=e,e.itad_id))).join(","),r=await s.getPromise(`${y}${t}?key=${v}&plains=${encodeURIComponent(o)}`);return 200===r.status&&(console.log(`ITAD ${n?"lowest":"current"} prices`),console.log(r.data),n?w._processLowestPrices(r,i):w._processCurrentPrices(r,i)),new Promise((e=>e()))}static _processCurrentPrices(e,n){const a=new Date,t=e.data[".meta"].currency;for(const i in e.data.data){if(e.data.data[i].list.length){const a=e.data.data[i].list[0];n[i].itad_price={shop:a.shop,price_old:a.price_old,price:a.price_new,cut:0===a.price_new?100:a.price_cut,currency:t}}else n[i].itad_price=null;h.saveGamePrice(n[i],"itad",a)}}static _processLowestPrices(e,n){const a=new Date,t=e.data[".meta"].currency;for(const i in e.data.data)"price"in e.data.data[i]?n[i].lowest_price={shop:e.data.data[i].shop,price:e.data.data[i].price,currency:t,cut:0===e.data.data[i].price?100:e.data.data[i].cut}:n[i].lowest_price=null,h.saveGamePrice(n[i],"lowest",a)}static getLowestPrices(e){return w.getPrices(e,!0)}}function G(e,n){return u(f.html.tradeSummary,{1:e.gamesInBundles,4:e.averageReviewScore,5:e.averageWeightedReviewScore,6:e.ratios.index,8:e.totalBundles,9:e.ratios.real,10:e.voteCount,11:(Math.log(e.voteCount)/Math.log(2)).toFixed(2),12:n})}function P(e){const n=document.querySelectorAll(".tradables"),a={to:[],from:[]};for(const n of Object.values(e))a[n.trade_direction].push(n),S(n);const t={};for(const e of["from","to"])t[e]=p(a[e]);const i=G(t.from,"offered");n[0].appendChild(c(i)[0]);const o=G(t.to,"requested");return n[1].prepend(c(o)[0]),function(e){return Object.values(e).forEach((e=>{const n=m.getTradeRatios(e),a=e.element,t=c(u(f.html.gameDetails,{0:n.summary,1:"bundles_all"in e?`${e.bundles_all} (${e.bundles_available} current)`:"none"}));a.append(...t);for(const n of["steam","itad","lowest"])e[`${n}PriceEl`]=a.querySelector(`.bve-game-details__${n}-price`);e.tradeRatioEl=a.querySelector(".bve-game-details__trade-ratio")})),new Promise((e=>e()))}(e)}function S(e){const n=document.querySelector(`.tradables_items_list li[data-item-id="${e.item_id}"]`);n?e.element=n:console.warn("Could not find HTML element for game",e.item_id)}const k={game2:{id:"game2",title:"2game",barter_vg_id:73},allyouplay:{id:"allyouplay",title:"AllYouPlay",barter_vg_id:141},amazonus:{id:"amazonus",title:"Amazon",barter_vg_id:12},battlenet:{id:"battlenet",title:"Blizzard",barter_vg_id:80},dlgamer:{id:"dlgamer",title:"DLGamer",barter_vg_id:42},direct2drive:{id:"direct2drive",title:"Direct2Drive",barter_vg_id:74},dreamgame:{id:"dreamgame",title:"Dreamgame",barter_vg_id:75},epic:{id:"epic",title:"Epic Game Store",barter_vg_id:66},bundlestars:{id:"bundlestars",title:"Fanatical",barter_vg_id:8},fireflower:{id:"fireflower",title:"FireFlower",barter_vg_id:0},gog:{id:"gog",title:"GOG",barter_vg_id:4},gamejolt:{id:"gamejolt",title:"Game Jolt",barter_vg_id:0},gamebillet:{id:"gamebillet",title:"GameBillet",barter_vg_id:144},impulse:{id:"impulse",title:"GameStop PC",barter_vg_id:145},gamersgate:{id:"gamersgate",title:"GamersGate",barter_vg_id:11},gamesplanetde:{id:"gamesplanetde",title:"GamesPlanet DE",barter_vg_id:43},gamesplanetfr:{id:"gamesplanetfr",title:"GamesPlanet FR",barter_vg_id:43},gamesplanet:{id:"gamesplanet",title:"GamesPlanet UK",barter_vg_id:43},gamesplanetus:{id:"gamesplanetus",title:"GamesPlanet US",barter_vg_id:43},gamesrepublic:{id:"gamesrepublic",title:"GamesRepublic",barter_vg_id:72},gamesload:{id:"gamesload",title:"Gamesload",barter_vg_id:207},greenmangaming:{id:"greenmangaming",title:"GreenManGaming",barter_vg_id:20},humblestore:{id:"humblestore",title:"Humble Store",barter_vg_id:13},humblewidgets:{id:"humblewidgets",title:"Humble Widgets",barter_vg_id:13},indiegalastore:{id:"indiegalastore",title:"IndieGala Store",barter_vg_id:7},itchio:{id:"itchio",title:"Itch.io",barter_vg_id:28},joybuggy:{id:"joybuggy",title:"JoyBuggy",barter_vg_id:0},macgamestore:{id:"macgamestore",title:"MacGameStore",barter_vg_id:22},microsoft:{id:"microsoft",title:"Microsoft Store",barter_vg_id:133},newegg:{id:"newegg",title:"Newegg",barter_vg_id:76},noctre:{id:"noctre",title:"Noctre",barter_vg_id:0},nuuvem:{id:"nuuvem",title:"Nuuvem",barter_vg_id:21},origin:{id:"origin",title:"Origin",barter_vg_id:0},squenix:{id:"squenix",title:"Square Enix",barter_vg_id:37},steam:{id:"steam",title:"Steam",barter_vg_id:1},uplay:{id:"uplay",title:"Ubisoft Store",barter_vg_id:14},voidu:{id:"voidu",title:"Voidu",barter_vg_id:122},wingamestore:{id:"wingamestore",title:"WinGameStore",barter_vg_id:34},etailmarket:{id:"etailmarket",title:"eTail.Market",barter_vg_id:0}},x={0:{name:"",icon:"unspecified2.png"},73:{name:"2game",icon:"2game.png"},211:{name:"3Kropki.pl",icon:"3kropki.png"},48:{name:"99 Cent Bundle",icon:"99cent.png"},124:{name:"akens.ru",icon:"akens.png"},131:{name:"Alienware",icon:"alienware.png"},141:{name:"Allyouplay",icon:"allyouplay.png"},134:{name:"Alpha Bundle",icon:"alphabundle.png"},12:{name:"Amazon",icon:"amazon.png"},184:{name:"AMD Rewards",icon:"amd.png"},176:{name:"Apple",icon:"apple.png"},147:{name:"ArenaNet",icon:"arenanet.png"},165:{name:"Bananagiveaway.com",icon:"bananag.png"},194:{name:"BANDAI NAMCO",icon:"bandai.png"},57:{name:"Barter.vg",icon:"barter.png"},80:{name:"battle.net",icon:"battlenet.png"},142:{name:"Best Buy",icon:"bestbuy.png"},148:{name:"Bethesda.net",icon:"bethesda.png"},120:{name:"Bitcoin Bundle",icon:"bitcoin.png"},87:{name:"Blink Bundle",icon:"blinkbundle.png"},50:{name:"Bread Box Bundle",icon:"breadbox.png"},137:{name:"BrightLocker",icon:"brightlocker.png"},45:{name:"Bunch of Keys",icon:"bunchkeys.png"},89:{name:"Bundle Bandits",icon:"bbandits.png"},90:{name:"Bundle Central",icon:"bcentral.png"},91:{name:"Bundle Dragon",icon:"bdragon.png"},92:{name:"Bundle In A Box",icon:"biab.png"},39:{name:"Bundle Kings",icon:"bundlekings.png"},118:{name:"Buy Games Not Socks",icon:"socks.png"},59:{name:"CDKeys.com",icon:"cdkeys.png"},193:{name:"ChampionFlow",icon:"championflow.png"},117:{name:"Charlie's Games",icon:"charlies.png"},41:{name:"Chrono.gg",icon:"chronogg.png"},167:{name:"Chubkeys",icon:"chubkeys.png"},224:{name:"CJS-CDKeys",icon:"blank.png"},27:{name:"Coinplay.io",icon:"coinplay.png"},222:{name:"Corel",icon:"corel.png"},226:{name:"Crucial Games",icon:"crucial.png"},31:{name:"Cubic Bundle",icon:"cubicbundle.png"},93:{name:"Cult of Mac",icon:"cultofmac.png"},109:{name:"CY Bundle",icon:"cybundle.png"},17:{name:"DailyIndieGame",icon:"dailyindie.png"},6:{name:"Desura",icon:"desura.png"},74:{name:"Direct2Drive",icon:"d2d.png"},110:{name:"Discord",icon:"discord.png"},42:{name:"DLGamer",icon:"dlgamer.png"},152:{name:"Dlh.net",icon:"dlhnet.png"},63:{name:"DogeBundle",icon:"dogebundle.png"},75:{name:"Dreamgate",icon:"dreamgate.png"},200:{name:"dupedornot",icon:"dupedornot.png"},5:{name:"EA",icon:"ea.png"},218:{name:"Elkjøp / Elgiganten",icon:"elgiganten.png"},79:{name:"Embloo",icon:"embloo.png"},210:{name:"Eneba",icon:"eneba.png"},66:{name:"Epic Games Store",icon:"epicgamesstore.png"},94:{name:"Eurobundle",icon:"eurobundle.png"},228:{name:"F2P.com",icon:"f2p.png"},8:{name:"Fanatical",icon:"fanatical.png"},84:{name:"Fangamer",icon:"fangamer.png"},125:{name:"FarmKEYS",icon:"farmkeys.png"},18:{name:"Flying Bundle",icon:"flyingbundle.png"},213:{name:"FreeAnywhere.net",icon:"freeanywhere2.png"},191:{name:"FreeToGame.com",icon:"freetogame.png"},113:{name:"From boxed copy",icon:"disc.png"},159:{name:"From Dev / Pub",icon:"devsource.png"},46:{name:"G2A",icon:"g2a.png"},83:{name:"G2play",icon:"g2play.png"},217:{name:"Gamazavr.ru",icon:"gamazavr.png"},173:{name:"Game Junkie",icon:"gamejunkie.png"},143:{name:"GAME UK",icon:"gameuk.png"},144:{name:"Gamebillet",icon:"gamebillet.png"},40:{name:"GameBundle",icon:"gamebundle.png"},162:{name:"Gamecode.win",icon:"gamecodewin.png"},177:{name:"GameDev.tv",icon:"gamedevtv.png"},221:{name:"Gameflip",icon:"gameflip.png"},227:{name:"Gameflix.ru",icon:"gameflixru.png"},149:{name:"Gamehag",icon:"gamehag.png"},155:{name:"GAMEHUNT",icon:"gamehunt.png"},103:{name:"Gameolith",icon:"gameolith.png"},233:{name:"Gamerpower",icon:"gamerpower.png"},11:{name:"GamersGate",icon:"gamersgate.png"},88:{name:"Games Rage",icon:"gamesrage.png"},72:{name:"Games Republic",icon:"grepublic.png"},201:{name:"GamesBolt",icon:"gamebolt.png"},207:{name:"GAMESLOAD",icon:"gamesload.png"},43:{name:"Gamesplanet",icon:"gamesplanet.png"},145:{name:"GameStop",icon:"gamestop.png"},164:{name:"Gamezito",icon:"gamezito.png"},216:{name:"Gaming Dragons",icon:"dragons.png"},81:{name:"Gamivo",icon:"gamivo.png"},123:{name:"gemly",icon:"gemly.png"},82:{name:"Get Games Go",icon:"getgames.png"},192:{name:"Giveaway of the Day",icon:"giveawayoftheday.png"},153:{name:"GiveAway.su",icon:"giveawaysu.png"},166:{name:"GiveawayHopper",icon:"ghopper.png"},231:{name:"givee.club",icon:"givee.png"},186:{name:"Givekey.ru",icon:"givekey.png"},154:{name:"Gleam",icon:"gleam.png"},212:{name:"Godankey",icon:"godankey.png"},4:{name:"GOG",icon:"gog.png"},58:{name:"GoGoBundle",icon:"gogobundles.png"},179:{name:"Google",icon:"google.png"},204:{name:"Grab The Games",icon:"grabthegame.png"},156:{name:"GrabFreeGame",icon:"grabfreegame.png"},95:{name:"gram.pl",icon:"gram.png"},16:{name:"Green Light Bundle",icon:"greenlight.png"},20:{name:"Green Man Gaming",icon:"gmg.png"},127:{name:"Greenlight Arcade",icon:"greenlighta.png"},9:{name:"Groupees",icon:"groupees3.png"},128:{name:"H2O Bundle",icon:"h2o.png"},232:{name:"HitSquad Games",icon:"hitsquad.png"},33:{name:"HRK",icon:"hrk.png"},3:{name:"Humble Bundle",icon:"humblebundle.png"},13:{name:"Humble Store",icon:"humblebundle.png"},85:{name:"Humble Trove",icon:"trove.png"},214:{name:"Idle-Empire",icon:"idle-empire.png"},229:{name:"iGames.gg",icon:"igames.png"},132:{name:"IGN",icon:"ign.png"},96:{name:"Indie Ammo Box",icon:"indieammo.png"},170:{name:"Indie DB",icon:"indiedb.png"},161:{name:"Indie Face Kick",icon:"indiefacekick.png"},10:{name:"Indie Royale",icon:"indieroyale.png"},115:{name:"Indie-games pack",icon:"igpack.png"},97:{name:"IndieBundle",icon:"iborg.png"},68:{name:"IndieDeals.net",icon:"indiedeals2.png"},121:{name:"IndieFort",icon:"gamersgate.png"},7:{name:"Indiegala",icon:"indiegala.png"},24:{name:"IndieGameStand",icon:"igamestand.png"},206:{name:"Intel",icon:"intel.png"},199:{name:"io interactive",icon:"ioi.png"},28:{name:"itch.io",icon:"itchio.png"},195:{name:"Jackbox Games",icon:"jackbox.png"},235:{name:"K4G",icon:"k4g.png"},220:{name:"Kalypso Media",icon:"kalypso.png"},150:{name:"Kartridge",icon:"kartridge.png"},202:{name:"Keyhub",icon:"keyhub.png"},158:{name:"KeyJoker",icon:"keyjoker.png"},223:{name:"Keysora",icon:"blank.png"},205:{name:"Kickstarter",icon:"kickstarter.png"},60:{name:"Kinguin",icon:"kinguin.png"},98:{name:"KissMyBundles",icon:"kissmb.png"},174:{name:"Last Best Offer",icon:"lbo.png"},15:{name:"Lazy Guys Bundle",icon:"lazyguys.png"},234:{name:"Legacy Games",icon:"legacygames.png"},111:{name:"lequestore",icon:"lequestore.png"},140:{name:"Loot Crate",icon:"lootcrate.png"},151:{name:"LootBoy",icon:"lootboy.png"},22:{name:"MacGameStore",icon:"macgamestore.png"},99:{name:"MadOrc",icon:"madorc.png"},56:{name:"MarvelousCrate",icon:"marvelous.png"},163:{name:"MarvelousGA",icon:"marvelousga.png"},133:{name:"Microsoft Store",icon:"microsoft.png"},187:{name:"MMOBomb",icon:"mmobomb.png"},208:{name:"MMOGA",icon:"mmoga.png"},190:{name:"MMOGames.com",icon:"mmogames2.png"},171:{name:"MMORPG.com",icon:"mmorpg.png"},76:{name:"Newegg",icon:"newegg.png"},25:{name:"Nintendo 3DS",icon:"3ds.png"},183:{name:"Nintendo Switch",icon:"switch.png"},21:{name:"Nuuvem",icon:"nuuvem.png"},180:{name:"NVIDIA",icon:"nvidia.png"},185:{name:"NVIDIA Rewards",icon:"nvidia.png"},129:{name:"Oculus",icon:"oculus.png"},30:{name:"one more bundle",icon:"onemore.png"},135:{name:"Opium Pulses",icon:"opiumpulses.png"},230:{name:"OPQuests",icon:"opquests.png"},36:{name:"Orlygift",icon:"orlygift.png"},62:{name:"Otaku Bundle",icon:"otakubundle.png"},38:{name:"OtakuMaker",icon:"otakumaker.png"},197:{name:"OVERKILL Software",icon:"overkillsoftware.png"},138:{name:"Oy Vey Keys",icon:"oyvey2.png"},100:{name:"Paddle",icon:"paddle.png"},101:{name:"PayWUW",icon:"paywuw.png"},203:{name:"PC Gamer",icon:"pcgamer.png"},102:{name:"Peon Bundle",icon:"peonb.png"},64:{name:"Plati",icon:"plati.png"},23:{name:"Playinjector",icon:"playinjector.png"},225:{name:"Playism",icon:"playism.png"},52:{name:"PlayStation 3",icon:"ps3.png"},51:{name:"PlayStation 4",icon:"ps4.png"},219:{name:"Playstation 5",icon:"ps4.png"},169:{name:"Project Z",icon:"projectz.png"},188:{name:"Prys",icon:"prys.png"},78:{name:"PSN",icon:"ps4.png"},77:{name:"PSVita",icon:"ps3.png"},114:{name:"PuppyGames",icon:"puppygames.png"},130:{name:"Razer",icon:"razer.png"},49:{name:"Redacted Network",icon:"redacted.png"},112:{name:"Rockstar Social Club",icon:"rockstar.png"},198:{name:"Running With Scissors",icon:"rws.png"},104:{name:"Select n' Play",icon:"selectnp.png"},105:{name:"ShinyLoot",icon:"shinyloot.png"},44:{name:"Sila Games",icon:"silagames.png"},209:{name:"SONKWO",icon:"sonkwo.png"},37:{name:"Square Enix",icon:"squareenix.png"},106:{name:"StackSocial",icon:"stacksocial.png"},139:{name:"Stardock",icon:"stardock.png"},1:{name:"Steam",icon:"steam.png"},35:{name:"Steam Greenlight",icon:"sgreenlight.png"},19:{name:"Steam Item",icon:"steam.png"},2:{name:"Steam Package",icon:"steam.png"},86:{name:"Steam-tracker",icon:"steam-tracker.png"},55:{name:"Steamgifts.com",icon:"steamgifts.png"},47:{name:"Steamground",icon:"steamground.png"},65:{name:"Steamtrades.com",icon:"streamtrades.png"},168:{name:"SteelSeries",icon:"steelseries.png"},119:{name:"Subsoap",icon:"subsoap.png"},116:{name:"Super Shock Bundle",icon:"supershock.png"},29:{name:"Super-Duper Bundle",icon:"superduper.png"},189:{name:"Takekey.ru",icon:"takekey.png"},32:{name:"Telltale Games",icon:"telltale.png"},69:{name:"The Indie Games Bundle",icon:"tigb.png"},70:{name:"Tiltify",icon:"tiltify.png"},126:{name:"TKFG",icon:"tkfg.png"},71:{name:"Tremor Games",icon:"tremorgames.png"},67:{name:"Twitch",icon:"twitch.png"},14:{name:"Ubisoft Connect",icon:"ubisoft.png"},175:{name:"Unity Asset Store",icon:"unity.png"},107:{name:"Universala",icon:"universala.png"},61:{name:"Unspecified Platform",icon:"unspecified2.png"},196:{name:"Victorage Giveaways",icon:"victorage.png"},108:{name:"VODO",icon:"vodo.png"},122:{name:"Voidu",icon:"voidu.png"},160:{name:"WeGame X",icon:"wegamex.png"},157:{name:"Who's Gaming Now?!",icon:"wgn.png"},26:{name:"WiiU",icon:"wiiu.png"},34:{name:"WinGameStore",icon:"wingamestore.png"},53:{name:"Xbox 360",icon:"xb360.png"},146:{name:"Xbox Live",icon:"xbone.png"},54:{name:"Xbox One",icon:"xbone.png"},215:{name:"Yuplay.ru",icon:"yuplay.png"},172:{name:"zeepond.com",icon:"blank.png"},178:{name:"Zenva Academy",icon:"zenva.png"}};function T(e){return e in k&&"barter_vg_id"in k[e]?x[k[e].barter_vg_id].icon:x[0].icon}const B=/https:\/\/barter.vg\/i\/(\d+)\//,O="⛁";function D(e,n){return`<img src="https://bartervg.com/imgs/ico/${n}" alt="${e}" class="price-link" />`}function C(e){if(e.steamPriceHtml=`${D("Steam","steam.png")} <abbr title="not available">N/A</abbr>`,"steam_price"in e&&null!==e.steam_price)try{e.steamPriceHtml=`<a href="https://store.steampowered.com/app/${e.sku}/" title="${e.title} on Steam">${D("Steam","steam.png")} ${e.steam_price.price}</a>`}catch(n){console.log({item_id:e.item_id,steam:e.steam_price})}N(e,"steam")}function A(e){if("itad_id"in e){if(e.itadPriceHtml='ITAD: <a href="https://isthereanydeal.com/game/'+e.itad_id+'/info/">N/A</a>',"itad_price"in e&&null!==e.itad_price)try{const n=T(e.itad_price.shop.id);e.itadPriceHtml=`<a href="https://isthereanydeal.com/game/${e.itad_id}/info/" title="Best current price: ${e.itad_price.price.toFixed(2)} at ${e.itad_price.shop.name}">${D(e.itad_price.shop.name,n)} ${e.itad_price.price.toFixed(2)}</a>`}catch(n){console.log({item_id:e.item_id,itad:e.itad_price})}N(e,"itad")}}function M(e){if("itad_id"in e){if(e.lowestPriceHtml='Best: <a href="https://isthereanydeal.com/game/'+e.itad_id+'/info/">N/A</a>',"lowest_price"in e&&null!==e.lowest_price)try{const n=T(e.lowest_price.shop.id);e.lowestPriceHtml=`<a href="https://isthereanydeal.com/game/${e.itad_id}/info/" title="Best historical price: ${e.lowest_price.price.toFixed(2)} at ${e.lowest_price.shop.name}">${D(e.lowest_price.shop.name,n)} ${e.lowest_price.price.toFixed(2)}</a>`}catch(n){console.log({item_id:e.item_id,itad:e.lowest_price})}N(e,"lowest")}}function N(e,n){for(const a of e.elArray)a.querySelector(`.${n}_price`).innerHTML=e[`${n}PriceHtml`]}function I(e,n){const a={steam:C,itad:A,lowest:M};Object.values(e).forEach((e=>{a[n](e)}))}function L(e){return Object.values(e).forEach((e=>{const n="price_ratio_data"in e?e.price_ratio_data:function(e){"ratios"in e||(e.ratios=m.getTradeRatios(e));const n={1:e.ratios.index,2:`${e.bundles_all}${O}`,3:e.item_id};return e.price_ratio_data=u('<div class="game-details"><span class="ratio" title="Game tradability index">{1}</span><span class="bundled" title="how many times the game has been bundled">{2}</span></div><div class="price-details"><span class="steam_price"></span><span class="itad_price"></span><span class="lowest_price"></span></div>',n),e.price_ratio_data}(e),a=n;for(const n of e.elArray){c(a).forEach((e=>{const a=e.querySelector(".showMoreToggle");a?a.parentNode.insertBefore(e,a):n.appendChild(e)}))}})),new Promise((e=>{e()}))}class E{ready(){"loading"!==document.readyState?E.getData():document.addEventListener("DOMContentLoaded",E.getData)}static async getData(){if(null===document.querySelector("#mutualmatches"))return;const e=function(){const e={};return document.querySelectorAll('.matchcol li a[href^="https://barter.vg/i/"]').forEach((n=>{const a=n.href.match(B);if(a){const t=a[1];t in e||(e[t]=[]),e[t].push(n.parentElement)}})),e}(),n=await async function(e){const n=window.location.href.replace(/[wt]\/m\/\??/,""),[a,t]=await Promise.all([s.getPromise(`${n}t/json`),s.getPromise(`${n}w/json`)]).catch((e=>{console.log("oh shit, an error!"),console.log(e)})),i={};return Object.values(Object.assign(...Object.values(a.data.by_platform),...Object.values(t.data.by_platform))).forEach((n=>{n.item_id in e&&(i[n.item_id]={...n,elArray:e[n.item_id]})})),i}(e);await Promise.all([L(n),w.getPrices(n).then((()=>{I(n,"itad")})),w.getLowestPrices(n).then((()=>{I(n,"lowest")})),b.getPrices(n).then((()=>{I(n,"steam")}))])}static get routes(){return[new e(/^https:\/\/barter\.vg\/u\/.+\/[wt]\/m\/\??$/,this,this.prototype.ready,null)]}}var F=[class{static get routes(){return[new e(/^https:\/\/barter\.vg\/u\/.+\/o\/.+\/$/,this,this.prototype.index,(()=>"Creating..."!==$(".statusCurrent").text()))]}async index(){const e=await s.getPromise(`${window.location.href}json`);if(200!==e.status)throw new Error("Oh shit!");const n=function(e){const n=e,a={to:[],from:[],all:{}};for(const e of["to","from"])for(const t of Object.values(n.items[e]))t.platform_id=t.platform,t.trade_direction=e,a.all[t.item_id]=t,a[e].push(t.item_id);return a}(e.data);await Promise.all([P(n.all),b.getPrices(n.all),w.getPrices(n.all),w.getLowestPrices(n.all)]),function(e){const{currency:n}=e,a={to:{total:"#requested_total_steam",itad:"#requested_total_itad",average:"#requested_average_steam"},from:{total:"#offered_total_steam",itad:"#offered_total_itad",average:"#offered_average_steam"}};for(const t of["to","from"])document.querySelector(a[t].total).innerHTML=`${e[t].steamTotal.toFixed(2)} ${n} (${e[t].steamTotalOld.toFixed(2)} ${n})`,document.querySelector(a[t].itad).innerHTML=`${e[t].itadTotal.toFixed(2)} ${n}`,document.querySelector(a[t].average).innerHTML=`${(e[t].steamTotal/e[t].nGames).toFixed(2)} ${n} (${(e[t].steamTotalOld/e[t].nGames).toFixed(2)} ${n})`}(function(e){const n={to:{nGames:0,steamTotal:0,steamTotalOld:0,itadTotal:0,lowestTotal:0},from:{nGames:0,steamTotal:0,steamTotalOld:0,itadTotal:0,lowestTotal:0}};let a;for(const t of Object.values(e.all)){if(n[t.trade_direction].nGames++,"steam_price"in t){t.steamPriceEl.innerHTML="Not available";try{let e=`${t.steam_price.price} ${t.steam_price.currency}`;0===t.steam_price.price?(e="Free",t.steamPriceEl.setAttribute("style","color: green")):0!==t.steam_price.cut&&(e+=` (${t.steam_price.cut}% off)`),t.steamPriceEl.innerHTML=e,n[t.trade_direction].steamTotal+=t.steam_price.price,n[t.trade_direction].steamTotalOld+=t.steam_price.price_old,a||(a=t.steam_price.currency)}catch(e){console.log({item_id:t.item_id,...t.steam_price})}}for(const e of["itad","lowest"]){t[`${e}PriceEl`].innerHTML="Not available";try{t[`${e}PriceEl`].innerHTML=`${t[`${e}_price`].shop.name}: ${t[`${e}_price`].price.toFixed(2)} ${t[`${e}_price`].currency}`,n[t.trade_direction][`${e}Total`]+=t[`${e}_price`].price,a||(a=t[`${e}_price`].currency)}catch(n){console.log({item_id:t.item_id,...t[`${e}_price`]})}}}return n.currency=a,n}(n))}},E];const j=document.createElement("style");j.setAttribute("type","text/css"),j.textContent=f.css.style,document.querySelector("head").append(j);const R=new class{constructor(){this.routes=[]}registerRoutes(e){const n=this;e.forEach((e=>{n.routes.push(e)}))}route(){let e=null;if(this.routes.forEach((n=>{if(null===e&&n.regex.test(window.location.href)){if(!n.hasPredicate)return void(e=n);n.predicate()&&(e=n)}})),null!==e){const n=new e.controller;return e.action.call(n),!0}return!1}};F.forEach((e=>{R.registerRoutes(e.routes)})),R.route()}();
//# sourceMappingURL=bundle.js.map