@@ -0,0 +1,304 @@
var themes = {};
var themeCSS = '';
var themeListOriginal = {
cleanlounge: {
url: 'http://api.ncla.me/themes/CleanLounge/data.json',
remote: true
},
cleanlounge2: {
url: 'http://api.ncla.me/themes/CleanLounge/data.json',
remote: true
}
};

var Themes = function() {
return this;
};

Themes.prototype.init = function() {
console.log('Themes init');

chrome.storage.local.get('themes', function(result) {
themes = result.themes || {};
console.log('t1');
// If we have a selected theme, add theme CSS to the variable
if (LoungeUser.userSettings.currentTheme) {
console.log('t2');
var name = LoungeUser.userSettings.currentTheme;
if (themes.hasOwnProperty(name)) {
console.log('t3');
themeCSS = themes[name].cachedCSS || '';
}
}

// if we don't have any themes
if (!Object.keys(themes).length) {
console.log('Resetting to bundled themes!');

// add bundled themes
themes = themeListOriginal;
chrome.storage.local.set({themes: themes}, function() {
updateThemes()
});
}
});
};

Themes.prototype.updateThemes = function(callback) {
console.log('Updating themes!');
chrome.storage.local.get('themes', function(result) {
var themes = result.themes;
for (var theme in themes) {
if (themes[theme].remote) {
console.log('Updating theme ' + theme);

// get JSON
var url = themes[theme].url + '?cachebreak=' + Date.now();
if (!url) {
continue;
}

get(url, (function(theme) {
return function() {
try {
var data = this.responseText;
var json = JSON.parse(data);
var err = '';
required = ['name', 'title', 'author', 'version', 'css', 'bg'];

for (var i = 0; i < required.length; ++i) {
if (!json[required[i]]) {
if (!err) {
err = 'The following information is missing from the JSON: ';
}

err += required[i] + ' ';
}
}

if (err) {
console.error(err);
return;
}

if (themes[theme].version == json.version) {
console.log('Version hasn\'t changed, no need to update');
return;
}

console.log('Everything looks good');

// merge new JSON into old, keeping options
if (json.options) {
for (var k in themes[theme].options) {
if (json.options.hasOwnProperty(k)) {
json.options[k].checked = themes[theme].options[k].checked;
} else {
delete themes[theme].options[k];
}
}
}

// merge obj and json
$.extend(true, themes[theme], json);
chrome.storage.local.set({themes: themes});
} catch (err) {
console.error('[' + theme + '] Failed to update: ', err);
}

// cache CSS so we can inject instantly
get(themes[theme].css + '?cachebreak=' + Date.now(), function() {
if (!this.status) {
console.error('[' + theme + '] Failed to retrieve CSS');
return;
}

var css = importantifyCSS(this.responseText);
if (css) {
if (theme === LoungeUser.userSettings.currentTheme) {
themeCSS = css;
}

themes[theme].cachedCSS = css;
chrome.storage.local.set({themes: themes});
}
});
}
})(theme));
}
}

if (callback) {
// fake a delay so users don't get worried, yo
setTimeout(callback, 750);
}
});
};

Themes.prototype.selectTheme = function(themeId) {
console.log('selecting theme with id' , themeId);
LoungeUser.saveSetting("currentTheme", themeId);

if (themes.hasOwnProperty(themeId)) {
themeCSS = themes[themeId].cachedCSS || '';
} else {
themeCSS = '';
}

return this;
};

Themes.prototype.saveThemeSetting = function(themeId, settingId, settingValue) {
themes[themeId].options[settingId].checked = settingValue;
console.log('Saving theme setting', settingId, 'for theme', themeId, 'value', settingValue);
this.syncThemesObject(themes);
return this;
};

Themes.prototype.syncThemesObject = function(themeObj) {
chrome.storage.local.set({themes: themes});
return this;
};

var themesBg = new Themes();
themesBg.init();

