diff --git a/index.html b/index.html
new file mode 100644
index 0000000..bf42c2d
--- /dev/null
+++ b/index.html
@@ -0,0 +1,16 @@
+
+
+
+
+ Locations - Idealista Enhancer
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/locations/AragüésdelPuerto.json b/locations/AragüésdelPuerto.json
new file mode 100644
index 0000000..a96843d
--- /dev/null
+++ b/locations/AragüésdelPuerto.json
@@ -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
+}
\ No newline at end of file
diff --git a/locations/Liédena.json b/locations/Liédena.json
new file mode 100644
index 0000000..5c4253a
--- /dev/null
+++ b/locations/Liédena.json
@@ -0,0 +1,11 @@
+{
+ "name": "Liédena",
+ "altitude": 432,
+ "bus": true,
+ "train": false,
+ "pharmacy": true,
+ "smoke": true,
+ "supermarkets": [],
+ "pool": true,
+ "gym": true
+}
\ No newline at end of file
diff --git a/locations/PuentelaReinadeJaca.json b/locations/PuentelaReinadeJaca.json
new file mode 100644
index 0000000..19d229d
--- /dev/null
+++ b/locations/PuentelaReinadeJaca.json
@@ -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
+}
\ No newline at end of file
diff --git a/locations/SanJuandePlan.json b/locations/SanJuandePlan.json
new file mode 100644
index 0000000..fdc43c1
--- /dev/null
+++ b/locations/SanJuandePlan.json
@@ -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
+}
\ No newline at end of file
diff --git a/src/ItemHTML.js b/src/ItemHTML.js
index 1498d9e..c461cf3 100644
--- a/src/ItemHTML.js
+++ b/src/ItemHTML.js
@@ -60,7 +60,7 @@ export default class ItemHTML {
html += ``;
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);
diff --git a/src/LocationStorage.js b/src/LocationStorage.js
new file mode 100644
index 0000000..7095e52
--- /dev/null
+++ b/src/LocationStorage.js
@@ -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);
+ }
+
+}
\ No newline at end of file
diff --git a/src/Locations.js b/src/Locations.js
index 7481545..50a79f2 100644
--- a/src/Locations.js
+++ b/src/Locations.js
@@ -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;
}
}
\ No newline at end of file
diff --git a/src/Menu.js b/src/Menu.js
index 9daa548..a6de7e8 100644
--- a/src/Menu.js
+++ b/src/Menu.js
@@ -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();
diff --git a/src/MenuHTML.js b/src/MenuHTML.js
index 95520e2..1d726e0 100644
--- a/src/MenuHTML.js
+++ b/src/MenuHTML.js
@@ -16,9 +16,24 @@ export default class MenuHTML {
static create() {
return `
-
-
+ ${this._openConfigButton()}
+ ${this._refreshDataButton()}
`;
}
+ static createSimple() {
+ return `
+
+ ${this._openConfigButton()}
+
`;
+ }
+
+ static _openConfigButton() {
+ return `
`;
+ }
+
+ static _refreshDataButton() {
+ return `
`
+ }
+
}
\ No newline at end of file
diff --git a/src/Styles.js b/src/Styles.js
index eb4b1c1..ae6d9e2 100644
--- a/src/Styles.js
+++ b/src/Styles.js
@@ -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,