Compare commits

...

2 Commits
master ... dev

Author SHA1 Message Date
Audrey 456a085675 Displaying airs 2021-09-07 20:08:55 +02:00
Audrey 094c189d23 jQuery rewrite 2021-09-06 20:20:28 +02:00
1 changed files with 65 additions and 22 deletions

View File

@ -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 = '<div id="FLE-airs" style="text-align:left;">';
$.each(quirks, function( key, value ) {
html += '<div class="icon icon--inventory" style="margin:1px; margin-bottom:5px;"><img src="' + value.img + '"><span class="icon__value" style="font-size:12px; bottom:-7px; right:-7px; padding:1px 3px;">' + value.num + '</span></div>';
});
$('div#FLE-airs').remove();
$(html + '</div>').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 //
////////////
@ -22,26 +61,24 @@ $(document).ready(fl_enhancer);
let items_total_value_displayed = false;
function display_items_total_value() {
// If anyone spams the "bazaar" link
// Prevents multiple display if spamming the "bazaar" link
if (items_total_value_displayed) {
return;
}
// Only computing the sum if all items are displayed
let shop = document.getElementsByClassName('menu-item--active');
if ( shop.length && shop[0].textContent != "Sell my things") {
let shop = $('button.menu-item--active')
if (shop.length && shop.text() != "Sell my things") {
return;
}
let total_price = 0;
for (let item of window.document.getElementsByClassName('shop__item')) {
let num_object = item.getElementsByClassName('js-item-value');
let price_object = item.getElementsByClassName('item__price');
if (price_object.length && num_object.length) {
let num = num_object[0].textContent;
let price = price_object[0].textContent;
total_price += ( num * price);
}
}
$('li.shop__item').each( function( index, element ){
total_price = (
$( this ).find('span.js-item-value').text() * // Number of items
$( this ).find('div.item__price').text() // Price
);
});
$('.input--item-search').after('<li class="shop__item js-item item "><div class="item__desc"><span class="js-item-name item__name">Total value:</span> <div class="price item__price">' + total_price + '</div></div></li>');
items_total_value_displayed = true;
}
@ -94,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() {
@ -108,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;
}
@ -154,9 +190,7 @@ function get_advantage() {
function possessions() {
get_advantage();
update_advantage_bar();
update_quirks_bar();
update_contacts_bar();
update_bar();
}
@ -194,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
@ -222,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) {
@ -242,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;