/**
* themes.init
* Run when extension has loaded, check if themes object in storage matches the hardcoded themes list,
* updating and readying up the themeCSS variable
*
* themes.update
* Update themes from remote
*
* themes.selectTheme
* Select a theme and sets it active
*
* themes.injectTheme
*
*
* theme.returnThemesObj
*
*/

chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
// Inject CSS file to specific tab
if (request.hasOwnProperty('injectCSS')) {
console.log('Injecting CSS (' + request.injectCSS + ') into tab ' + sender.tab.id);
chrome.tabs.insertCSS(sender.tab.id, {file: request.injectCSS, runAt: 'document_start'}, function(x) {
console.log(x)
});
}

// Inject CSS code to specific tab
if (request.hasOwnProperty('injectCSSCode')) {
// put !important on *everything* because Chrome is fucking retarded
console.log('Injected CSS code into tab ' + sender.tab.id);
chrome.tabs.insertCSS(sender.tab.id, {
code: importantifyCSS(request.injectCSSCode),
runAt: 'document_start'
}, function(x) {
console.log(x)
});
}

// Inject theme CSS (in bg for speed purposes)
if (request.hasOwnProperty('injectCSSTheme')) {
(function loop(id, tries) {
if (tries > 200) {
return;
}

chrome.tabs.insertCSS(id, {code: themeCSS, runAt: 'document_start'}, function(x) {
// retry if it's called before tab exists (dah fuck chrome?)
var e = chrome.runtime.lastError;
if (e) {
console.error('Error while inserting theme CSS: ', e);
setTimeout(loop.bind(this, id, tries + 1), 5);
}
});
})(sender.tab.id, 0);
}

if (request.hasOwnProperty('updateThemes')) {
themesBg.updateThemes(sendResponse);
if (sendResponse) {
return true;
}
}

if (request.hasOwnProperty('setCurrentTheme')) {
console.log('setting theme current');
themesBg.selectTheme(request.setCurrentTheme);
}

if(request.hasOwnProperty('changeThemeSetting')) {
var themeSetting = request.changeThemeSetting;
if(themeSetting.themeId && themeSetting.settingId) {
themesBg.saveThemeSetting(themeSetting.themeId, themeSetting.settingId, themeSetting.settingValue);
}
}

});

chrome.webRequest.onBeforeRequest.addListener(function(details) {
if(LoungeUser.userSettings.disableStylesheetLoading === '1') {
return {cancel: true}
}
},
{
urls: ['*://csgolounge.com/css/*', '*://dota2lounge.com/css/*'],
types: ['stylesheet']
},
['blocking']
);

chrome.alarms.onAlarm.addListener(function(alarm) {
if (alarm.name == 'remoteThemesUpdate') {
//updateThemes();
themesBg.updateThemes();
}
});

chrome.runtime.onInstalled.addListener(function(details) {
//updateThemes();
console.log(themes);
themesBg.updateThemes();
});

function updateThemes(callback) {

}

