Skip to content

Commit

Permalink
Merge pull request #62 from dolkensp/develop
Browse files Browse the repository at this point in the history
Merge develop -> master
  • Loading branch information
peter-dolkens authored Jun 10, 2020
2 parents ff27647 + 60e8352 commit f1259aa
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 74 deletions.
2 changes: 2 additions & 0 deletions src/content_scripts/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
'web_resources/HangarXPLOR.Ships.js',
'web_resources/HangarXPLOR.SearchBox.js',
'web_resources/HangarXPLOR.Search.js',
'web_resources/HangarXPLOR.SaveCache.js',
'web_resources/HangarXPLOR.SaveSettings.js',
'web_resources/HangarXPLOR.Render.js',
'web_resources/HangarXPLOR.ProcessPage.js',
'web_resources/HangarXPLOR.ProcessItem.js',
'web_resources/HangarXPLOR.Pager.js',
'web_resources/HangarXPLOR.Log.js',
'web_resources/HangarXPLOR.LoadCache.js',
'web_resources/HangarXPLOR.LoadSettings.js',
'web_resources/HangarXPLOR.LoadPage.js',
'web_resources/HangarXPLOR.Filter.js',
Expand Down
2 changes: 2 additions & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
"web_resources/HangarXPLOR.Dropdown.js",
"web_resources/HangarXPLOR.Filter.js",
"web_resources/HangarXPLOR.LoadPage.js",
"web_resources/HangarXPLOR.LoadCache.js",
"web_resources/HangarXPLOR.LoadSettings.js",
"web_resources/HangarXPLOR.Log.js",
"web_resources/HangarXPLOR.Pager.js",
"web_resources/HangarXPLOR.ProcessItem.js",
"web_resources/HangarXPLOR.ProcessPage.js",
"web_resources/HangarXPLOR.Render.js",
"web_resources/HangarXPLOR.SaveCache.js",
"web_resources/HangarXPLOR.SaveSettings.js",
"web_resources/HangarXPLOR.Search.js",
"web_resources/HangarXPLOR.SearchBox.js",
Expand Down
24 changes: 24 additions & 0 deletions src/web_resources/HangarXPLOR.LoadCache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

var HangarXPLOR = HangarXPLOR || {};

HangarXPLOR.LoadCache = function(callback)
{
HangarXPLOR.Log('Load Cache');

chrome.storage.local.get(null, (cache) => {

if (HangarXPLOR._cacheHash == HangarXPLOR._activeHash && cache['cache:count'] > 0)
{
HangarXPLOR._fromCache = true;

for (var i = 0; i < cache['cache:count']; i++) { HangarXPLOR.ProcessItem.apply($(cache['cache:' + i])[0]) }

HangarXPLOR.DrawUI();
return;
}

HangarXPLOR._fromCache = false;
if (typeof callback === 'function') callback.call(this);

});
}
4 changes: 3 additions & 1 deletion src/web_resources/HangarXPLOR.LoadPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var HangarXPLOR = HangarXPLOR || {};
// Load a page of pledges from RSI
HangarXPLOR.LoadPage = function(pageNo)
{
pageNo = pageNo || 1;

HangarXPLOR.UpdateStatus(pageNo);

var url = '/account/pledges?page=' + pageNo;
Expand All @@ -16,4 +18,4 @@ HangarXPLOR.LoadPage = function(pageNo)
var $page = $('<div>');

$page.load(url + ' .page-wrapper', function(response, status) { if (status == "success") { HangarXPLOR.ProcessPage(this, pageNo) } else { HangarXPLOR.Log('Error loading page ' + pageNo + ' of your hangar - please contact [email protected] for further support') } });
}
}
11 changes: 6 additions & 5 deletions src/web_resources/HangarXPLOR.LoadSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ HangarXPLOR.LoadSettings = function(callback)
HangarXPLOR._pageNo = settings._pageNo || 1;
HangarXPLOR._pageCount = settings._pageCount || 10;
HangarXPLOR._logEnabled = settings._logEnabled || false;
HangarXPLOR._cacheHash = settings._cacheHash || 0;

