Skip to content

Commit

Permalink
Feature: Add ability to clear cache via the extension icon
Browse files Browse the repository at this point in the history
Feature: Implement #36 and enable by default
Feature: Implement #26 and disable by default
TODO: Implement UI for #26 and #36
  • Loading branch information
peter-dolkens committed Mar 11, 2021
1 parent 03fe460 commit faff145
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 92 deletions.
21 changes: 20 additions & 1 deletion src/ui_resources/HangarXPLOR.Settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,28 @@
<html>
<head>
<title>HangarXPLOR Settings</title>
<script src="HangarXPLOR.Settings.js"></script>
<style>
body {
width: 300px;
background: url(https://robertsspaceindustries.com/rsi/static/images/gridbg.png) repeat center top,
url(https://robertsspaceindustries.com/rsi/static/images/bg_bengalinterior.jpg) no-repeat top,
url(https://robertsspaceindustries.com/rsi/static/images/noisebg.gif) repeat top;
color: #4ee0ff;
}
</style>
</head>
<body>
<h1>Settings</h1>
<p>Disclaimer: This is really ugly for now. I'm sorry.</p>
<h2>Actions</h2>
<ul>
<!--
<li><input id="noPledgeID" type="checkbox" name="noPledgeID">Hide Pledge ID</input></li>
<li><input id="noPrefix" type="checkbox" name="noPrefix">Hide Pledge Prefix</input></li>
<li><input id="noNickname" type="checkbox" name="noNickname">Hide Nicknames</input></li>
-->
<li><button id="clearCache">Clear Cache</button></li>
</ul>
<script src="HangarXPLOR.Settings.js"></script>
</body>
</html>
12 changes: 10 additions & 2 deletions src/ui_resources/HangarXPLOR.Settings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@

/* eslint no-console: "off" */
console.log('Hi');
document.getElementById('clearCache').addEventListener("click", function(e) {
chrome.storage.sync.get(null, function(settings) {
settings._cacheSalt = btoa(Math.random());

chrome.storage.sync.set(settings, () => {
chrome.tabs.reload();
window.close();
});
});
});
2 changes: 2 additions & 0 deletions src/web_resources/HangarXPLOR.Download.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ HangarXPLOR._callbacks = HangarXPLOR._callbacks || {};
ship.name = $('.title', $ship).text();
ship.name = ship.name.replace(/^\s*(?:Aegis|Anvil|Banu|Drake|Esperia|Kruger|MISC|Origin|RSI|Tumbril|Vanduul|Xi'an)[^a-z0-9]+/gi, '');
ship.name = ship.name.replace(/^\s*(?:Aegis|Anvil|Banu|Drake|Esperia|Kruger|MISC|Origin|RSI|Tumbril|Vanduul|Xi'an)[^a-z0-9]+/gi, '');
ship.nickname = $('.custom-name-text', $ship).text();
ship.lti = pledge.lti;
ship.warbond = pledge.warbond;
ship.package_id = pledge.id;
Expand Down Expand Up @@ -74,6 +75,7 @@ HangarXPLOR._callbacks = HangarXPLOR._callbacks || {};

var $target = $(HangarXPLOR._selected.length > 0 ? HangarXPLOR._selected : HangarXPLOR._inventory);

// TODO: CSV support will need to be careful of user-entered data...
var buffer = "Manufacturer, Ship, Lti, Warbond, ID, Pledge, Cost, Date\n";
buffer = buffer + HangarXPLOR.GetShipList($target).map(function(ship) { return [ '"' + ship.manufacturer + '"', '"' + ship.name + '"', ship.lti, ship.warbond, ship.package_id, '"' + ship.pledge + '"', '"' + ship.cost + '"', '"' + ship.pledge_date + '"' ].join(',')}).join('\n')

Expand Down
1 change: 1 addition & 0 deletions src/web_resources/HangarXPLOR.DrawUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ HangarXPLOR.DrawUI = function()
{ Value: 'IsModel', Text: 'Models', Selected: HangarXPLOR._type == 'IsModel' },
{ Value: 'IsPlant', Text: 'Plants', Selected: HangarXPLOR._type == 'IsPlant' },
{ Value: 'IsPoster', Text: 'Posters', Selected: HangarXPLOR._type == 'IsPoster' },
{ Value: 'IsNameable', Text: 'Nameable', Class: 'split', Selected: HangarXPLOR._type == 'IsNameable' },
], '158px', 'js-custom-filter', function(e, value) { HangarXPLOR._type = value; HangarXPLOR.SaveSettings(); HangarXPLOR.Render(); HangarXPLOR.RefreshPager(); /* HangarXPLOR.ResetBulkUI(); */ }));

$controls1.append(HangarXPLOR.Dropdown([
Expand Down
78 changes: 43 additions & 35 deletions src/web_resources/HangarXPLOR.Filter.js
Original file line number Diff line number Diff line change
@@ -1,106 +1,114 @@

var HangarXPLOR = HangarXPLOR || {};

HangarXPLOR.Filter = function(list, filter)
{
HangarXPLOR.Filter = function (list, filter) {
switch (filter) {
case "HasLTI":
list = $.grep(list, function(item) { return item.hasLTI; });
list = $.grep(list, function (item) { return item.hasLTI });
break;
case "!HasLTI":
list = $.grep(list, function(item) { return !item.hasLTI; });
list = $.grep(list, function (item) { return !item.hasLTI });
break;
case "IsGiftable":
list = $.grep(list, function(item) { return item.isGiftable; });
list = $.grep(list, function (item) { return item.isGiftable });
break;
case "!IsGiftable":
list = $.grep(list, function(item) { return !item.isGiftable; });
list = $.grep(list, function (item) { return !item.isGiftable });
break;
case "IsShip":
list = $.grep(list, function(item) { return item.isShip && !item.isPackage; });
list = $.grep(list, function (item) { return item.isShip && !item.isPackage });
break;
case "HasShip":
list = $.grep(list, function(item) { return item.hasShip; });
list = $.grep(list, function (item) { return item.hasShip });
break;
case "IsNameable":
list = $.grep(list, function (item) { return item.isNameable });
break;
case "HasNickname":
list = $.grep(list, function (item) { return item.hasNickname });
break;
case "!HasNickname":
list = $.grep(list, function (item) { return !item.hasNickname });
break;
case "IsPackage":
list = $.grep(list, function(item) { return item.isPackage; });
list = $.grep(list, function (item) { return item.isPackage });
break;
case "!IsPackage":
list = $.grep(list, function(item) { return !item.isPackage && item.hasShip; });
list = $.grep(list, function (item) { return !item.isPackage && item.hasShip });
break;
case "IsWarbond":
list = $.grep(list, function(item) { return item.isWarbond && (item.hasShip || item.isUpgrade); });
list = $.grep(list, function (item) { return item.isWarbond && (item.hasShip || item.isUpgrade) });
break;
case "!IsWarbond":
list = $.grep(list, function(item) { return !item.isWarbond && (item.hasShip || item.isUpgrade); });
list = $.grep(list, function (item) { return !item.isWarbond && (item.hasShip || item.isUpgrade) });
break;
case "IsCombo":
list = $.grep(list, function(item) { return item.isCombo; });
list = $.grep(list, function (item) { return item.isCombo });
break;
case "IsUpgrade":
list = $.grep(list, function(item) { return item.isUpgrade; });
list = $.grep(list, function (item) { return item.isUpgrade });
break;
case "IsUpgraded":
list = $.grep(list, function(item) { return item.isUpgraded; });
list = $.grep(list, function (item) { return item.isUpgraded });
break;
case "!IsUpgraded":
list = $.grep(list, function(item) { return !item.isUpgraded; });
list = $.grep(list, function (item) { return !item.isUpgraded });
break;
case "IsAddOn":
list = $.grep(list, function(item) { return item.isAddOn; });
list = $.grep(list, function (item) { return item.isAddOn });
break;
case "IsPaint":
list = $.grep(list, function(item) { return item.isPaint; });
list = $.grep(list, function (item) { return item.isPaint });
break;
case "IsExtra":
list = $.grep(list, function(item) { return item.isAddOn || item.isUpgrade; });
list = $.grep(list, function (item) { return item.isAddOn || item.isUpgrade });
break;
case "IsFlair":
list = $.grep(list, function(item) { return item.isFlair; });
list = $.grep(list, function (item) { return item.isFlair });
break;
case "HasValue":
list = $.grep(list, function(item) { return item.hasValue; });
list = $.grep(list, function (item) { return item.hasValue });
break;
case "!HasValue":
list = $.grep(list, function(item) { return !item.hasValue; });
list = $.grep(list, function (item) { return !item.hasValue });
break;
case "IsMeltable":
list = $.grep(list, function(item) { return item.isMeltable; });
list = $.grep(list, function (item) { return item.isMeltable });
break;
case "!IsMeltable":
list = $.grep(list, function(item) { return !item.isMeltable; });
list = $.grep(list, function (item) { return !item.isMeltable });
break;
case "IsModel":
list = $.grep(list, function(item) { return item.isModel; });
list = $.grep(list, function (item) { return item.isModel });
break;
case "IsPoster":
list = $.grep(list, function(item) { return item.isPoster; });
list = $.grep(list, function (item) { return item.isPoster });
break;
case "IsPlant":
list = $.grep(list, function(item) { return item.isSpacePlant; });
list = $.grep(list, function (item) { return item.isSpacePlant });
break;
case "IsDecoration":
list = $.grep(list, function(item) { return item.isDecoration; });
list = $.grep(list, function (item) { return item.isDecoration });
break;
case "IsComponent":
list = $.grep(list, function(item) { return item.isComponent; });
list = $.grep(list, function (item) { return item.isComponent });
break;
case "IsReward":
list = $.grep(list, function(item) { return item.isReward; });
list = $.grep(list, function (item) { return item.isReward });
break;
case "!IsReward":
list = $.grep(list, function(item) { return !item.isReward; });
list = $.grep(list, function (item) { return !item.isReward });
break;
case "IsSelected":
list = $.grep(list, function(item) { return item.isSelected; });
list = $.grep(list, function (item) { return item.isSelected });
break;
case "IsFreeCCU":
list = $.grep(list, function(item) { return item.isUpgrade && !item.hasValue; });
list = $.grep(list, function (item) { return item.isUpgrade && !item.hasValue });
break;
case "!IsFreeCCU":
list = $.grep(list, function(item) { return !item.isUpgrade || item.hasValue; });
list = $.grep(list, function (item) { return !item.isUpgrade || item.hasValue });
break;
}

return list;
}
39 changes: 22 additions & 17 deletions src/web_resources/HangarXPLOR.LoadSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,29 @@ 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._cacheHash = settings._cacheHash || 0;
HangarXPLOR._cacheSalt = settings._cacheSalt || btoa(Math.random());
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._cacheHash = settings._cacheHash || 0;
HangarXPLOR._cacheSalt = settings._cacheSalt || btoa(Math.random());

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 = 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._setting = HangarXPLOR._setting || {};
HangarXPLOR._setting.NoPledgeID = settings._setting_NoPledgeID || false;
HangarXPLOR._setting.NoPrefix = settings._setting_NoPrefix || false;
HangarXPLOR._setting.NoNickname = settings._setting_NoNickname || false;

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

Expand Down
Loading

0 comments on commit faff145

Please sign in to comment.