function importantifyCSS(css) {
if (css) {
try {
var cssTree = parseCSS(css);
var rules = cssTree.stylesheet.rules;

for (var i = 0; i < rules.length; ++i) {
var rule = rules[i];
var decls = rule.declarations;

if (!decls) {
continue;
}

for (var l = 0; l < decls.length; ++l) {
if (!decls[l].value) {
continue;
}

decls[l].value = decls[l].value.replace('!important', '').trim() + ' !important';
}
}

css = stringifyCSS(cssTree, {compress: true});
} catch (err) {
console.error('Tried to parse CSS, failed: ', err);
return '';
}
}

return css;
}
@@ -319,7 +319,7 @@ function init() {
//'<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 class="ld-trade-filters-info"><span class="ld-filtered-amount">0 trades were</span> 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() {
@@ -580,7 +580,7 @@ function newFreezeReturn(tries) {
toHide[i].classList.remove('hidden');
}

// The reason why this should never happen is because we cancel out this request from bet_bg.js
// The reason why this should never happen is because we cancel out this request from bg/bet.js
$.ajax({
url: 'ajax/postToReturn.php',
success: function(data) {
@@ -151,8 +151,9 @@ Trade.prototype.fetchExtraData = function(callback) {
};

Trade.prototype.getExtraSteamData = function(profileId, callback) {
console.log((window.location.protocol + '//steamcommunity.com/profiles/' + profileId + '?xml=1'));
$.ajax({
url: 'http://steamcommunity.com/profiles/' + profileId + '?xml=1',
url: (window.location.protocol + '//steamcommunity.com/profiles/' + profileId + '?xml=1'),
type: 'GET',
success: function(data) {
//console.log(data);
@@ -357,8 +358,7 @@ Trade.prototype.generateTradeURL = function(appID) {
if(!this.tradeID) {
return;
}

return 'http://' + (appID == '730' ? 'csgolounge.com' : 'dota2lounge.com') + '/trade?t=' + this.tradeID;
return window.location.protocol + '//' + (appID == '730' ? 'csgolounge.com' : 'dota2lounge.com') + '/trade?t=' + this.tradeID;
};

Trade.prototype.getTradeDescriptionFromHTML = function() {
@@ -378,7 +378,7 @@ function tradeObject(domObj) {
function updateFilteredCount() {
tradesFiltered++;
if(LoungeUser.userSettings.showTradeFilterBox === '1') {
$('span.ld-filtered-amount').text(tradesFiltered + (tradesFiltered === 1 ? ' trade' : ' trades'));
$('span.ld-filtered-amount').text(tradesFiltered + (tradesFiltered === 1 ? ' trade was' : ' trades were'));
}
}

@@ -16,8 +16,9 @@
"app/helpers.js",
"app/user.js",
"app/match.js",
"app/bg/bet_bg.js",
"app/bg/background.js"
"app/bg/bet.js",
"app/bg/background.js",
"app/bg/themes.js"
],
"persistent": true
},
@@ -26,7 +27,7 @@
"default_title": "LoungeDestroyer settings",
"default_popup": "popup/popup.html"
},
"options_page": "settings/options.html",
"options_page": "settings_v2/index.html",
"permissions": [
"notifications",
"*://csgolounge.com/*",
@@ -6,7 +6,9 @@
"directories": {
"test": "tests"
},
"dependencies": {},
"dependencies": {
"marked": "^0.3.5"
},
"devDependencies": {
"gulp": "^3.9.0",
"gulp-filter": "^3.0.0",
@@ -22,6 +22,9 @@ navAnchor.each( function() {
parent.not('.logo').addClass('active');
});

var changelogRequested = false;
var patreonsRequested = false;

// -----------------------------------------
// Page switcher
// -----------------------------------------
@@ -53,6 +56,88 @@ navAnchor.click( function(e) {
$('div.group-error').removeClass('group-error');
}
}

if(page === 'page-changelog') {
var $changelog = $('#page-changelog .pad-full');
var $changelogContent = $('#changelog-content');

if(!changelogRequested) {
$('.preloader.loading', $changelog).show();
$.ajax('https://api.github.com/repos/ncla/LoungeDestroyer/releases?per_page=15', {
type: 'GET',
success: function(data) {
console.log(data);
$.each(data, function(i, release) {
//console.log(release);
//console.log(release.body);
console.log(marked(release.body));
//<h3>v0.8.2.2
//<small>released on april 31st, 2015</small>
//</h3>
var releaseVersion = release.tag_name;
var releaseDate = moment(release.published_at).format('MMMM Do, YYYY').toLowerCase();
console.log(releaseDate);
$changelogContent.append('<h3>' + releaseVersion + ' <small>released on ' + releaseDate + '</small></h3>');
$changelogContent.append(marked(release.body));
$changelogContent.append('<br class="margin"/>');
});
$changelogContent.find('ul').addClass('list');
changelogRequested = true;
$('.preloader.loading', $changelog).fadeOut(function() {
$changelogContent.fadeIn();
});
},
error: function(jqXHR) {
$('.preloader.loading', $changelog).fadeOut(function() {
$changelogContent.fadeIn();
});
$changelogContent.append('<p>Failed to load changelog.. :(</p>');
changelogRequested = true;
}
});
}
}

if(page === 'page-donate') {
if(!patreonsRequested) {
$('#page-donate .preloader.loading').show();
$.ajax('http://api.ncla.me/destroyer/patreonlist', {
type: 'GET',
success: function(data) {
if(data.length) {
//$('.patreon-list').removeClass('hidden');
var placeHolder = $('.patreon-list .placeholder');
$.each(data, function(i, v) {
var newRow = $(placeHolder).clone().removeClass('hidden');
$(newRow).find('th:eq(0)').text(i + 1);
$(newRow).find('td:eq(0)').text(v.name);
$(newRow).find('td:eq(1)').text('$' + v.amount);
$('.patreon-list tbody').append($(newRow));
})
} else {
$('.no-patreons').removeClass('hidden');
}

$('.preloader.loading', $changelog).fadeOut(function() {
setTimeout(function() {
$('#page-donate .patreon-list').fadeIn();
}, 1000);
});

patreonsRequested = true;
},
error: function(jqXHR) {
$('.not-loaded-patreons').removeClass('hidden');
patreonsRequested = true;
}
});
}

}

if(page === 'page-themes') {
initSlider();
}
});

// -----------------------------------------
@@ -230,8 +315,9 @@ $("input[data-validation]")
})
// or when they lose focus
.blur( function(){
var self = this;
clearTimeout(self.validateTimer);
validateInput(self, function(){}, true);
validateInput($(self), function(){}, true);
}
);

Large diffs are not rendered by default.

@@ -3,6 +3,7 @@
@import selectize.scss
@import mixins.scss
@import modal.scss
@import preloader.scss

$main-orange: #e79403
$main-width: 980px
@@ -335,6 +336,7 @@ main
+clearfix

section
padding-top: 100px
transition: margin-top 0.2s
+clearfix

@@ -483,6 +485,7 @@ $btnGrayActive: darken($btnGray,7%)

> li
margin-right: 7px
margin-bottom: 5px
float: left

&:last-child
@@ -508,6 +511,9 @@ form
z-index: 10
right: 0

div.form-inline
@extend form.form-inline // Might want to re-do this

input[type="text"],
input[type="number"],
input[type="url"],
@@ -865,8 +871,6 @@ $error-color: #d32f2f
$slider-height: 551px

#page-themes
margin-top: 5px

.card
.group[class*="col-"]
padding: 0
@@ -1147,6 +1151,18 @@ $slider-height: 551px
display: block
text-align: center

#themes-slider li[data-theme]
.btn.enabled
display: none
.btn.enable-this-theme
display: inline-block

#themes-slider li[data-theme].active
.btn.enabled
display: inline-block
.btn.enable-this-theme
display: none

.theme-desc
border-bottom: 1px solid #eeeeee
padding: 10px 15px
@@ -1195,6 +1211,59 @@ $slider-height: 551px
// # Footer
// #
#page-donate
.card:nth-child(2)
min-height: 500px
table
width: 100%
margin-top: 20px

//border-collapse: separate
//border-spacing: 5em
thead
font-size: 12px
color: #363636

tbody
font-size: 13px
color: #575757

tr
height: 35px
line-height: 35px
border-bottom: 1px solid #e4e4e4

tbody tr:hover
background-color: #EEEEEE

thead tr:first-child
border-bottom: 2px solid #e4e4e4

thead tr th:first-child
width: 50px

tbody tr:last-child
border-bottom: 0

tr th, tr td
text-align: right
padding: 0 10px

thead tr th:nth-child(2), tbody tr td:nth-child(2)
text-align: left

//thead th:nth-child(2), tbody tr:nth-child(1)
// text-align: left
#page-settings .keywordsContainer
.keyword
display: inline-block
background: #eaeaea
padding: 3px 6px
border-radius: 5px
margin: 1px

footer[role="contentinfo"]
padding-bottom: 17px
font-size: 14px
@@ -1211,4 +1280,5 @@ footer[role="contentinfo"]
text-align: right

a
color: #595959
color: #595959

Large diffs are not rendered by default.

Large diffs are not rendered by default.