@@ -12,9 +12,11 @@ var inventory = new Inventory();
var lastAccept = 0;
var blacklistedItemList = {};
var earlyBackpackLoad = false;
var tradeShowFilter;
var tradeHideFilter;
var tradeMarkFilter;
var timezoneName = (LoungeUser.userSettings.timezone == 'auto' ? jstz.determine().name() : LoungeUser.userSettings.timezone);
var tradesFiltered = 0;

var container = document.createElement('div');

@@ -166,10 +168,12 @@ function init() {
}

// create RegExp's from users trade filters
var tradeShowArr = LoungeUser.userSettings.showTradesFilterArray || [];
var tradeHideArr = LoungeUser.userSettings.hideTradesFilterArray || [];
var tradeMarkArr = LoungeUser.userSettings.markTradesFilterArray || [];
var tradeItemsHaveArr = LoungeUser.userSettings.hideTradesItemsHave || [];
var tradeItemsWantArr = LoungeUser.userSettings.hideTradesItemsWant || [];
tradeShowFilter = createKeywordRegexp(tradeShowArr);
tradeHideFilter = createKeywordRegexp(tradeHideArr);
tradeMarkFilter = createKeywordRegexp(tradeMarkArr);

// the following requires DOM
$(document).ready(function() {
@@ -306,11 +310,44 @@ function init() {
});
}

