2021-08-29 10:51:49 +02:00
|
|
|
|
// ==UserScript==
|
|
|
|
|
// @author Audrey
|
|
|
|
|
// @description Helper script for Fallenlondon
|
|
|
|
|
// @downloadURL https://forge.chapril.org/audrey/fallen_london_scripts/raw/branch/master/FL_enhancer.user.js
|
|
|
|
|
// @grant none
|
|
|
|
|
// @icon https://images.fallenlondon.com/favicons/favicon.ico
|
|
|
|
|
// @match https://www.fallenlondon.com/*
|
|
|
|
|
// @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
|
2021-09-16 15:40:06 +02:00
|
|
|
|
// @version 0.1-rc2
|
2021-08-29 10:51:49 +02:00
|
|
|
|
// ==/UserScript==
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
$(document).ready(fl_enhancer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////
|
|
|
|
|
// BAZAAR //
|
|
|
|
|
////////////
|
|
|
|
|
|
|
|
|
|
let items_total_value_displayed = false;
|
|
|
|
|
|
|
|
|
|
function display_items_total_value() {
|
|
|
|
|
// If anyone spams 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") {
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$('.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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////
|
|
|
|
|
// MYSELF //
|
|
|
|
|
////////////
|
|
|
|
|
|
|
|
|
|
function update_quirks_bar() {
|
|
|
|
|
if (!localStorage.FLE_quirks) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let quirks = JSON.parse(localStorage.FLE_quirks);
|
|
|
|
|
let html = '<div id="FLE-quirks" 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; background-color: #457c46;">' + value.num + '</span></div>';
|
|
|
|
|
});
|
|
|
|
|
$('div#FLE-quirks').remove();
|
|
|
|
|
$(html + '</div>').insertAfter('button.travel-button--infobar');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function update_contacts_bar() {
|
|
|
|
|
if (!localStorage.FLE_contacts) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let icon_value_color = {
|
|
|
|
|
'0': '',
|
|
|
|
|
'1': '',
|
|
|
|
|
'2': '',
|
|
|
|
|
'3': '',
|
|
|
|
|
'4': '',
|
|
|
|
|
'5': 'background-color: rgb(180, 140, 0);',
|
|
|
|
|
'6': 'background-color: rgb(190, 110, 23);',
|
|
|
|
|
'7': 'background-color: rgb(183, 70, 5);',
|
|
|
|
|
};
|
|
|
|
|
let contacts = JSON.parse(localStorage.FLE_contacts);
|
|
|
|
|
let html = '<div id="FLE-contacts" style="text-align:left;">';
|
|
|
|
|
let z_index = 0;
|
|
|
|
|
$.each(contacts, function( key, value ) {
|
|
|
|
|
html += '<div class="icon icon--inventory" style="margin:1px; margin-bottom:5px; z-index:' + z_index-- + ';"><img src="' + value.img + '"><span class="icon__value" style="font-size:12px; bottom:-7px; right:-7px; padding:1px 3px;' + icon_value_color[value.Favours] + '">' + value.Renown + '+' + value.Favours + '</span></div>';
|
|
|
|
|
});
|
|
|
|
|
$('div#FLE-contacts').remove();
|
|
|
|
|
$(html + '</div>').insertAfter('button.travel-button--infobar');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function get_quirks() {
|
|
|
|
|
let quirks = {}
|
|
|
|
|
$("[data-group-name=Quirks] li.quality-item").each( function( index, element ){
|
|
|
|
|
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')};
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
localStorage.setItem('FLE_quirks', JSON.stringify(quirks));
|
|
|
|
|
update_quirks_bar();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function get_contacts() {
|
|
|
|
|
let contacts = {}
|
|
|
|
|
$("[data-group-name=Contacts] li.quality-item").each( function( index, element ){
|
|
|
|
|
let found = $( this ).find('span').prop('textContent').match(/(:?Favours|Renown): (.*) (\d+)\/\d+/);
|
|
|
|
|
if (found) {
|
|
|
|
|
let [_, type, faction, num] = found;
|
|
|
|
|
if (!contacts[faction]) {
|
|
|
|
|
contacts[faction] = {'Renown': 0, 'Favours': 0, img: $( this).find('img').prop('src')};
|
|
|
|
|
}
|
|
|
|
|
contacts[faction][type] = num;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
localStorage.setItem('FLE_contacts', JSON.stringify(contacts));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function myself() {
|
|
|
|
|
get_quirks();
|
|
|
|
|
update_quirks_bar();
|
|
|
|
|
get_contacts();
|
|
|
|
|
update_contacts_bar();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////
|
|
|
|
|
// POSSESSIONS //
|
|
|
|
|
/////////////////
|
|
|
|
|
|
|
|
|
|
function update_advantage_bar() {
|
|
|
|
|
if (!localStorage.FLE_advantage) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let advantage = JSON.parse(localStorage.FLE_advantage);
|
|
|
|
|
let html = '<div id="FLE-advantage" style="text-align:left;">';
|
|
|
|
|
$.each(advantage, function( key, value ) {
|
|
|
|
|
html += '<div class="icon icon--inventory" style="margin:1px; margin-bottom:5px;"><img src="' + key + '"><span class="icon__value" style="font-size:12px; bottom:-7px; right:-7px; padding:1px 3px;">' + value + '</span></div>';
|
|
|
|
|
});
|
|
|
|
|
$('div#FLE-advantage').remove();
|
|
|
|
|
$(html + '</div>').insertAfter('button.travel-button--infobar');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function get_advantage() {
|
|
|
|
|
let advantage = {};
|
|
|
|
|
$("[data-group-name=Advantage] li.item img").each( function( index, element ){
|
|
|
|
|
let found = $( this ).prop('alt').match(/× (\d+);/);
|
|
|
|
|
if (found) {
|
|
|
|
|
advantage[$( this ).prop('src')] = found[1];
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
localStorage.setItem('FLE_advantage', JSON.stringify(advantage));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function possessions() {
|
|
|
|
|
get_advantage();
|
|
|
|
|
update_advantage_bar();
|
|
|
|
|
update_quirks_bar();
|
|
|
|
|
update_contacts_bar();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function monitor_url_change() {
|
|
|
|
|
|
|
|
|
|
// https://dirask.com/posts/JavaScript-on-location-changed-event-on-url-changed-event-DKeyZj
|
|
|
|
|
// If the url is updated ...
|
|
|
|
|
;(function() {
|
|
|
|
|
let pushState = history.pushState;
|
|
|
|
|
let replaceState = history.replaceState;
|
|
|
|
|
|
|
|
|
|
history.pushState = function() {
|
|
|
|
|
pushState.apply(history, arguments);
|
|
|
|
|
window.dispatchEvent(new Event('pushstate'));
|
|
|
|
|
window.dispatchEvent(new Event('locationchange'));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
history.replaceState = function() {
|
|
|
|
|
replaceState.apply(history, arguments);
|
|
|
|
|
window.dispatchEvent(new Event('replacestate'));
|
|
|
|
|
window.dispatchEvent(new Event('locationchange'));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.addEventListener('popstate', function() {
|
|
|
|
|
window.dispatchEvent(new Event('locationchange'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////
|
|
|
|
|
// GLOBAL //
|
|
|
|
|
////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function cleanup() {
|
|
|
|
|
// Remove the banner
|
|
|
|
|
$('div.banner').remove();
|
|
|
|
|
// Remove the candles
|
|
|
|
|
$('div.candle-container').remove();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function display_stats_progress() {
|
2021-09-16 15:40:06 +02:00
|
|
|
|
const capped_qualities = ["Dangerous", "Persuasive", "Shadowy", "Watchful"];
|
2021-08-29 10:51:49 +02:00
|
|
|
|
$('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());
|
2021-09-16 15:40:06 +02:00
|
|
|
|
quality = $( this ).find('span.item__name').text();
|
2021-08-29 10:51:49 +02:00
|
|
|
|
target = lvl + 1;
|
|
|
|
|
lvl_pts = Math.round(lvl * target / 2);
|
2021-09-16 15:40:06 +02:00
|
|
|
|
if (capped_qualities.includes(quality) && target > 70) {
|
|
|
|
|
target = 70;
|
|
|
|
|
lvl_pts = 2485 + (lvl-70) * 70;
|
|
|
|
|
}
|
2021-08-29 10:51:49 +02:00
|
|
|
|
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>' );
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function common() {
|
|
|
|
|
// Remove the FL banner to avoid useless scrolling
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function sleep(ms) {
|
|
|
|
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function go() {
|
|
|
|
|
// Always done regardless of the location
|
|
|
|
|
common();
|
|
|
|
|
|
|
|
|
|
// Actions specific to some locations
|
|
|
|
|
url = window.location.toString();
|
|
|
|
|
if (url != 'https://www.fallenlondon.com/bazaar') {
|
|
|
|
|
items_total_value_displayed = false;
|
|
|
|
|
}
|
|
|
|
|
switch (url) {
|
|
|
|
|
case 'https://www.fallenlondon.com/bazaar':
|
|
|
|
|
display_items_total_value();
|
|
|
|
|
break;
|
|
|
|
|
case 'https://www.fallenlondon.com/possessions':
|
|
|
|
|
possessions();
|
|
|
|
|
break;
|
|
|
|
|
case 'https://www.fallenlondon.com/myself':
|
|
|
|
|
myself();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
console.log('');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function fl_enhancer() {
|
|
|
|
|
|
|
|
|
|
// On page load (by the browser)
|
|
|
|
|
await sleep(3600);
|
|
|
|
|
go();
|
|
|
|
|
|
|
|
|
|
// When the url is updated by js
|
|
|
|
|
monitor_url_change();
|
|
|
|
|
window.addEventListener('locationchange', async function(){
|
|
|
|
|
await sleep(2);
|
|
|
|
|
go();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|