Differente menus.

Adding LocationStorage to do make a lot of calls to GitHub.
Better DarkMode.
This commit is contained in:
Jorge Bolois Guerrero 2022-10-30 13:40:24 +01:00
parent 4ee68ed298
commit fa8a62053f
11 changed files with 176 additions and 9 deletions

16
index.html Normal file
View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>Locations - Idealista Enhancer</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</head>
<body>
<!-- TODO: Please integrate a way to add/update/remove locations from a GUI. -->
</body>
</html>

View File

@ -0,0 +1,14 @@
{
"name": "Aragüés del Puerto",
"altitude": 970,
"bus": false,
"train": false,
"pharmacy": true,
"smoke": false,
"supermarkets": [{
"type": "CUSTOM",
"url": "https://goo.gl/maps/8Qukf8FzqMYXkhPt8"
}],
"pool": false,
"gym": false
}

11
locations/Liédena.json Normal file
View File

@ -0,0 +1,11 @@
{
"name": "Liédena",
"altitude": 432,
"bus": true,
"train": false,
"pharmacy": true,
"smoke": true,
"supermarkets": [],
"pool": true,
"gym": true
}

View File

@ -0,0 +1,16 @@
{
"name": "Puente la Reina de Jaca",
"altitude": 707,
"bus": true,
"train": false,
"pharmacy": true,
"smoke": false,
"supermarkets": [
{
"type": "CUSTOM",
"url": "https://goo.gl/maps/ioeCNKvhrsgn42gu5"
}
],
"pool": false,
"gym": false
}

View File

@ -0,0 +1,20 @@
{
"name": "San Juan de Plan",
"altitude": 1120,
"bus": false,
"train": false,
"pharmacy": false,
"smoke": false,
"supermarkets": [
{
"type": "SUMA",
"url": "https://goo.gl/maps/gfyi26FV6iw3QS5E9"
},
{
"type": "SIMPLY",
"url": "https://goo.gl/maps/SsQPLC2XzAwWX5gw8"
}
],
"pool": false,
"gym": false
}

View File

@ -60,7 +60,7 @@ export default class ItemHTML {
html += `<div class='${this.INFORMATION_CONTAINER_CLASS_NAME}'>`;
html += this._createLocationName(item);
if (item.location && item.location.name) {
if (item.location && !item.location.errorMessage) {
html += this._createLocationTrain(item);
html += this._createLocationBus(item);
html += this._createLocationGym(item);

43
src/LocationStorage.js Normal file
View File

@ -0,0 +1,43 @@
import Log from "./Log.js";
export default class LocationStorage {
static KEY = 'midefos-idealista-location-storage';
static get storage() {
return window.localStorage;
}
static get data() {
if (!this._data) {
this._init();
}
return JSON.parse(this._data);
}
static get _data() {
return this.storage.getItem(this.key);
}
static get(name) {
const locations = this.data;
return locations[name];
}
static save(location) {
const locations = this.data;
locations[location.name] = location;
this._save(locations);
}
static _init() {
Log.debug(`Init location storage`);
this._save({});
}
static _save(data) {
const json = JSON.stringify(data);
this.storage.setItem(this.key, json);
}
}

View File

@ -1,18 +1,29 @@
import Location from './Location.js';
import LocationStorage from './LocationStorage.js';
import Log from './Log.js';
export default class Locations {
static async get(name) {
const storageLocation = LocationStorage.get(name)
if (storageLocation) {
return storageLocation;
}
const response = await fetch(`https://raw.githubusercontent.com/Midefos/idealista-enhancer/main/locations/${name}.json`);
Log.debug(`Requested location '${name}'`);
if (response.status == 404) {
Log.debug(`Missing information for location: '${name}'`);
return { errorMessage: 'Datos no disponibles...' };
const errorLocation = { name: name, errorMessage: 'Datos no disponibles...' };
LocationStorage.save(errorLocation);
return errorLocation;
}
const data = await response.json();
return Location.fromRaw(data);
const location = Location.fromRaw(data);
LocationStorage.save(location);
return location;
}
}

View File

@ -6,15 +6,35 @@ import MenuHTML from "./MenuHTML.js";
export default class Menu {
static LIST_SELECTOR = '#main-content';
static OTHER_LOCATIONS_SELECTORS = `#side-content,
.home-boxes-container.new-home`;
constructor() {
if (this._shouldNotLoad()) return;
const mainContent = document.querySelector('#main-content, #side-content');
mainContent.innerHTML = MenuHTML.create() + mainContent.innerHTML;
this._createMenu();
this._initEvents();
}
_createMenu() {
const listNode = document.querySelector(Menu.LIST_SELECTOR);
if (listNode) {
listNode.innerHTML = MenuHTML.create() + listNode.innerHTML;
} else {
this._createSimpleMenu();
}
}
_createSimpleMenu() {
const locationNode = document.querySelector(Menu.OTHER_LOCATIONS_SELECTORS);
if (locationNode) {
locationNode.innerHTML = MenuHTML.createSimple() + locationNode.innerHTML;
}
}
_initEvents() {
Event.click(MenuHTML.RELOAD_INFORMATION_SELECTOR, () => {
Information.create();

View File

@ -16,9 +16,24 @@ export default class MenuHTML {
static create() {
return `
<div class='${this.CONTAINER_CLASS_NAME}'>
<button class='${ButtonClass.IDEALISTA_BUTTON_CLASS} ${ConfigurationHTML.OPEN_CONFIG_CLASS_NAME}' title='Abrir configuración'> Configuración</button>
<button class='${ButtonClass.IDEALISTA_BUTTON_CLASS} ${this.RELOAD_INFORMATION_CLASS_NAME}' title='Refrescar información'> Refrescar</button>
${this._openConfigButton()}
${this._refreshDataButton()}
</div>`;
}
static createSimple() {
return `
<div class='${this.CONTAINER_CLASS_NAME}'>
${this._openConfigButton()}
</div>`;
}
static _openConfigButton() {
return `<button class='${ButtonClass.IDEALISTA_BUTTON_CLASS} ${ConfigurationHTML.OPEN_CONFIG_CLASS_NAME}' title='Abrir configuración'>⚙ Configuración</button>`;
}
static _refreshDataButton() {
return `<button class='${ButtonClass.IDEALISTA_BUTTON_CLASS} ${this.RELOAD_INFORMATION_CLASS_NAME}' title='Refrescar información'>⟳ Refrescar</button>`
}
}

View File

@ -131,7 +131,8 @@ export default class Styles {
.pagination li a,
.btn.regular,
.dropdown-wrapper, .dropdown-wrapper .dropdown,
.new-radio-button input:checked + label,
.new-radio-button input:checked + label, .new-radio-button label,
.new-search-box #campoBus, .result-list, .text-image-component_texts,
.rs-light-adcard_info,
.sticky-bar-detail,
.home,