From 456a085675f65f244806c14e083240d6d7c65e40 Mon Sep 17 00:00:00 2001 From: Audrey Date: Mon, 6 Sep 2021 22:50:59 +0200 Subject: [PATCH] Displaying airs --- FL_enhancer.user.js | 65 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/FL_enhancer.user.js b/FL_enhancer.user.js index 4b532b4..2b3010d 100644 --- a/FL_enhancer.user.js +++ b/FL_enhancer.user.js @@ -15,6 +15,45 @@ $(document).ready(fl_enhancer); +/////////// +// STORY // +/////////// + +function update_airs_bar() { + if (!localStorage.FLE_airs) { + return; + } + let quirks = JSON.parse(localStorage.FLE_airs); + let html = '
'; + $.each(quirks, function( key, value ) { + html += '
' + value.num + '
'; + }); + $('div#FLE-airs').remove(); + $(html + '
').insertAfter('button.travel-button--infobar'); +} + +function get_airs_value() { + let updated = false; + let airs = {} + if (localStorage.FLE_airs) { + airs = JSON.parse(localStorage.FLE_airs); + } + // Airs from a Location (storylet requirement) + let airs_unlock = $('[alt^="You unlocked this with The Airs"]').first(); + if (airs_unlock.length) { + console.log('airs detected'); + let [_, txt, num] = airs_unlock.attr('alt').match(/You unlocked this with (The Airs.*?)(\d+)/); + if (!airs[txt]) { + airs[txt] = { 'num': num, 'img': airs_unlock.attr('src') }; + } + updated = true; + } + + if (updated) { + localStorage.setItem('FLE_airs', JSON.stringify(airs)); + } +} + //////////// // BAZAAR // //////////// @@ -92,11 +131,10 @@ function get_quirks() { let found = $( this ).find('span').prop('textContent').match(/(\w+)\s+(\d+)/); if (found){ let [_, quirk, num] = found; - quirks[quirk] = {'num': num, img: $( this).find('img').prop('src')}; + quirks[quirk] = {'num': num, 'img': $( this).find('img').prop('src')}; } }); localStorage.setItem('FLE_quirks', JSON.stringify(quirks)); - update_quirks_bar(); } function get_contacts() { @@ -106,7 +144,7 @@ function get_contacts() { if (found) { let [_, type, faction, num] = found; if (!contacts[faction]) { - contacts[faction] = {'Renown': 0, 'Favours': 0, img: $( this).find('img').prop('src')}; + contacts[faction] = {'Renown': 0, 'Favours': 0, 'img': $( this).find('img').prop('src')}; } contacts[faction][type] = num; } @@ -152,9 +190,7 @@ function get_advantage() { function possessions() { get_advantage(); - update_advantage_bar(); - update_quirks_bar(); - update_contacts_bar(); + update_bar(); } @@ -192,6 +228,13 @@ function monitor_url_change() { // GLOBAL // //////////// +function update_bar() { + update_airs_bar(); + update_advantage_bar(); + update_quirks_bar(); + update_contacts_bar(); +} + function cleanup() { // Remove the banner @@ -220,10 +263,8 @@ function common() { // Display CP and number of points required for the next level near the progress bar display_stats_progress(); - // Display contacts & quirks in the sidebar - update_advantage_bar(); - update_quirks_bar(); - update_contacts_bar(); + // Display contacts, quirks, possessions & airs in the sidebar + update_bar(); } function sleep(ms) { @@ -240,6 +281,10 @@ function go() { items_total_value_displayed = false; } switch (url) { + case 'https://www.fallenlondon.com/': + get_airs_value(); + update_bar(); + break; case 'https://www.fallenlondon.com/bazaar': display_items_total_value(); break;