HangarXPLOR._feature = HangarXPLOR._feature || {};
HangarXPLOR._feature.LTI = settings._feature_LTI || '';
HangarXPLOR._feature.Warbond = settings._feature_Warbond || '';
HangarXPLOR._feature = HangarXPLOR._feature || {};
HangarXPLOR._feature.LTI = settings._feature_LTI || '';
HangarXPLOR._feature.Warbond = settings._feature_Warbond || '';
HangarXPLOR._feature.Giftable = settings._feature_Giftable || '';
HangarXPLOR._feature.Meltable = settings._feature_Meltable || '';
HangarXPLOR._feature.Upgraded = settings._feature_Upgraded || '';
HangarXPLOR._feature.Valuable = settings._feature_Valuable || '';
HangarXPLOR._feature.Reward = settings._feature_Reward || '';
HangarXPLOR._feature.Summary = settings._feature_Summary || 'cash';
HangarXPLOR._feature.Reward = settings._feature_Reward || '';
HangarXPLOR._feature.Summary = settings._feature_Summary || 'cash';

HangarXPLOR.Log('Loaded Settings', settings);

Expand Down
5 changes: 4 additions & 1 deletion src/web_resources/HangarXPLOR.ProcessItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ HangarXPLOR._giftableCount = HangarXPLOR._giftableCount || 0;
HangarXPLOR._packageCount = HangarXPLOR._packageCount || 0;
HangarXPLOR._ltiCount = HangarXPLOR._ltiCount || 0;
HangarXPLOR._warbondCount = HangarXPLOR._warbondCount || 0;
HangarXPLOR._raw = HangarXPLOR._raw || [];

