Guest User

Untitled

a guest
Dec 19th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 49.50 KB | None | 0 0
  1. There you go you lazy shit.
  2.  
  3. var app_id = window.location.hostname == 'dota2lounge.com' ? '570' : '730';
  4. var cleanparse = false;
  5. var inexactAlert = false;
  6. var bets = {};
  7. var version = '0.3.6RC';
  8. var newVersion = (localStorage['LoungeStats_lastversion'] != version);
  9.  
  10. var setting_method = localStorage['LoungeStats_setting_method'];
  11. var setting_currency = localStorage['LoungeStats_setting_currency'];
  12. var setting_bvalue = localStorage['LoungeStats_setting_bvalue'];
  13. var setting_xaxis = localStorage['LoungeStats_setting_xaxis'];
  14. var setting_debug = localStorage['LoungeStats_setting_debug'];
  15. var setting_beforedate = localStorage['LoungeStats_setting_beforedate'];
  16. var setting_domerge = localStorage['LoungeStats_setting_domerge'];
  17.  
  18. var loading = false;
  19. var user_steam64 = $('#profile .full:last-child input').val().split('=').pop();
  20. var accounts = {aval:{}, active:[]};
  21.  
  22. if('LoungeStats_accounts' in localStorage) accounts = JSON.parse(localStorage['LoungeStats_accounts']);
  23.  
  24. function addAcc(id, name) {
  25. accounts['aval'][id] = name;
  26. localStorage['LoungeStats_accounts'] = JSON.stringify(accounts);
  27. }
  28.  
  29. var currencysymbol = '$';
  30. var currencyText = 'USD';
  31.  
  32. function setCurrencySymbol(){
  33. if(setting_currency == '3') {
  34. currencysymbol = '€';
  35. currencyText = 'EUR';
  36. }
  37. else if(setting_currency == '2') {
  38. currencysymbol = '£';
  39. currencyText = 'GBP';
  40. }
  41. else if(setting_currency == '5') {
  42. currencysymbol = 'p';
  43. currencyText = 'RUB';
  44. }
  45. else if(setting_currency == '1') {
  46. currencysymbol = '$';
  47. currencyText = 'USD';
  48. } else {
  49. currencysymbol = 'R$';
  50. currencyText = 'BRL';
  51. }
  52. }
  53.  
  54. //Well, since you cant force the market price (exact algo) this has to do the trick.
  55. var curr_usd_eur = 1.266215;
  56. var curr_usd_gbp = 1.603485;
  57. var curr_usd_rub = 0.02423;
  58. var curr_usd_brd = 0.403356;
  59.  
  60. //http://stackoverflow.com/a/6700/3526458
  61. Object.size = function(obj) {
  62. var size = 0, key;
  63. for (key in obj) {
  64. if (key in obj) size++;
  65. }
  66. return size;
  67. };
  68. //http://stackoverflow.com/a/6562764/3526458
  69. function clearSelection() {
  70. if(document.selection) {
  71. document.selection.empty();
  72. } else if(window.getSelection) {
  73. window.getSelection().removeAllRanges();
  74. }
  75. }
  76. //http://stackoverflow.com/a/5812341/3526458
  77. function isValidDate(s) {
  78. var bits = s.split('.');
  79. var d = new Date(bits[2], bits[1] - 1, bits[0]);
  80. return d && (d.getMonth() + 1) == bits[1] && d.getDate() == Number(bits[0]);
  81. }
  82.  
  83. function getLoungeBetHistory(callback) {
  84.  
  85. if(app_id == '730') {
  86. $.ajax({
  87. url: 'ajax/betHistory.php',
  88. type: 'POST',
  89. success: function(data) {callback(data);},
  90. error: function() {callback(null);}
  91. });
  92. } else {
  93. $.ajax({
  94. url: 'ajax/betHistory.php',
  95. type: 'POST',
  96. success: function(data) {
  97. $.ajax({
  98. url: 'ajax/betHistoryArchives.php',
  99. type: 'POST',
  100. success: function(dataArchived) {callback(data.split('</tbody>')[0]+dataArchived.split('<tbody>')[1]);},
  101. error: function() {callback(null);}
  102. });
  103. },
  104. error: function() {callback(null);}
  105. });
  106. }
  107. }
  108.  
  109. function parseLoungeBetHistory(html, callback) {
  110. var doommeedd = $.parseHTML(html);
  111. var cacheWeapons = {}; bets = {}; var donerequests = 0;
  112.  
  113. // Preparse, get all matches, all overal needed weapons and arrify them
  114.  
  115. $($(doommeedd).find('tr:nth-child(3n+1)').get().reverse()).each(function(i, bet) {
  116. var betid = bet.children[2].children[0].href.split('=').pop();
  117.  
  118. if(setting_debug == '1') console.log('Parsing match #' + betid);
  119.  
  120. if(!(('LoungeStats_betcache_s'+user_steam64+'_'+betid) in localStorage) || cleanparse || newVersion) {
  121. //Match wasnt cached, parse & cache...
  122. var date = bet.children[6].textContent;
  123. var matchoutcome = bet.children[1].children[0].classList[0];
  124. if(!matchoutcome) matchoutcome = "draw";
  125. var tocache = {'matchid': betid, 'date': date, 'intdate': new Date(Date.parse(date.replace(/-/g,' ') + ' +0')).getTime(), 'matchoutcome': matchoutcome, 'items': {'bet':[], 'won':[], 'lost':[]}};
  126.  
  127. tocache.teams = [bet.children[2].children[0].textContent, bet.children[4].children[0].textContent];
  128. tocache.winner = (bet.children[4].style.fontWeight == 'bold')+0;
  129.  
  130. var betItems = $(bet).next().find('div > div.name > b:first-child');
  131. var wonItems = $(bet).next().next().find('div > div.name > b:first-child');
  132.  
  133. //Iterate trough all the items and add them to an array
  134. $(betItems).each(function(i, item) {
  135. var itemname = item.textContent.trim();
  136. tocache.items.bet.push(itemname);
  137. if(wonItems.length === 0 && matchoutcome && matchoutcome != 'won' && matchoutcome != 'draw'/*matchoutcome == 'lost' Lounge admins are retarded*/) {
  138. tocache.items.lost.push(itemname);
  139. }
  140. });
  141. //if(matchoutcome == 'won') {
  142. $(wonItems).each(function(i, item) {
  143. var itemname = item.textContent.trim();
  144. tocache.items.won.push(itemname);
  145. });
  146. //}
  147. if(setting_debug == '1') console.log(tocache);
  148.  
  149. localStorage['LoungeStats_betcache_s'+user_steam64+'_'+betid] = JSON.stringify(tocache);
  150. }
  151. });
  152.  
  153. addAcc(user_steam64, $('#profile h1:first-child').text());
  154.  
  155. var useaccs = accounts.active;
  156.  
  157. var bits = setting_beforedate.split('.');
  158. var d = new Date(bits[2], bits[1]-1, bits[0]).getTime();
  159.  
  160. if(!setting_domerge || setting_domerge == '0') useaccs = [user_steam64];
  161.  
  162. for(var x in useaccs) {
  163. var accid = useaccs[x];
  164. for(var lSKey in localStorage) {
  165. if(lSKey.indexOf('LoungeStats_betcache_s'+accid+'_') != -1) {
  166. var parsedStorage = JSON.parse(localStorage[lSKey]);
  167. //var tocache = {'matchid': betid, 'date': date, 'matchoutcome': matchoutcome, 'items': {'bet':[], 'won':[], 'lost':[]}};
  168.  
  169. if(parsedStorage.intdate > d) {
  170. var key = parsedStorage.intdate.toString() + parsedStorage.matchid;
  171. if(!(key in bets)) {
  172. bets[key] = parsedStorage;
  173. } else {
  174. bets[key].items.bet = bets[key].items.bet.concat(parsedStorage.items.bet);
  175. bets[key].items.won = bets[key].items.won.concat(parsedStorage.items.won);
  176. bets[key].items.lost = bets[key].items.lost.concat(parsedStorage.items.lost);
  177. }
  178. }
  179. }
  180. }
  181. }
  182.  
  183. for(var bet in bets) {
  184. var dabet = bets[bet];
  185.  
  186. var itemarray = dabet.items.bet.concat(dabet.items.won).concat(dabet.items.lost);
  187.  
  188. for(var i in itemarray) {
  189. var itemname = itemarray[i];
  190. var date = dabet.date;
  191. //var localKeyName = getItemKeyName(itemname, date);
  192. var x = Date.parse(date.replace(/-/g,' ') + ' +0');
  193.  
  194. //since between 28.11.2014 and 30.11.2014 the market crashed and the price skyrocketed, i need to fix gabens shit.
  195. if(x>1417132800000&&x<1417395600000){
  196. date="2014-11-28 00:00:00";
  197. }
  198.  
  199. if(cleanparse || !getItemPrice(itemname, date)) { /*|| (!(localKeyName in cacheWeapons)*/
  200. //Price of an item is needed thats not cached yet, add it to cache que
  201. if(setting_debug == '1') console.log('Added ' + itemname + ' To cache que...');
  202. if(!cacheWeapons[itemname]) cacheWeapons[itemname] = [];
  203. if((setting_method !== '0' && cacheWeapons[itemname].indexOf(date) == -1) || cacheWeapons[itemname].length === 0) cacheWeapons[itemname].push(date);
  204. //cacheWeapons[localKeyName] = [itemname, date];
  205. }
  206. }
  207. }
  208.  
  209. if(setting_debug == '1'){console.log('weapos to cache:'); console.log(cacheWeapons);}
  210.  
  211. //iterate trough all the queud items that the price is needed of, get & cache it.
  212. var cancel = false;
  213. var cwlen = Object.size(cacheWeapons);
  214.  
  215. if(cwlen > 0) {
  216. $('#loungestats_datacontainer').html('<progress id="loungestats_loadprogress" value="0" max="' + cwlen + '"></progress><br/>Loading uncached item prices<label id="loungestats_loadprogresslabel">(0/' + cwlen + ')</label>...');
  217. var aboutTime = [0,0,0,0,0,0,0,0,0,0];
  218. var startTick = new Date().getTime();
  219.  
  220. getAllPrices(cacheWeapons, Object.keys(cacheWeapons), setting_method == '1' ? 380 : 560, 0, function(success) {
  221. if(success) {
  222. $('#loungestats_datacontainer').html('Generating stats... (If you can see this either you are using a calculator or, more likely, something went horribly wrong)');
  223. callback(true);
  224. } else {
  225. $('#loungestats_datacontainer').html('Could not connect to steam communitymarket API, try again later...');
  226. if(setting_method == '1') $('#loungestats_datacontainer').append('<br>If you keep getting this error try switching the parsing method to "Most exact <b>& safest</b>"');
  227. loading = false;
  228. }
  229. }, function(prog) {
  230. var endTick = new Date().getTime();
  231. aboutTime.shift();
  232. aboutTime.push(endTick-startTick);
  233. startTick = endTick;
  234. var eta = 0;
  235. for(var i = 0; i < 10; i++) eta += aboutTime[i];
  236. eta *= cwlen - prog;
  237. eta /= 600000;
  238. eta = parseInt(eta);
  239.  
  240. if(eta >= 30){
  241. eta += ' Minute(s), Better grab some coffee..';
  242. }else{
  243. eta += ' Minute(s)';
  244. }
  245.  
  246. $('#loungestats_loadprogress').val(prog);
  247. $('#loungestats_loadprogresslabel').html('(' + prog + '/' + cwlen + ')<br/>ETA: ~'+eta);
  248. }, setting_method !== '0');
  249. }
  250. else {
  251. $('#loungestats_datacontainer').html('Generating stats... (If you can see this either you are using a calculator or, more likely, something went horribly wrong)');
  252. callback(true);
  253. }
  254. }
  255.  
  256. function plot_zomx(plot, minx, maxx) {
  257. if(!minx){
  258. plot.replot({ axes: {
  259. xaxis: {
  260. min: plot.axes.xaxis.min,
  261. max: plot.axes.xaxis.max
  262. },
  263. yaxis: {
  264. min: plot.axes.yaxis.min,
  265. max: plot.axes.yaxis.max
  266. },
  267. }});
  268. }else{
  269. plot.replot({ axes: {
  270. xaxis: {
  271. min: minx,
  272. max: maxx
  273. },
  274. yaxis: {
  275. min: null,
  276. max: null
  277. }
  278. }});
  279. }
  280. /*$('#loungestats_stats_text').html('<div id="loungestats_stats_text"><hr>Overall value of items won: ' + overallWon.toFixed(2) + ' ' + currencysymbol);
  281. $('#loungestats_stats_text').append('<br>Overall value of items lost: ' + overallLost.toFixed(2) + ' ' + currencysymbol);
  282. $('#loungestats_stats_text').append('<br>Overall won bets: ' + overallWonCount + '/' + parseInt(overallWonCount + overallLostCount) + ' (' + parseInt(100/parseInt(overallWonCount + overallLostCount)*parseInt(overallWonCount)) + '%)');
  283. $('#loungestats_stats_text').append('<br>Net value: ' + overallValue.toFixed(2) + ' ' + currencysymbol);
  284. $('#loungestats_stats_text').append('<br>Highest win: ' + biggestwin.toFixed(2) + ' ' + currencysymbol + '<a href="/match?m=' + biggestwinid + '"> (Match link)</a>');
  285. $('#loungestats_stats_text').append('<br>Highest loss: ' + biggestloss.toFixed(2) + ' ' + currencysymbol + '<a href="/match?m=' + biggestlossid + '"> (Match link)</a>');
  286. $('#loungestats_stats_text').append('<br>Longest losing streak: ' + losestreaklast + '<a id="loungestats_zoonon_lls" href="javascript:void(0)"> (Show on plot)</a>');
  287. $('#loungestats_stats_text').append('<br>Longest winning streak: ' + winstreaklast + '<a id="loungestats_zoonon_lws" href="javascript:void(0)"> (Show on plot)</a></div>');*/
  288. }
  289.  
  290. function forceExcelDecimal(f, comma) {
  291. f = parseFloat(f).toFixed(2);
  292. if(comma) f = f.replace('.',',');
  293. return f;
  294. }
  295.  
  296. function generateStatsPage() {
  297. var overallValue = 0.0;
  298. var overallWon = 0.0;
  299. var overallLost = 0.0;
  300. var overallWonCount = 0;
  301. var overallLostCount = 0;
  302. var biggestwin = 0.0;
  303. var biggestwinid = 0;
  304. var biggestloss = 0.0;
  305. var biggestlossid = 0;
  306. var winstreakstart = 0; var winstreaktemp = 0; var winstreaklast = 0;
  307. var losestreakstart = 0; var losestreaktemp = 0; var losestreaklast = 0;
  308. var last = null;
  309.  
  310. var chartData = [];
  311. var betData = [];
  312.  
  313. //iterate trough bets array
  314. var absoluteIndex = 0;
  315. var betsKeys = Object.keys(bets).sort();
  316.  
  317. if(betsKeys.length === 0){
  318. $('#loungestats_datacontainer').html('Looks like you dont have any bets with the set criteria');
  319. return;
  320. }
  321.  
  322. var firstDate = bets[betsKeys[0]].intdate;
  323. var lastDate = bets[betsKeys[betsKeys.length-1]].intdate;
  324.  
  325.  
  326. for(var i in betsKeys) {
  327. var b = bets[betsKeys[i]];
  328. var betid = b.matchid;
  329. var betdate = b.date;
  330. //And, since i cached the "correct" value above for the market crash, i need to use it here too ofc.
  331. var x = Date.parse(betdate.replace(/-/g,' ') + ' +0');
  332.  
  333. //since between 28.11.2014 and 30.11.2014 the market crashed and the price skyrocketed, i need to fix gabens shit.
  334. if(x>1417132800000&&x<1417395600000){
  335. betdate="2014-11-28 00:00:00";
  336. }
  337.  
  338. var value = 0.0;
  339. var betValue = 0.0;
  340. var teamString = '';
  341. var mergeMatchWin = false;
  342. var wonOrlost = (b.matchoutcome == 'won' || b.matchoutcome == 'lost');
  343.  
  344. if(wonOrlost) {
  345. teamString = '<b>'+b.teams[b.winner]+'</b> vs. '+b.teams[!b.winner+0];
  346. if(teamString == '<b></b> vs. ') teamString = 'Prediction';
  347. } else {
  348. teamString = b.teams.join(' vs. ');
  349. }
  350. var itemname, item, price;
  351.  
  352. for(item in b.items.bet) {
  353. itemname = b.items.bet[item];
  354. betValue += getItemPrice(itemname, betdate);
  355. }
  356.  
  357. if(setting_debug == '1') console.log('################################# ' + teamString + '(' + betid + ')');
  358. if(setting_debug == '1') console.log('>>>Winnings');
  359. if(setting_debug == '1') console.log(b.items.won);
  360. for(item in b.items.won) {
  361. itemname = b.items.won[item];
  362. price = getItemPrice(itemname, betdate);
  363. if(setting_debug == '1') console.log(itemname + ': ' + price + ' (' + betdate + ')');
  364. if(setting_debug == '1') console.log('Keyname: ' + getItemKeyName(itemname, betdate));
  365. value += price;
  366. overallWon += price;
  367. }
  368.  
  369. if(setting_debug == '1') console.log('>>>Losses');
  370. if(setting_debug == '1') console.log(b.items.lost);
  371.  
  372. for(item in b.items.lost) {
  373. itemname = b.items.lost[item];
  374. price = getItemPrice(itemname, betdate);
  375. if(setting_debug == '1') console.log(itemname + ': ' + price + ' (' + betdate + ')');
  376. if(setting_debug == '1') console.log('Keyname: ' + getItemKeyName(itemname, betdate));
  377.  
  378. value -= price;
  379. overallLost += price;
  380. }
  381. if(setting_debug == '1') console.log('net change:' + value);
  382. overallValue += value;
  383.  
  384. mergeMatchWin = (value >= 0);
  385. var truevalue = value.toFixed(2);
  386.  
  387. if(last != mergeMatchWin && wonOrlost) {
  388. winstreaktemp = 0;
  389. losestreaktemp = 0;
  390. last = mergeMatchWin;
  391. }
  392.  
  393. if(mergeMatchWin && wonOrlost) {
  394. //win
  395. if(value > biggestwin) {
  396. biggestwin = value;
  397. biggestwinid = betid;
  398. }
  399. winstreaktemp++;
  400. overallWonCount++;
  401. if(winstreaktemp > winstreaklast) {
  402. winstreakstart = i - (winstreaktemp-1);
  403. winstreaklast = winstreaktemp;
  404. }
  405. value = '+'+value.toFixed(2);
  406. }else if(wonOrlost) {
  407. //loss
  408. if((value * -1) > biggestloss) {
  409. biggestloss = value * -1;
  410. biggestlossid = betid;
  411. }
  412.  
  413. losestreaktemp++;
  414. overallLostCount++;
  415. if(losestreaktemp > losestreaklast) {
  416. losestreakstart = i - (losestreaktemp-1);
  417. losestreaklast = losestreaktemp;
  418. }
  419. value = value.toFixed(2).toString();
  420. }
  421.  
  422. if(setting_debug == '1') console.log('node(' + b.date + ')->' + overallValue);
  423.  
  424. chartData.push([setting_xaxis == '0' ? b.date : absoluteIndex, parseFloat(overallValue.toFixed(2)), betValue, value, teamString, truevalue]);
  425. if(setting_bvalue == 1) betData.push([setting_xaxis == '0' ? b.date : absoluteIndex, betValue, teamString]);
  426. absoluteIndex++;
  427. }
  428.  
  429. //generate DOM content
  430. $('#loungestats_datacontainer').empty();
  431. $('#loungestats_datacontainer').append('<a id="loungestats_fullscreenbutton" class="button">Toggle Fullscreen</a><div id="loungestats_profitgraph" class="jqplot-target"></div>');
  432.  
  433. var boundary = parseInt(absoluteIndex * 0.05); if(boundary === 0) boundary = 1;
  434.  
  435. var xaxis_def = setting_xaxis == '0' ? {renderer:$.jqplot.DateAxisRenderer,tickOptions: {formatString: '%d %b %y'}, min: firstDate*0.9999,maxx: lastDate*1.0001} : {renderer: $.jqplot.LinearAxisRenderer, tickOptions: {formatString: '%i'}};
  436.  
  437. var plot = $.jqplot('loungestats_profitgraph', [chartData, betData], {
  438. title:{text: 'Overall profit over time'},
  439. gridPadding:{left: 55, right: 35, top: 25, bottom: 25},
  440. axesDefaults:{ showTickMarks:false },
  441. axes:{
  442. xaxis: xaxis_def,
  443. yaxis: {
  444. pad: 1,
  445. tickOptions:{formatString: '%0.2f ' + currencysymbol, labelPosition: 'end', tooltipLocation: 'sw'}
  446. }
  447. },
  448. canvasOverlay: {show: true},
  449. grid: {gridLineColor: '#414141', borderColor: '#414141', background: '#373737'},
  450. cursor: {show: true, zoom: true, showTooltip: false},
  451. highlighter: {show: true, tooltipOffset: 20, fadeTooltip: true, yvalues: 4},
  452. series:[{lineWidth:2, markerOptions:{show: false, style:'circle'}, highlighter: {formatString: '<strong>%s</strong><br>Overall Profit: %s<br>Value bet: %s<br>Value change: %s ' + currencysymbol + '<br>Game: %s'}},
  453. {lineWidth:1, markerOptions:{show: false, style:'circle'}, highlighter: {formatString: '<strong>%s</strong><br>Value bet: %s<br>Game: %s'/*, tooltipLocation: 'sw'*/}}],
  454. seriesColors: [ '#FF8A00', '#008A00' ]
  455. });
  456.  
  457. $('#loungestats_profitgraph').bind('jqplotDataClick',
  458. function (ev, seriesIndex, pointIndex, data) {
  459. window.open('/match?m='+bets[betsKeys[pointIndex]].matchid,'_blank');
  460. }
  461. );
  462.  
  463. $('#loungestats_profitgraph').bind('jqplotDataMouseOver', function () {
  464. $('.jqplot-event-canvas').css( 'cursor', 'pointer' );
  465. });
  466.  
  467. $('#loungestats_profitgraph').on('jqplotDataUnhighlight', function() {
  468. $('.jqplot-event-canvas').css('cursor', 'crosshair');
  469. });
  470.  
  471. if(setting_xaxis == '0') {
  472. $('#loungestats_profitgraph').dblclick(function() {plot_zomx(plot, firstDate*0.9999, lastDate*1.0001); clearSelection();});
  473. $('#loungestats_resetzoombutton').click(function() {plot_zomx(plot, firstDate*0.9999, lastDate*1.0001);});
  474. }else{
  475. //with the linearaxisrenderer, i cant pre-set minx, and maxx, lol.
  476. plot_zomx(plot, -boundary, absoluteIndex+boundary);
  477. $('#loungestats_profitgraph').dblclick(function() {plot_zomx(plot, -boundary, absoluteIndex+boundary); clearSelection();});
  478. $('#loungestats_resetzoombutton').click(function() {plot_zomx(plot, -boundary, absoluteIndex+boundary);});
  479. }
  480.  
  481. $('#loungestats_fullscreenbutton').click(function() {toggleFullscreen(plot);plot_zomx(plot);});
  482. $('.hideuntilready').removeClass("hideuntilready");
  483.  
  484. $(window).on('resize', function() {plot.replot();});
  485.  
  486. $('#loungestats_datacontainer').append('<div id="loungestats_stats_text"></div>');
  487.  
  488. $('#loungestats_stats_text').append('<hr>Overall value of items won: ' + overallWon.toFixed(2) + ' ' + currencysymbol);
  489. $('#loungestats_stats_text').append('<br>Overall value of items lost: ' + overallLost.toFixed(2) + ' ' + currencysymbol);
  490. $('#loungestats_stats_text').append('<br>Overall won bets: ' + overallWonCount + '/' + parseInt(overallWonCount + overallLostCount) + ' (' + parseInt(100/parseInt(overallWonCount + overallLostCount)*parseInt(overallWonCount)) + '%) <a class="info">?<p class="infobox">Draws are not counted into this, only losses & wins are counted in this stat</p></a>');
  491. $('#loungestats_stats_text').append('<br>Net value: ' + overallValue.toFixed(2) + ' ' + currencysymbol);
  492. $('#loungestats_stats_text').append('<br>Highest win: ' + biggestwin.toFixed(2) + ' ' + currencysymbol + '<a href="/match?m=' + biggestwinid + '"> (Match link)</a>');
  493. $('#loungestats_stats_text').append('<br>Highest loss: ' + biggestloss.toFixed(2) + ' ' + currencysymbol + '<a href="/match?m=' + biggestlossid + '"> (Match link)</a>');
  494. $('#loungestats_stats_text').append('<br>Longest losing streak: ' + losestreaklast + '<a id="loungestats_zoonon_lls" href="javascript:void(0)"> (Show on plot)</a>');
  495. $('#loungestats_stats_text').append('<br>Longest winning streak: ' + winstreaklast + '<a id="loungestats_zoonon_lws" href="javascript:void(0)"> (Show on plot)</a>');
  496.  
  497. $('#loungestats_zoonon_lws').click(function() {
  498. plot_zomx(plot,chartData[winstreakstart][0],chartData[winstreakstart+winstreaklast][0]);
  499. }).removeAttr('id');
  500. $('#loungestats_zoonon_lls').click(function() {
  501. plot_zomx(plot,chartData[losestreakstart][0],chartData[losestreakstart+losestreaklast][0]);
  502. }).removeAttr('id');
  503.  
  504. $('#loungestats_csvexport').click(function(){
  505. var useaccs = (!setting_domerge || setting_domerge == '0') ? [user_steam64] : accounts.active;
  506. var d = new Date();
  507.  
  508. var csvContent = 'data:application/csv; charset=charset=iso-8859-1, Users represented in Export(SteamID64):;="' + useaccs.join(', ') + '"\n \
  509. Time of Export:;' + d.getUTCDate() + '-' + d.getUTCMonth() + '-' + d.getUTCFullYear() + ' ' + d.getUTCHours() + ':' + d.getUTCMinutes() + '\n \
  510. Currency:;'+currencyText+'\n \
  511. Bet Data:\n \
  512. Game;Date;Match ID;Bet Outcome;Bet Value;Value Change;Overall Profit;Bet Items;Won Items;Lost Items\n';
  513.  
  514. for(var i in betsKeys) {
  515. var b = bets[betsKeys[i]];
  516. var c = chartData[i];
  517. var betdate = b.date;
  518.  
  519. csvContent += c[4].replace('<b>','[').replace('</b>',']') +';'+ b.date +';'+ b.matchid +';'+ b.matchoutcome +';'+ forceExcelDecimal(c[2],true) +';'+ forceExcelDecimal(c[5],true) +';'+ forceExcelDecimal(c[1],true) +';'+ b.items.bet.join(', ') +';'+ b.items.won.join(', ') +';'+ b.items.lost.join(', ') +'\n';
  520. }
  521.  
  522. var encodedUri = encodeURI(csvContent);
  523. var link = document.createElement("a");
  524. link.setAttribute("href", encodedUri);
  525. link.setAttribute("download", "LoungeStats_Export.csv");
  526. link.click();
  527. }).removeAttr('id');
  528.  
  529. $('#loungestats_screenshotbutton').click(function(){
  530. if($('#loungestats_screenshotbutton').text() != "Screenshot") return;
  531. alert("The Screenshot will be taken in 4 Seconds so that you can Hover a bet if you want to...\n\n You can also quickly put the graph in Fullscreen mode!");
  532. $('#loungestats_screenshotbutton').text("Waiting");
  533. setTimeout(function(){$('#loungestats_screenshotbutton').text("Waiting.")},1000);
  534. setTimeout(function(){$('#loungestats_screenshotbutton').text("Waiting..")},2000);
  535. setTimeout(function(){$('#loungestats_screenshotbutton').text("Waiting...")},3000);
  536. setTimeout(function(){
  537. $('#loungestats_screenshotbutton').text("Uploading...");
  538. //$('#loungestats_profitgraph').attr("style", "width: 900px; height: 450px;");
  539. //plot.replot();
  540. var canvas = $("#loungestats_profitgraph").find('.jqplot-grid-canvas, .jqplot-series-shadowCanvas, .jqplot-series-canvas, .jqplot-highlight-canvas');
  541. var w = canvas[0].width;
  542. var h = canvas[0].height;
  543. var newCanvas = $('<canvas/>').attr('width',w).attr('height',h)[0];
  544. var context = newCanvas.getContext("2d");
  545. context.fillStyle = "#FFF";
  546. context.fillRect(0, 0, w, h);
  547. context.fillStyle = "#000";
  548. $(canvas).each(function() {
  549. context.drawImage(this, this.style.left.replace("px",""), this.style.top.replace("px",""));
  550. });
  551.  
  552. context.font="11px Arial";
  553. var yaxis = $("#loungestats_profitgraph .jqplot-yaxis");
  554. $(yaxis.children()).each(function() {
  555. context.fillText(this.textContent, 3, parseInt(this.style.top)+10);
  556. });
  557. var xaxis = $("#loungestats_profitgraph .jqplot-xaxis");
  558. $(xaxis.children()).each(function() {
  559. context.fillText(this.textContent, parseInt(this.style.left)+1, h-12);
  560. });
  561. var ttip = $("#loungestats_profitgraph .jqplot-highlighter-tooltip")[0];
  562. if(ttip.style.display != "none"){
  563. var topoffset = parseInt(ttip.style.top);
  564. if(topoffset < 20) topoffset = 20;
  565. context.font="16px Arial";
  566. context.fillStyle = "rgba(57,57,57,.8)";
  567. context.strokeStyle = "#808080";
  568. context.fillRect(parseInt(ttip.style.left), topoffset, ttip.clientWidth, ttip.clientHeight);
  569. context.lineWidth="1";
  570. context.rect(parseInt(ttip.style.left), topoffset, ttip.clientWidth, ttip.clientHeight);
  571. context.stroke();
  572. context.fillStyle = "rgba(220,220,220,.8)";
  573. var strs = ttip.innerHTML.replace(/<br>/g,"|").replace(/<.+?>/g,"").split("|");
  574. for(var i = 0; i < strs.length; i++) context.fillText(strs[i], parseInt(ttip.style.left)+5, topoffset+18+(i*16))
  575. }
  576. context.font="14px Arial";
  577. context.fillStyle = "#000";
  578. //$('#loungestats_profitgraph').removeAttr("style");
  579. //plot.replot();
  580. context.textAlign = 'center';
  581. context.font="bold 15px Arial";
  582. context.fillText("LoungeStats Profit Graph ("+(app_id == '730' ? "CS:GO" : "DotA")+") | http://reddit.com/r/LoungeStats", w/2, 17);
  583.  
  584. $.ajax({
  585. url: 'https://api.imgur.com/3/image',
  586. type: 'post',
  587. headers: {
  588. Authorization: 'Client-ID 449ec55696fd751'
  589. },
  590. data: {
  591. image: newCanvas.toDataURL("image/jpeg", 0.92).replace("data:image/jpeg;base64,",""),
  592. title: "LoungeStats Profit Graph Autoupload",
  593. description: "Visit http://reddit.com/r/LoungeStats for more infos!"
  594. },
  595. dataType: 'json',
  596. success: function(response) {
  597. if(response.success) {
  598. var myPopup = window.open(response.data.link, "", "directories=no,height="+h+",width="+w+",menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,top=0,location=no");
  599. if (!myPopup)
  600. alert("Your Screenshot was uploaded, but looks like your browser blocked the PopUp!");
  601. else {
  602. $('#loungestats_screenshotbutton').text("Screenshot");
  603. myPopup.onload = function() {
  604. setTimeout(function() {
  605. if (myPopup.screenX === 0) alert("Your Screenshot was uploaded, but looks like your browser blocked the PopUp!");
  606. }, 0);
  607. };
  608. }
  609. }
  610. },
  611. error: function(){
  612. $('#loungestats_screenshotbutton').text("Screenshot");
  613. alert("Sorry, uploading the image to imgur failed :(\n\nTry it again in a second and doublecheck that imgur is up!");
  614. }
  615. });
  616. },4000)
  617. })
  618. }
  619.  
  620. var activefast = 0;
  621. var fastindex = 0;
  622. var fastLooping = false;
  623.  
  624. function getAllPrices(itemarray, itemarraykeylist, delay, arrayoffset, callback, progresscallback, exact) {
  625. if(!arrayoffset) arrayoffset = 0;
  626. var item = itemarraykeylist[arrayoffset];
  627. var itemDates = itemarray[itemarraykeylist[arrayoffset]];
  628.  
  629. if(!item) {
  630. if(activefast === 0) callback(true);
  631. return true;
  632. }
  633. if(exact) {
  634. //var betdate = new Date(Date.parse(loungetime.replace(/-/g,' ') + ' +0'));
  635. cacheItemsExact(item, itemDates, function(success) {
  636. if(success) {
  637. progresscallback(arrayoffset+1);
  638. //Recursively re-call myself with a delay until all prices are parsed, this is because the amount of requests to the market possible is limited
  639. setTimeout(function() {getAllPrices(itemarray, itemarraykeylist, delay, arrayoffset+1, callback, progresscallback, exact);}, delay);
  640. }
  641. else {
  642. $('#loungestats_datacontainer').html('Could not connect to steam communitymarket API, try again later...');
  643. if(setting_method == '1') $('#loungestats_datacontainer').append('<br>If you keep getting this error try switching the parsing method to "Most exact <b>& safest</b>"');
  644. callback(false);
  645. }
  646. });
  647. } else {
  648. if(arrayoffset === 0) fastindex = 0;
  649. fastLooping = true;
  650. while(activefast < 10 && fastindex < itemarraykeylist.length) {
  651. item = itemarraykeylist[fastindex];
  652. activefast++; fastindex++;
  653. cacheItem(item, function(success) {
  654. if(success) {
  655. activefast--;
  656. progresscallback(fastindex-activefast);//this actually is right, wat.
  657. if(!fastLooping) getAllPrices(itemarray, itemarraykeylist, delay, fastindex, callback, progresscallback, exact);
  658. if(setting_debug == '1') console.log(fastindex-activefast);
  659. } else {
  660. fastindex = itemarraykeylist.length +1;
  661. $('#loungestats_datacontainer').html('Could not connect to steam communitymarket API, try again later...');
  662. if(setting_method == '1') $('#loungestats_datacontainer').append('<br>If you keep getting this error try switching the parsing method to "Most exact <b>& safest</b>"');
  663. callback(false);
  664. }
  665. }, itemarray[item]);
  666. }
  667. fastLooping = false;
  668. }
  669. }
  670.  
  671. function cacheItem(itemname, callback, exactfallback) {
  672. if(setting_debug == '1') console.log('Caching item price of ' + itemname + '...>>>>>>>>>>>>>>>>>>>>>>>>>>>');
  673. if(setting_debug == '1') console.log(getItemKeyName(itemname, ""));
  674.  
  675. GM_xmlhttpRequest({
  676. method: 'GET',
  677. url: 'http://steamcommunity.com/market/priceoverview/?currency=' + localStorage['LoungeStats_setting_currency'] + '&appid=' + app_id + '&market_hash_name=' + encodeURI(itemname),
  678. onload: function(response) {
  679. if(response.status == 200) {
  680. var responseParsed = JSON.parse(response.responseText);
  681. if(responseParsed.success === true && 'median_price' in responseParsed) {
  682. var price = parseFloat(responseParsed['median_price'].replace('&#36;','').replace('&#163;','').replace('&#8364;','').replace('p&#1091;&#1073;.','').replace('&#82;','').replace(',', '.').trim());
  683. if(setting_debug == '1') console.log('Cached item price of ' + itemname + ' | Price: ' + price);
  684. if(setting_debug == '1') console.log(exactfallback);
  685. for(loungetime in exactfallback){
  686. var localKeyName = getItemKeyName(itemname, exactfallback[loungetime]);
  687. localStorage.setItem(localKeyName, price);
  688. }
  689. if(setting_debug == '1') console.log('');
  690. callback(true);
  691. return;
  692. }// No median price seems existant, attempt to use the lowest price
  693. else if(responseParsed.success == true && 'lowest_price' in responseParsed) {
  694. var price = parseFloat(responseParsed['lowest_price'].replace('&#36;','').replace('&#163;','').replace('&#8364;','').replace('p&#1091;&#1073;.','').replace('&#82;','').replace(',', '.').trim());
  695. if(responseParsed['lowest_price'].indexOf('&#82;&#36;') > -1) {
  696. price *= curr_usd_brd;
  697. }else if(responseParsed['lowest_price'].indexOf('&#163;') > -1) {
  698. price *= curr_usd_gbp;
  699. }else if(responseParsed['lowest_price'].indexOf('&#8364;') > -1) {
  700. price *= curr_usd_eur;
  701. }else if(responseParsed['lowest_price'].indexOf('p&#1091;&#1073;') > -1) {
  702. price *= curr_usd_rub;
  703. }else if(responseParsed['lowest_price'].indexOf('&#36;') > -1) {
  704. //hi
  705. }
  706. if(setting_debug == '1') console.log('Cached item price of ' + itemname + ' | Price: ' + price);
  707.  
  708. for(loungetime in exactfallback){
  709. var localKeyName = getItemKeyName(itemname, exactfallback[loungetime]);
  710. localStorage.setItem(localKeyName, price);
  711. }
  712. console.log('');console.log('');
  713. callback(true);
  714. return;
  715. }// No lowest price seems existant, assume price as 0 since i cant do anything else really
  716. else if(setting_debug == '1') {
  717. console.log('Failed to load ' + itemname + ', assuming as 0');
  718. }
  719. }
  720. if(setting_debug == '1') console.log("X.X");
  721. for(loungetime in exactfallback){
  722. var localKeyName = getItemKeyName(itemname, exactfallback[loungetime]);
  723. localStorage.setItem(localKeyName, 0.0);
  724. }
  725. callback(true);
  726. }
  727. });
  728. }
  729.  
  730. //Converting usd to other currencies using static conversion rates (Thanks GabeN)
  731. function convertUsd(usd) {
  732. if(usd < 0.02) usd = 0.02;
  733. if(setting_currency == '3') {
  734. return usd / curr_usd_eur;
  735. }
  736. else if(setting_currency == '2') {
  737. return usd / curr_usd_gbp;
  738. }
  739. else if(setting_currency == '5') {
  740. return usd / curr_usd_rub;
  741. }
  742. else if(setting_currency == '7') {
  743. return usd / curr_usd_brd;
  744. }
  745. return usd;
  746. }
  747.  
  748. function cacheItemsExact(itemname, loungetimes, callback) {
  749. if(setting_debug == '1') console.log('Caching exact item prices of ' + itemname + '...');
  750. GM_xmlhttpRequest({
  751. method: 'GET',
  752. //tricky stuff, since i cant get the price history when im not logged in, im downloading the items market page. Even if there are not items on sale at that very moment
  753. //in the javascript there still is an array with the past price history
  754. url: 'http://steamcommunity.com/market/listings/' + app_id + '/' + encodeURI(itemname) + '?l=english',
  755. onload: function(response) {
  756. if(response.status == 200) {
  757. //which i do filter out with this regex pattern
  758. var rgx = /var line1=\[\[(.*)\]\]/.exec(response.responseText);
  759. var curr = /var strFormatPrefix[^]*?var strFormatSuffix[^]*?;/.exec(response.responseText);
  760. var inexact = false;
  761.  
  762. if(rgx) {
  763. var arr = JSON.parse('[[' + rgx[1] + ']]');
  764.  
  765.  
  766. if(arr !== null) {
  767. for(var loungetimei in loungetimes){
  768. var localKeyName = getItemKeyName(itemname, loungetimes[loungetimei]);
  769. var betdate = new Date(Date.parse(loungetimes[loungetimei].replace(/-/g,' ') + ' +0'));
  770.  
  771. var prev = null;
  772. //and iterate trough it here if it was found
  773. var p = 0.0;
  774. var datadate = null;
  775. for(var i in arr) {
  776. datadate = new Date(Date.parse(arr[i][0]));
  777. p = parseFloat(arr[i][1]);
  778.  
  779. if(curr[0].indexOf('&#82;&#36;') > -1) {
  780. p *= curr_usd_brd;
  781. }else if(curr[0].indexOf('&#163;') > -1) {
  782. p *= curr_usd_gbp;
  783. }else if(curr[0].indexOf('&#8364;') > -1) {
  784. p *= curr_usd_eur;
  785. }else if(curr[0].indexOf('p&#1091;&#1073;') > -1) {
  786. p *= curr_usd_rub;
  787. }else if(curr[0].indexOf('&#36;') > -1) {
  788. //hi
  789. } else { inexact = true; }
  790.  
  791. if(datadate >= betdate && (prev === null || prev < betdate)) {
  792. if(inexact && !inexactAlert) {
  793. inexactAlert = true;
  794. alert('For your Information. Since you are using the exact method you want exact prices. Because of this, i am alerting you that i cant provide exact prices for you sadly, the reason being that i dont know how to deal with your local currency. The best you can do is to select US$ as your currency, this will display values in your local currency. The alternative is to use the fast method because i can tell steam which currency i want the prices in for that, which i cant for the price history sadly. I\'m sorry for that');
  795. }
  796. if(setting_debug == '1') console.log('Parsed: ' + datadate + ' Requested: ' + loungetimes[loungetimei]);
  797. localStorage[localKeyName] = p;
  798. }
  799. prev = datadate;
  800. }
  801. if(!localStorage[localKeyName]){
  802. if(setting_debug == '1') console.log('Parsed: ' + datadate + ' Requested: ' + loungetimes[loungetimei]);
  803. localStorage[localKeyName] = p;
  804. }
  805. }
  806. callback(true);
  807. return;
  808. }
  809. }
  810. }
  811. //otherwise attempt to use the inexact price instead of the exact price since i cant do anything else really
  812. if((response.responseText.indexOf('There is no price history available for this item yet.') > -1) || response.responseText.indexOf('There are no listings for this item.') > -1) {
  813. if(setting_debug == '1') console.log('Falling back to unexact price...');
  814. cacheItem(itemname, callback, loungetimes);
  815. return;
  816. }
  817. callback(false);
  818. }
  819. });
  820. }
  821. //Internal function for generating central localstorage key names
  822. function getItemKeyName(itemname, loungetime) {
  823. if(loungetime && setting_method !== '0') {
  824. var betdate = new Date(Date.parse(loungetime.replace(/-/g,' ') + ' +0'));
  825. return 'LoungeStats_itemexact_' + betdate.getUTCDate() + '_' + betdate.getUTCMonth() + '_' + betdate.getYear() + '_' + itemname.replace(/ /g, '_');
  826. } else {
  827. return 'LoungeStats_' + currencysymbol + 'item_' + itemname.replace(/ /g, '_');
  828. }
  829. }
  830.  
  831. function getItemPrice(itemname, loungetime) {
  832. var localKeyName = getItemKeyName(itemname, loungetime);
  833. if(localStorage[localKeyName]) {
  834. if(loungetime && setting_method !== '0') {
  835. return convertUsd(parseFloat(localStorage[localKeyName]));
  836. }
  837. return parseFloat(localStorage[localKeyName]);
  838. }
  839. return false;
  840. }
  841. //Main sub that handles most of the stuff
  842. function loadStats(clean) {
  843. if(loading) {
  844. alert('I\'m already loading, sheesh.');
  845. return;
  846. }
  847.  
  848. if(typeof(Storage) == void(0)) {
  849. $('#ajaxCont').html('Your browser does not seem to support localstorage, update it and try again.');
  850. return;
  851. }
  852. else if(!setting_method) {
  853. $('#ajaxCont').html('Please set up Loungestats first');
  854. $('#loungestats_overlay').fadeIn(500);
  855. return;
  856. }
  857.  
  858. $(window).off('resize');
  859. cleanparse = clean;
  860. $('#ajaxCont').html('<a id="loungestats_settingsbutton" class="button">LoungeStats Settings</a> \
  861. <a id="loungestats_reloadbutton" class="button hideuntilready">Refresh cache</a> \
  862. <a id="loungestats_resetzoombutton" class="button hideuntilready">Reset Zoom</a> \
  863. <a id="loungestats_screenshotbutton" class="button hideuntilready">Screenshot</a> \
  864. <a id="loungestats_csvexport" class="button hideuntilready">Export CSV (Excel)</a> \
  865. <a class="button" target="_blank" href="http://steamcommunity.com/tradeoffer/new/?partner=33309635&token=H0lCbkY3">Donate ♥</a> \
  866. <a class="button" target="_blank" href="http://reddit.com/r/LoungeStats">Subreddit</a> \
  867. <br><hr><br> \
  868. <div id="loungestats_datacontainer"> \
  869. <img src="../img/load.gif" id="loading" style="margin: 0.75em 2%"> \
  870. </div>');
  871. if(newVersion) {
  872. localStorage['LoungeStats_lastversion'] = version;
  873. $('#ajaxCont').prepend('<div id="loungestats_updateinfo" class="bpheader">LoungeStats was updated to ' + version + '!<br/>Please make sure to check <a href="http://reddit.com/r/loungestats">the subreddit</a> to see what changes were made!</div>');
  874. }
  875.  
  876. $('#loungestats_reloadbutton').click(function() {loadStats(true);});
  877.  
  878. $('#loungestats_settingsbutton').click(function() {
  879. $('#loungestats_overlay').fadeIn(500);
  880.  
  881. var multiaccthing;
  882.  
  883. if(app_id == 730) {
  884. multiaccthing = '<div>CS:GO Accounts</div>';
  885. } else {
  886. multiaccthing = '<div>DotA Accounts</div>';
  887. }
  888.  
  889. for(var i in accounts.aval) {
  890. if(accounts.active.indexOf(i) > -1) {
  891. multiaccthing += '<input type="checkbox" name="'+i+'" checked> "<a href="http://steamcommunity.com/profiles/'+i+'" target="_blank">'+accounts.aval[i]+'</a>"<br/>';
  892. } else {
  893. multiaccthing += '<input type="checkbox" name="'+i+'"> "<a href="http://steamcommunity.com/profiles/'+i+'" target="_blank">'+accounts.aval[i]+'</a>"<br/>';
  894. }
  895. }
  896. $('#loungestats_mergepicks').html(multiaccthing);
  897. }).removeAttr('id');
  898. loading = true;
  899. getLoungeBetHistory(function(data) {
  900. if(data !== null) {
  901. parseLoungeBetHistory(data, function(success) {
  902. if(success) {
  903. generateStatsPage();
  904. }
  905. loading = false;
  906. });
  907. } else {
  908. loading = false;
  909. $('#loungestats_datacontainer').html('Looks like Lounge is dead at the moment..');
  910. }
  911. });
  912. }
  913.  
  914. function toggleFullscreen(jqplot) {
  915. if($('#loungestats_profitgraph').hasClass('fullsc')) {
  916. $('#loungestats_profitgraph').removeClass('fullsc');
  917. $('#loungestats_fullscreenbutton').removeClass('fullsc');
  918. } else {
  919. $('#loungestats_profitgraph').addClass('fullsc');
  920. $('#loungestats_fullscreenbutton').addClass('fullsc');
  921. }
  922. jqplot.replot();
  923. }
  924.  
  925. //called when save is pressed in the settings
  926. function saveSettings() {
  927. localStorage['LoungeStats_setting_method'] = $('#loungestats_method').val(); setting_method = localStorage['LoungeStats_setting_method'];
  928. localStorage['LoungeStats_setting_currency'] = $('#loungestats_currency').val(); setting_currency = localStorage['LoungeStats_setting_currency'];
  929. localStorage['LoungeStats_setting_bvalue'] = $('#loungestats_bgraph').val(); setting_bvalue = localStorage['LoungeStats_setting_bvalue'];
  930. localStorage['LoungeStats_setting_xaxis'] = $('#loungestats_xaxis').val(); setting_xaxis = localStorage['LoungeStats_setting_xaxis'];
  931. localStorage['LoungeStats_setting_debug'] = $('#loungestats_debug').val(); setting_debug = localStorage['LoungeStats_setting_debug'];
  932. localStorage['LoungeStats_setting_domerge'] = $('#loungestats_domerge').val(); setting_domerge = localStorage['LoungeStats_setting_domerge'];
  933.  
  934. if(isValidDate($('#loungestats_beforedate').val())){
  935. localStorage['LoungeStats_setting_beforedate'] = $('#loungestats_beforedate').val(); setting_beforedate = localStorage['LoungeStats_setting_beforedate'];
  936. } else {
  937. alert('The format of the given date is invalid! Use Day.Month.Year!');
  938. return;
  939. }
  940.  
  941. accounts.active = [];
  942. $('#loungestats_mergepicks input').each(function(i,c) {
  943. if(c.checked) accounts.active.push(c.name);
  944. });
  945. localStorage['LoungeStats_accounts'] = JSON.stringify(accounts);
  946.  
  947. setCurrencySymbol();
  948. $('#loungestats_overlay').fadeOut(500);
  949. loadStats();
  950. }
  951.  
  952. //I know that gm scripts are called on the documentReady, i like having it like this nevertheless.
  953. function init() {
  954. $('section:nth-child(2) div:nth-child(1)').append('<a id="loungestats_tabbutton" class="button">LoungeStats</a>');
  955. GM_addStyle('.jqplot-highlighter-tooltip {background-color: #393938; border: 1px solid gray; padding: 5px; color: #ccc} \
  956. .jqplot-xaxis {margin-top: 5px; font-size: 12px} \
  957. .jqplot-yaxis {margin-right: 5px; width: 55px; font-size: 12px} \
  958. .jqplot-yaxis-tick {text-align: right; width: 100%} \
  959. #loungestats_overlay {z-index: 9000; display: none; top: 0px; left: 0px; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.4); position: fixed} \
  960. #loungestats_settings_title {text-align: center; font-size: 12px; height: 40px; border: 2px solid #DDD; border-top: none; background-color: #EEE; width: 100%; margin-top: -10px; -webkit-border-radius: 0 0 5px 5px; border-radius: 0 0 5px 5px; padding: 10px 5px 0 5px; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;} \
  961. #loungestats_settingswindow {font-size: 13px; z-index: 9001; padding: 10px; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; position: relative; background-color: white; left: 50%; top: 50%; width: 300px; margin-left: -151px; height: 420px; margin-top: -211px; -webkit-border-radius: 5px; border-radius: 5px; -webkit-box-shadow: 0 0 10px -5px #000; box-shadow: 0 0 10px -5px #000; border: 1px solid gray; overflow: hidden;-webkit-transition: all 250ms ease-in-out;-moz-transition: all 250ms ease-in-out;-ms-transition: all 250ms ease-in-out;-o-transition: all 250ms ease-in-out;transition: all 250ms ease-in-out;} \
  962. #loungestats_settingswindow.accounts {width: 500px; margin-left: -251px;} \
  963. #loungestats_settings_leftpanel select, #loungestats_settings_leftpanel input{margin: 5px 0; width: 100%; height: 22px !important; padding: 0;} \
  964. #loungestats_settings_leftpanel input{width: 274px;} \
  965. #loungestats_fullscreenbutton{margin-right: 29px !important; margin-top: -5px !important; height: 14px; z-index: 8998; position: relative;} \
  966. #loungestats_fullscreenbutton.fullsc{position: fixed;margin: 0 !important;right: 34px; top: -5px;} \
  967. #loungestats_profitgraph{position: relative; height: 400px; clear: left; z-index: 322;} \
  968. #loungestats_profitgraph.fullsc{background-color: #DDD;height: 100% !important;left: 0;margin: 0;position: fixed !important;top: 0;width: 100%;} \
  969. #loungestats_settings_leftpanel{width: 278px; float: left;} \
  970. #loungestats_settings_rightpanel{width: 188px; float: left; margin-left: 11px;} \
  971. #loungestats_settings_panelcontainer{width: 500px;} \
  972. #loungestats_datacontainer{position: relative;clear: both;} \
  973. .jqplot-highlighter-tooltip{z-index: 8999;} \
  974. #loungestats_updateinfo{text-align: center;} \
  975. #loungestats_mergepicks{border:2px solid #ccc; height: 100px; overflow-y: scroll; height: 258px; padding: 5px;-moz-box-sizing: border-box;-webkit-box-sizing: border-box;box-sizing: border-box;} \
  976. #loungestats_mergepicks div:first-child{font-weight: bold;} \
  977. #loungestats_mergepicks input{height: 20px !important;vertical-align: middle;} \
  978. #loungestats_datecontainer{position: relative;} \
  979. #loungestats_stats_text a{color: blue;} \
  980. .hideuntilready{display: none !important;}');
  981.  
  982. GM_addStyle('.calendar {top: 5px !important; left: 108px !important; font-family: \'Trebuchet MS\', Tahoma, Verdana, Arial, sans-serif !important;font-size: 0.9em !important;background-color: #EEE !important;color: #333 !important;border: 1px solid #DDD !important;-moz-border-radius: 4px !important;-webkit-border-radius: 4px !important;border-radius: 4px !important;padding: 0.2em !important;width: 14em !important;}.calendar .months {background-color: #F6AF3A !important;border: 1px solid #E78F08 !important;-moz-border-radius: 4px !important;-webkit-border-radius: 4px !important;border-radius: 4px !important;color: #FFF !important;padding: 0.2em !important;text-align: center !important;}.calendar .prev-month,.calendar .next-month {padding: 0 !important;}.calendar .prev-month {float: left !important;}.calendar .next-month {float: right !important;}.calendar .current-month {margin: 0 auto !important;}.calendar .months .prev-month,.calendar .months .next-month {color: #FFF !important;text-decoration: none !important;padding: 0 0.4em !important;-moz-border-radius: 4px !important;-webkit-border-radius: 4px !important;border-radius: 4px !important;cursor: pointer !important;}.calendar .months .prev-month:hover,.calendar .months .next-month:hover {background-color: #FDF5CE !important;color: #C77405 !important;}.calendar table {border-collapse: collapse !important;padding: 0 !important;font-size: 0.8em !important;width: 100% !important;}.calendar th {text-align: center !important; color: black !important;}.calendar td {text-align: right !important;padding: 1px !important;width: 14.3% !important;}.calendar tr{border: none !important; background: none !important;}.calendar td span {display: block !important;color: #1C94C4 !important;background-color: #F6F6F6 !important;border: 1px solid #CCC !important;text-decoration: none !important;padding: 0.2em !important;cursor: pointer !important;}.calendar td span:hover {color: #C77405 !important;background-color: #FDF5CE !important;border: 1px solid #FBCB09 !important;}.calendar td.today span {background-color: #FFF0A5 !important;border: 1px solid #FED22F !important;color: #363636 !important;}');
  983.  
  984. $('body').append('<div id="loungestats_overlay"> \
  985. <div id="loungestats_settingswindow"'+((setting_domerge == '1') ? ' class="accounts"' : '')+'> \
  986. <div id="loungestats_settings_title">Loungestats '+version+' Settings | by <a href="http://reddit.com/u/kinsi55">/u/kinsi55</a><br><br></div> \
  987. <div id="loungestats_settings_panelcontainer"> \
  988. <div id="loungestats_settings_leftpanel"> \
  989. Pricing accuracy <a class="info">?<p class="infobox"><br>Fastest: Use current item prices for all bets<br><br>Most accurate: Use item prices at approximately the time of the bet, as little delay as possible between requests<br><br>Most accurate & safest: Same as Most accurate, but with a bit more delay between requests</p></a>:<br> \
  990. <select id="loungestats_method"> \
  991. <option value="0">Fastest</option> \
  992. <option value="1">Most accurate</option> \
  993. <option value="2">Most accurate & safest</option> \
  994. </select><br> \
  995. Currency:<br> \
  996. <select id="loungestats_currency"> \
  997. <option value="1">US Dollar(Most exact)</option> \
  998. <option value="3">Euro</option> \
  999. <option value="2">Great British Pound</option> \
  1000. <option value="5">Rubel</option> \
  1001. <option value="7">Brazilian real</option> \
  1002. </select><br> \
  1003. Show bet value graph:<br> \
  1004. <select id="loungestats_bgraph"> \
  1005. <option value="1">Yes</option> \
  1006. <option value="0">No</option> \
  1007. </select><br> \
  1008. Merge Accounts:<br> \
  1009. <select id="loungestats_domerge"> \
  1010. <option value="0">No</option> \
  1011. <option value="1">Yes</option> \
  1012. </select><br> \
  1013. Exclude bets before <a class="info">?<p class="infobox"><br>Any bet that happened before the given date will be excluded. To disable this just pick any date before you started betting(e.g. set the year to 2000 or something)</p></a>:<br> \
  1014. <div id="loungestats_datecontainer"> \
  1015. <input id="loungestats_beforedate"><br> \
  1016. </div> \
  1017. X-Axis:<br> \
  1018. <select id="loungestats_xaxis"> \
  1019. <option value="0">Date</option> \
  1020. <option value="1">Incrementing</option> \
  1021. </select><br> \
  1022. Debug mode:<br> \
  1023. <select id="loungestats_debug"> \
  1024. <option value="0">Off</option> \
  1025. <option value="1">On</option> \
  1026. </select><br> \
  1027. </div> \
  1028. <div id="loungestats_settings_rightpanel"> \
  1029. Accounts to merge <a class="info">?<p class="infobox"><br>Since you chose to merge accounts, select all acounts you want to be merged in the graph(The current one is NOT automatically included!)</p></a>:<br> \
  1030. <div id="loungestats_mergepicks"></div> \
  1031. </div> \
  1032. </div> \
  1033. <div style="position: absolute; bottom: 10px;"> \
  1034. <a id="loungestats_settings_save" class="button">Save</a> \
  1035. <a id="loungestats_settings_close" class="button">Close</a> \
  1036. </div> \
  1037. </div> \
  1038. </div>');
  1039.  
  1040. $('#loungestats_domerge').change(function() {
  1041. if($('#loungestats_domerge').val() == 1) {
  1042. $('#loungestats_settingswindow').addClass('accounts');
  1043. } else {
  1044. $('#loungestats_settingswindow').removeClass('accounts');
  1045. }
  1046. });
  1047.  
  1048. if(setting_method) $('#loungestats_method').val(setting_method);
  1049. if(setting_currency) $('#loungestats_currency').val(setting_currency);
  1050. if(setting_bvalue) $('#loungestats_bgraph').val(setting_bvalue);
  1051. if(setting_xaxis) $('#loungestats_xaxis').val(setting_xaxis);
  1052. if(setting_debug) $('#loungestats_debug').val(setting_debug);
  1053. if(setting_domerge) $('#loungestats_domerge').val(setting_domerge);
  1054. if(setting_beforedate) {
  1055. $('#loungestats_beforedate').val(setting_beforedate);
  1056. } else {
  1057. $('#loungestats_beforedate').val('01.01.2000');
  1058. localStorage['LoungeStats_setting_beforedate'] = '01.01.2000';
  1059. setting_beforedate = '01.01.2000';
  1060. }
  1061.  
  1062. new datepickr('loungestats_beforedate', {
  1063. 'dateFormat': 'd.m.Y'
  1064. });
  1065.  
  1066. $('.calendar').detach().appendTo('#loungestats_datecontainer');
  1067.  
  1068. $('#loungestats_tabbutton').click(function() {loadStats(false);}).removeAttr('id');
  1069. $('#loungestats_overlay, #loungestats_settings_close').click(function() {$('#loungestats_overlay').fadeOut(500);});
  1070. $('#loungestats_settings_save').click(function() {saveSettings();});
  1071. $('#loungestats_settingswindow #loungestats_beforedate, .calendar').click(function(e) {e.stopPropagation();});
  1072. $('#loungestats_settingswindow').click(function(e) {e.stopPropagation();$('.calendar').css('display','none');});
  1073. }
  1074.  
  1075. setCurrencySymbol();
  1076. init();
Add Comment
Please, Sign In to add comment