if ($('a[href="/trades"]').length || document.URL.indexOf('/result?') !== -1 || document.URL.indexOf('/trades') !== -1) {
$('.tradepoll').each(function(index, value) {
var trade = new Trade(value);
trade.addTradeDescription();
var isHomepage = ($('.title a[href="/trades"]').length > 0);

if (isHomepage || document.URL.indexOf('/result?') !== -1 || document.URL.indexOf('/trades') !== -1) {
if(LoungeUser.userSettings.showTradeFilterBox === '1') {
$('div.title:eq(0)').after('<div class="ld-trade-filters">' +
'<div class="ld-trade-filters-buttons">' +
//'<button class="buttonright">Hide this</button>' +
'<a href="#" class="buttonright" id="changefilters">Change filters</a>' +
'<button class="buttonright" id="showtrades">Show trades</button></div>' +
'<div class="ld-trade-filters-info"><span class="ld-filtered-amount">0 trades</span> were filtered <br>by your <a href="#"><b>trade settings</b></a>' +
'</div> </div>');

$('.ld-trade-filters #changefilters, .ld-trade-filters .ld-trade-filters-info a').click(function() {
chrome.runtime.sendMessage({openSettings: true}, function(data) {
console.log('Message sent for opening settings page');
});
});

$('.ld-trade-filters #showtrades').click(function() {
$('.tradepoll').each(function(index, value) {
var trade = tradeObject(value);
$(trade.tradeElement).show();
});
});
}

$('.tradepoll:not(.notavailable)').each(function(index, value) {
var trade = tradeObject(value);
if((LoungeUser.userSettings.tradeLoadExtra === '1' && isHomepage) || LoungeUser.userSettings.tradeLoadExtra === '2') {
if(isScrolledIntoView(trade.tradeElement)) {
trade.fetchExtraData(function() {});
}
}
if(LoungeUser.userSettings.tradeLoadExtra === '1' && !isHomepage) {
trade.fetchExtraData(function() {});
}
});

}

if (document.URL.indexOf('/match?m=') != -1 || document.URL.indexOf('/predict') != -1) {
@@ -356,104 +393,104 @@ function init() {

// add custom 'Preview' buttons to trades that don't have it
// first create preview element if it doesn't exist
(function() {
if (LoungeUser.userSettings.addTradePreviews === '0') {
return;
}

if (!document.getElementById('logout')) {
return;
}

var previewElm = document.getElementById('preview');

if (previewElm) {
return;
}

if (document.querySelector('.tradepoll')) {
previewElm = document.createElement('section');
previewElm.id = 'preview';
previewElm.className = 'destroyer';
document.body.appendChild(previewElm);
customPreview = true;
}

previewElm = $(previewElm);

$('.tradepoll').each(function(ind, elm) {
if (!elm.querySelector('.tradeheader a.button[onclick^="livePreview"]')) {
var header = elm.querySelector('.tradeheader');
var span = (header && header.querySelector('span[style*="float: right"]')) || false;
var btn = document.createElement('a');

btn.className = 'button destroyer live-preview';
btn.innerHTML = 'Preview';
btn.style.float = 'none';

if (!header) {
return;
}

if (!span) {
// if buttons already exist in header, don't place within span
if (elm.querySelector('.tradeheader > a.button')) {
span = header;
btn.className = 'buttonright';
btn.style.float = 'right';
} else {
span = document.createElement('span');
span.style.float = 'right';
header.appendChild(span);
}
}

var tradeId = elm.querySelector('a[href^="trade?"]');
var self = this instanceof $ ? this : $(this);
if (tradeId) {
tradeId = tradeId.getAttribute('href').replace('trade?t=', '');
} else {
return;
}

// magic happens here
btn.addEventListener('click', function() {
if (previewElm.attr('data-index') == ind) {
previewElm.hide();
previewElm.attr('data-index', '-1');
return;
}

previewElm.show();
previewElm.html('<img src="../img/load.gif" id="loading" style="margin: 0.75em 2%">');

var offset = self.offset();
if ($(document).width() > offset.left + self.outerWidth() + Math.max(410, $(document).width() * 0.5)) {
offset.top = Math.floor(offset.top - 20);
offset.left = Math.floor(offset.left + self.outerWidth() + 10);
} else {
// position below if not enough space on right
offset.top = Math.floor(offset.top + self.height() + 10);
offset.left = Math.floor(offset.left);
}

previewElm.offset(offset);

$.ajax({
url: 'ajax/livePreview.php',
type: 'POST',
data: 't=' + tradeId,
success: function(d) {
previewElm.html(d).slideDown('fast');
previewElm.attr('data-index', ind);
}
})
});

span.appendChild(btn);
}
});
})();
//(function() {
// if (LoungeUser.userSettings.addTradePreviews === '0') {
// return;
// }
//
// if (!document.getElementById('logout')) {
// return;
// }
//
// var previewElm = document.getElementById('preview');
//
// if (previewElm) {
// return;
// }
//
// if (document.querySelector('.tradepoll')) {
// previewElm = document.createElement('section');
// previewElm.id = 'preview';
// previewElm.className = 'destroyer';
// document.body.appendChild(previewElm);
// customPreview = true;
// }
//
// previewElm = $(previewElm);
//
// $('.tradepoll').each(function(ind, elm) {
// if (!elm.querySelector('.tradeheader a.button[onclick^="livePreview"]')) {
// var header = elm.querySelector('.tradeheader');
// var span = (header && header.querySelector('span[style*="float: right"]')) || false;
// var btn = document.createElement('a');
//
// btn.className = 'button destroyer live-preview';
// btn.innerHTML = 'Preview';
// btn.style.float = 'none';
//
// if (!header) {
// return;
// }
//
// if (!span) {
// // if buttons already exist in header, don't place within span
// if (elm.querySelector('.tradeheader > a.button')) {
// span = header;
// btn.className = 'buttonright';
// btn.style.float = 'right';
// } else {
// span = document.createElement('span');
// span.style.float = 'right';
// header.appendChild(span);
// }
// }
//
// var tradeId = elm.querySelector('a[href^="trade?"]');
// var self = this instanceof $ ? this : $(this);
// if (tradeId) {
// tradeId = tradeId.getAttribute('href').replace('trade?t=', '');
// } else {
// return;
// }
//
// // magic happens here
// btn.addEventListener('click', function() {
// if (previewElm.attr('data-index') == ind) {
// previewElm.hide();
// previewElm.attr('data-index', '-1');
// return;
// }
//
// previewElm.show();
// previewElm.html('<img src="../img/load.gif" id="loading" style="margin: 0.75em 2%">');
//
// var offset = self.offset();
// if ($(document).width() > offset.left + self.outerWidth() + Math.max(410, $(document).width() * 0.5)) {
// offset.top = Math.floor(offset.top - 20);
// offset.left = Math.floor(offset.left + self.outerWidth() + 10);
// } else {
// // position below if not enough space on right
// offset.top = Math.floor(offset.top + self.height() + 10);
// offset.left = Math.floor(offset.left);
// }
//
// previewElm.offset(offset);
//
// $.ajax({
// url: 'ajax/livePreview.php',
// type: 'POST',
// data: 't=' + tradeId,
// success: function(d) {
// previewElm.html(d).slideDown('fast');
// previewElm.attr('data-index', ind);
// }
// })
// });
//
// span.appendChild(btn);
// }
// });
//})();

container.querySelector('input').value = LoungeUser.userSettings.autoDelay || 5;

@@ -630,6 +667,23 @@ $(document).on('mouseover', '.matchmain', function() {
}
});

$(document).on('mouseover', '.tradepoll:not(.notavailable)', function() {
if(LoungeUser.userSettings.tradeLoadExtra === '3') {
var trade = tradeObject(this);
trade.fetchExtraData(function(){});
}
});

$(window).scrolled(function() {
console.log('Scrolled');
$('.tradepoll:not(.notavailable)').each(function(index, value) {
if(isScrolledIntoView(value) && ['1', '2'].indexOf(LoungeUser.userSettings.tradeLoadExtra) !== -1) {
var trade = tradeObject(value);
trade.fetchExtraData(function(){});
}
});
});

// auto-magically add market prices to newly added items, currently only for trade list
var itemObs = new MutationObserver(function(records) {
for (var i = 0, j = records.length; i < j; ++i) {
@@ -638,10 +692,9 @@ var itemObs = new MutationObserver(function(records) {
for (var k = 0, l = records[i].addedNodes.length; k < l; ++k) {
var elm = records[i].addedNodes[k];
if (elm.classList) {
if (elm.classList.contains('tradepoll')) {
if (elm.classList.contains('tradepoll') && !elm.classList.contains('notavailable')) {
hasTradeNodes = true;
var trade = new Trade(elm);
trade.addTradeDescription();
var trade = tradeObject(elm);
}
}
}

Large diffs are not rendered by default.

@@ -49,7 +49,22 @@ User.prototype.defaultSettings =
opskins: '1',
bettingValuesCsgo: '0',
betHistoryTotalColumn: '2',
disableStylesheetLoading: '0'
disableStylesheetLoading: '0',

globalTradeFilters: '1',
showTradeFilterBox: '1',
tradeLoadExtra: '1',
tradeLoadSteamData: '1',
hideFilteredTrades: '1',
showTradeDescriptions: '1',

hideDonatorTrades: '0',
hideNoTradeofferTrades: '0',
hideTradesPrivateProfile: '0',
maxVacBans: '0',
minSteamLevel: '0',
minAccAgeDays: '0',
minAlltimePlaytime: '0'
};

// defaultSettings get modified when changing settings?
@@ -33,7 +33,7 @@ function restore_options() {
});

// display the keywords list
$("#hideTradesFilter,#markTradesFilter").each(function(){
$("#showTradesFilter, #hideTradesFilter, #hideTradesItemsHave, #hideTradesItemsWant").each(function(){
parseAndDisplayKeywords.apply(this);
});

@@ -171,10 +171,10 @@ function restore_options() {
a = new Audio(url);
a.play();
});
$("#hideTradesFilter, #markTradesFilter").on("change", function(){
$("#showTradesFilter, #hideTradesFilter, #hideTradesItemsHave, #hideTradesItemsWant").on("change", function(){
var outp = parseAndDisplayKeywords.apply(this);

defaultUser.saveSetting(this.id+"Array", outp);
defaultUser.saveSetting(this.id + "Array", outp);
});

// handles extracting and displaying keywords. Should be used as event handler for input
@@ -187,14 +187,14 @@ function restore_options() {
// get all text within quotes
input = input.replace(quoteRegexp, function(m1,m2,m3){
if (m3.length && keywords.indexOf(m3) === -1) {
keywords.push(m3.trim().toLowerCase()); // push the content (sans quotes) to keywords
keywords.push(m3.trim()); // push the content (sans quotes) to keywords
}
return ""; // remove from string
});
// get all words (separated by whitespace)
input.replace(/[^\s]+/g, function(m1){
if (m1.length && keywords.indexOf(m1) === -1) {
keywords.push(m1.trim().toLowerCase()); // push word to keywords
keywords.push(m1.trim()); // push word to keywords
}
return "";
});
@@ -195,13 +195,6 @@ <h3 class="page-header">Features</h3>
<option value="0">Disabled</option>
</select>
</div>
<div class="col-md-6 ld-setting">
<label class="control-label">Show trade descriptions:</label>
<select id="showDescriptions" class="form-control">
<option value="1">Enabled</option>
<option value="0">Disabled</option>
</select>
</div>
<div class="col-md-6 ld-setting">
<label class="control-label">Enable auto-betting/-returning/-accept:</label>
<select id="enableAuto" class="form-control">
@@ -211,13 +204,13 @@ <h3 class="page-header">Features</h3>
<option value="0">Disabled</option>
</select>
</div>
<div class="col-md-6 ld-setting">
<label class="control-label">Add preview buttons to all trades:</label>
<select id="addTradePreviews" class="form-control">
<option value="1">Enabled</option>
<option value="0">Disabled</option>
</select>
</div>
<!--<div class="col-md-6 ld-setting">-->
<!--<label class="control-label">Add preview buttons to all trades:</label>-->
<!--<select id="addTradePreviews" class="form-control">-->
<!--<option value="1">Enabled</option>-->
<!--<option value="0">Disabled</option>-->
<!--</select>-->
<!--</div>-->
<div class="col-md-6 ld-setting">
<label class="control-label">Show match type and exact time:</label>
<select id="showExtraMatchInfo" class="form-control">
@@ -266,30 +259,161 @@ <h3 class="page-header">Audio</h3>
</div>
</div>

<h3 class="page-header">Trade filters</h3>
<h3 class="page-header">Trades</h3>

<h4 class="page-header">Trade features</h4>

<div class="row">
<div class="col-md-6 ld-setting">
<label class="control-label">Trade filtering:</label>
<select id="globalTradeFilters" class="form-control">
<option value="1">Enable trade filters</option>
<option value="0">Disable trade filters</option>
</select>
</div>
<div class="col-md-6 ld-setting">
<label class="control-label">Load extra trade data:</label>
<select id="tradeLoadExtra" class="form-control">
<option value="3">Load when mouse is over the trade</option>
<option value="2">Load only for trades that are in the view</option>
<option value="1">Load automatically for all trades on search, in view on home page</option>
<option value="0">Disable</option>
</select>
</div>
<div class="col-md-6 ld-setting">
<label class="control-label">Load Steam profile data:</label>
<select id="tradeLoadSteamData" class="form-control">
<option value="1">Enable</option>
<option value="0">Disable</option>
</select>
</div>
<div class="col-md-6 ld-setting">
<label class="control-label">Show 'x trades were filtered' info box on the page:</label>
<select id="showTradeFilterBox" class="form-control">
<option value="1">Enable</option>
<option value="0">Disable</option>
</select>
</div>
<div class="col-md-6 ld-setting">
<label class="control-label">Hide filtered trades:</label>
<select id="hideFilteredTrades" class="form-control">
<option value="1">Enable</option>
<option value="0">Disable</option>
</select>
</div>
<div class="col-md-6 ld-setting">
<label class="control-label">Show trade descriptions:</label>
<select id="showTradeDescriptions" class="form-control">
<option value="1">Enabled</option>
<option value="0">Disabled</option>
</select>
</div>
</div>

<h4 class="page-header">Trade filters</h4>

<div class="row">
<div class="col-md-4 ld-setting">
<label class="control-label">Hide trades posted by site donators:</label>
<select id="hideDonatorTrades" class="form-control">
<option value="1">Enable</option>
<option value="0">Disable</option>
</select>
</div>
<div class="col-md-4 ld-setting">
<label class="control-label">Hide trades that do not have trade offer link:</label>
<select id="hideNoTradeofferTrades" class="form-control">
<option value="1">Enable</option>
<option value="0">Disable</option>
</select>
</div>
<div class="col-md-4 ld-setting">
<label class="control-label">Hide trades where the user has private profile:</label>
<select id="hideTradesPrivateProfile" class="form-control">
<option value="1">Enable</option>
<option value="0">Disable</option>
</select>
</div>

<div class="col-md-3 ld-setting">
<label for="smallBetPercentage" class="control-label">Maximum amount of VAC bans:</label>
<input type="number" min="0" max="100" class="form-control" id="maxVacBans">
</div>
<div class="col-md-3 ld-setting">
<label for="smallBetPercentage" class="control-label">Minimum Steam level:</label>
<input type="number" min="0" max="100" class="form-control" id="minSteamLevel">
</div>
<div class="col-md-3 ld-setting">
<label for="smallBetPercentage" class="control-label">Minimum account age in days:</label>
<input type="number" min="0" max="100" class="form-control" id="minAccAgeDays">
</div>
<div class="col-md-3 ld-setting">
<label for="smallBetPercentage" class="control-label">Minimum all time play time:</label>
<input type="number" min="0" max="100" class="form-control" id="minAlltimePlaytime">
</div>
</div>



<div class="row">
<div class="col-md-6 ld-setting">
<label class="control-label">Hide trades that include:</label>
<label class="control-label">Show only trades where descriptions include:</label>
<input type="text" id="showTradesFilter" class="form-control" placeholder="Enter keywords">
<p class="help-block">
Only trades that include these keywords will be shown.
</p>
<p class="help-block">Currently matching:
<span class="keywordsContainer"></span>
</p>
</div>
<div class="col-md-6 ld-setting">
<label class="control-label">Hide trades where descriptions include:</label>
<input type="text" id="hideTradesFilter" class="form-control" placeholder="Enter keywords">
<p class="help-block">
Any trades that include these keywords will be hidden. Keywords are separated by space, unless enclosed in quotes. Punctuation and leading/trailing whitespace is ignored when matching.
Any trades that include these keywords will be hidden.
</p>
<p class="help-block">Currently matching:
<span class="keywordsContainer"></span>
</p>
</div>

<!--<div class="col-md-4 ld-setting">-->
<!--<label class="control-label">Mark trades that include:</label>-->
<!--<input type="text" id="markTradesFilter" class="form-control" placeholder="Enter keywords">-->
<!--<p class="help-block">-->
<!--Any trades that include these keywords will be visibly marked with a red line next to their description.-->
<!--</p>-->
<!--<p class="help-block">Currently matching:-->
<!--<span class="keywordsContainer"></span>-->
<!--</p>-->
<!--</div>-->
</div>

<div class="row">
<div class="col-md-6 ld-setting">
<label class="control-label">Mark trades that include:</label>
<input type="text" id="markTradesFilter" class="form-control" placeholder="Enter keywords">
<label class="control-label">Hide trades where user has following items:</label>
<input type="text" id="hideTradesItemsHave" class="form-control" placeholder="Enter item names">
<p class="help-block">
Any trades that include these keywords will be visibly marked with a red line next to their description. Keywords are separated by space, unless enclosed in quotes. Punctuation and leading/trailing whitespace is ignored when matching.
Only trades that include these item names will be shown.
</p>
<p class="help-block">Currently matching:
<span class="keywordsContainer"></span>
</p>
</div>
<div class="col-md-6 ld-setting">
<label class="control-label">Hide trades where user wants following items:</label>
<input type="text" id="hideTradesItemsWant" class="form-control" placeholder="Enter item names">
<p class="help-block">
Only trades that include these item names will be shown.
</p>
<p class="help-block">Currently matching:
<span class="keywordsContainer"></span>
</p>
</div>
</div>

<div class="alert alert-info">Keywords are separated by space, unless enclosed in quotes. Punctuation and leading/trailing whitespace is ignored when matching for trade description. Item names need to have full item name, separated by double quotes.</div>

<h3 class="page-header">Betting inventory statistics</h3>
<div class="row">
<div class="col-md-4 ld-setting">