// Apply a pre-defined filter to a list of items
HangarXPLOR.ProcessItem = function()
{

// Pre-cache raw markup
if (HangarXPLOR._fromCache != true) HangarXPLOR._raw.push(this.outerHTML);

// Preprocess Tumbril Cyclone
$('.without-images .title:contains(Tumbril Cyclone)', this).each(function() {
var $tumbril = $(this);
Expand Down
1 change: 1 addition & 0 deletions src/web_resources/HangarXPLOR.ProcessPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ HangarXPLOR.ProcessPage = function($page, pageNo)

if (isEmpty || $items.length < 10)
{
HangarXPLOR.SaveCache();
HangarXPLOR.DrawUI();
} else {
HangarXPLOR.LoadPage(pageNo + 1);
Expand Down
24 changes: 24 additions & 0 deletions src/web_resources/HangarXPLOR.SaveCache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

var HangarXPLOR = HangarXPLOR || {};

HangarXPLOR.SaveCache = function(callback)
{
if (HangarXPLOR._fromCache == true) return;

var cacheItems = {};

$.each(HangarXPLOR._raw, (index, item) => {
cacheItems['cache:' + index] = item;
});

cacheItems['cache:count'] = HangarXPLOR._raw.length;

delete HangarXPLOR._raw;

chrome.storage.local.clear();
chrome.storage.local.set(cacheItems);

HangarXPLOR._cacheHash = HangarXPLOR._activeHash;

HangarXPLOR.SaveSettings(callback);
}
21 changes: 11 additions & 10 deletions src/web_resources/HangarXPLOR.SaveSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ HangarXPLOR.SaveSettings = function()
HangarXPLOR = HangarXPLOR || {};
HangarXPLOR._feature = HangarXPLOR._feature || {};

var settings = settings || {};
settings._type = HangarXPLOR._type || 'All';
settings._sort = HangarXPLOR._sort || 'Purchased';
settings._pageNo = HangarXPLOR._pageNo || 1;
settings._pageCount = HangarXPLOR._pageCount || 10;
settings._logEnabled = HangarXPLOR._logEnabled || false;
var settings = settings || {};
settings._type = HangarXPLOR._type || 'All';
settings._sort = HangarXPLOR._sort || 'Purchased';
settings._pageNo = HangarXPLOR._pageNo || 1;
settings._pageCount = HangarXPLOR._pageCount || 10;
settings._logEnabled = HangarXPLOR._logEnabled || false;
settings._cacheHash = HangarXPLOR._cacheHash || 0;

settings._feature_LTI = HangarXPLOR._feature.LTI || '';
settings._feature_Warbond = HangarXPLOR._feature.Warbond || '';
settings._feature_LTI = HangarXPLOR._feature.LTI || '';
settings._feature_Warbond = HangarXPLOR._feature.Warbond || '';
settings._feature_Giftable = HangarXPLOR._feature.Giftable || '';
settings._feature_Meltable = HangarXPLOR._feature.Meltable || '';
settings._feature_Upgraded = HangarXPLOR._feature.Upgraded || '';
settings._feature_Valuable = HangarXPLOR._feature.Valuable || '';
settings._feature_Reward = HangarXPLOR._feature.Reward || '';
settings._feature_Summary = HangarXPLOR._feature.Summary || 'cash';
settings._feature_Reward = HangarXPLOR._feature.Reward || '';
settings._feature_Summary = HangarXPLOR._feature.Summary || 'cash';

HangarXPLOR.Log('Saved Settings', settings);

Expand Down
69 changes: 12 additions & 57 deletions src/web_resources/HangarXPLOR.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,14 @@ var HangarXPLOR = HangarXPLOR || {};
HangarXPLOR.$list = null; // Element where we display the pledges
HangarXPLOR._inventory = []; // Inventory containing all pledges
HangarXPLOR._debugRoot = $('#HangarXPLOR-js-1').attr('src').replace(/(.*)web_resources.*/, "$1");

HangarXPLOR.LoadSettings = function(callback)
{
chrome.storage.sync.get(null, function(settings) {
settings = settings || {};

HangarXPLOR = HangarXPLOR || {};
HangarXPLOR._type = settings._type || 'All';
HangarXPLOR._sort = settings._sort || 'Purchased';
HangarXPLOR._pageNo = settings._pageNo || 1;
HangarXPLOR._pageCount = settings._pageCount || 10;
HangarXPLOR._logEnabled = settings._logEnabled || false;

HangarXPLOR._feature = HangarXPLOR._feature || {};
HangarXPLOR._feature.LTI = settings._feature_LTI || '';
HangarXPLOR._feature.Warbond = settings._feature_Warbond || '';
HangarXPLOR._feature.Giftable = settings._feature_Giftable || '';
HangarXPLOR._feature.Meltable = settings._feature_Meltable || '';
HangarXPLOR._feature.Upgraded = settings._feature_Upgraded || '';
HangarXPLOR._feature.Valuable = settings._feature_Valuable || '';
HangarXPLOR._feature.Reward = settings._feature_Reward || '';
HangarXPLOR._feature.Summary = settings._feature_Summary || 'cash';

HangarXPLOR.Log('Loaded Settings', settings);

if (typeof callback === 'function') callback.call(this);
});
}

HangarXPLOR.SaveSettings = function()
{
HangarXPLOR = HangarXPLOR || {};
HangarXPLOR._feature = HangarXPLOR._feature || {};

var settings = settings || {};
settings._type = HangarXPLOR._type || 'All';
settings._sort = HangarXPLOR._sort || 'Purchased';
settings._pageNo = HangarXPLOR._pageNo || 1;
settings._pageCount = HangarXPLOR._pageCount || 10;
settings._logEnabled = HangarXPLOR._logEnabled || false;

settings._feature_LTI = HangarXPLOR._feature.LTI || '';
settings._feature_Warbond = HangarXPLOR._feature.Warbond || '';
settings._feature_Giftable = HangarXPLOR._feature.Giftable || '';
settings._feature_Meltable = HangarXPLOR._feature.Meltable || '';
settings._feature_Upgraded = HangarXPLOR._feature.Upgraded || '';
settings._feature_Valuable = HangarXPLOR._feature.Valuable || '';
settings._feature_Reward = HangarXPLOR._feature.Reward || '';
settings._feature_Summary = HangarXPLOR._feature.Summary || 'cash';

HangarXPLOR.Log('Saved Settings', settings);

chrome.storage.sync.set(settings);
}

HangarXPLOR._shipCount = HangarXPLOR._shipCount || 0;
HangarXPLOR._upgradeCount = HangarXPLOR._upgradeCount || 0;
HangarXPLOR._giftableCount = HangarXPLOR._giftableCount || 0;
HangarXPLOR._packageCount = HangarXPLOR._packageCount || 0;
HangarXPLOR._ltiCount = HangarXPLOR._ltiCount || 0;


var RSI = RSI || {};

HangarXPLOR.Initialize = function()
{
HangarXPLOR.LoadSettings(function() {
Expand All @@ -75,7 +22,15 @@ HangarXPLOR.Initialize = function()
HangarXPLOR.$list = $($lists[0]);
HangarXPLOR.$list.addClass('js-inventory');
$lists = undefined;
HangarXPLOR.LoadPage(1);

HangarXPLOR.UpdateStatus(0);

RSI.Api.Account.pledgeLog((payload) => {
HangarXPLOR._activeHash = payload.data.rendered.length + ':' + payload.data.rendered.substr(39, 20);

HangarXPLOR.LoadCache(HangarXPLOR.LoadPage);
});

} else {
HangarXPLOR.Log('Error locating inventory');
}
Expand Down

0 comments on commit f1259aa

Please sign in to comment.