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 67 additions and 58 deletions

View File

@ -8,13 +8,52 @@
// @name FallenLondon Enhancer
// @namespace https://forge.chapril.org/audrey/
// @require https://forge.chapril.org/audrey/fallen_london_scripts/raw/branch/master/jquery/jquery-3.6.0.min.js
// @version 0.1-rc3
// @version 0.1-rc1
// ==/UserScript==
"use strict";
$(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,57 +61,28 @@ $(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;
}
function update_third_tier_counts() {
const t3_qualities = {
'0' : { id: '525', src: '//images.fallenlondon.com/icons/bookpurplesmall.png' }, // Journal of Infamy
'1' : { id: '932', src: '//images.fallenlondon.com/icons/scrawl1small.png' }, // Correspondence Plaque
'2' : { id: '827', src: '//images.fallenlondon.com/icons/sunsetsmall.png' }, // Vision of the Surface
'3' : { id: '587', src: '//images.fallenlondon.com/icons/mountainglowsmall.png' }, // Mystery of the Elder Continent
'4' : { id: '659', src: '//images.fallenlondon.com/icons/conversationsmall.png' }, // Scrap of Incendiary Gossip
'5' : { id: '825', src: '//images.fallenlondon.com/icons/wakesmall.png' }, // Memory of Distant Shores
'6' : { id: '668', src: '//images.fallenlondon.com/icons/bottledsoulbluesmall.png' }, // Brilliant Soul
'7' : { id: '828', src: '//images.fallenlondon.com/icons/scaryeyesmall.png' }, // A Tale of Terror!!
'8' : { id: '830', src: '//images.fallenlondon.com/icons/papers3small.png' }, // Compromising Document
'9' : { id: '589', src: '//images.fallenlondon.com/icons/mirrorsmall.png' }, // Memory of Light
'A' : { id: '831', src: '//images.fallenlondon.com/icons/waves3small.png' }, // Zee-Ztory
'B' : { id: '822', src: '//images.fallenlondon.com/icons/bottlewillowsmall.png' }, // Bottle of Stranngling Willow Absinthe
'C' : { id: '915', src: '//images.fallenlondon.com/icons/scrap2small.png' }, // Whisper-Satin Scrap
};
$('div#FLE-ccc').remove();
let html = '<div id="FLE-ccc" style="text-align:left;">';
$.each(t3_qualities, function(order, quality) {
let quality_id = quality.id;
let image_src = quality.src;
let elem = $('div [data-quality-id="' + quality_id + '"]');
let quantity = elem.length == 1 ? elem.find('.js-item-value').html() : 0;
html += '<div class="icon icon--inventory" style="margin:1px; margin-bottom:5px;"><img src="' + image_src + '"><span class="icon__value" style="font-size:12px; bottom:-7px; right:-7px; padding:1px 3px; background-color: ' + (quantity > 49 ? '#457c46' : 'black') + ';">' + quantity + '</span></div>';
});
$(html + '</div>').insertAfter('div#FLE-quirks');
}
////////////
// MYSELF //
@ -121,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() {
@ -135,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;
}
@ -181,10 +190,7 @@ function get_advantage() {
function possessions() {
get_advantage();
update_advantage_bar();
update_quirks_bar();
update_contacts_bar();
update_third_tier_counts();
update_bar();
}
@ -222,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
@ -231,18 +244,12 @@ function cleanup() {
}
function display_stats_progress() {
const capped_qualities = ["Dangerous", "Persuasive", "Shadowy", "Watchful"];
$('ul.items--list li.sidebar-quality').each( function( index, element ){
bar = $( this ).find('div.progress-bar');
percent = bar.find('span').prop('style').width.slice(0, -1);
lvl = Number($( this ).find('span.item__value').text());
quality = $( this ).find('span.item__name').text();
target = lvl + 1;
lvl_pts = Math.round(lvl * target / 2);
if (capped_qualities.includes(quality) && target > 70) {
target = 70;
lvl_pts = 2485 + (lvl-70) * 70;
}
CP = Math.round(target * percent / 100);
points = Math.round(lvl_pts + CP);
bar.html( bar.html() + '<span style="color:grey; font-size:75%;">' + points + ' (' + lvl_pts + '+' + CP + '/' + target + ')</span>' );
@ -251,15 +258,13 @@ function display_stats_progress() {
function common() {
// Remove the FL banner to avoid useless scrolling
// cleanup();
cleanup();
// 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) {
@ -276,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;