attempt: fixed trash data being loaded anyway

This commit is contained in:
buzz-lightsnack-2007 2024-05-07 11:50:53 +08:00
parent 2a4e60420d
commit 44f0bf9420

View file

@ -35,13 +35,15 @@ class Page_Results extends Page {
// Set the reference website when overriding or unset. // Set the reference website when overriding or unset.
if (override || !this[`ref`]) {this[`ref`] = await global.read([`last`])}; if (override || !this[`ref`]) {this[`ref`] = await global.read([`last`])};
// Get all the data. if (this[`ref`]) {
let DATA = { // Get all the data.
"data": await global.read([`sites`, this[`ref`]]) let DATA = {
} "data": await global.read([`sites`, this[`ref`]])
}
// Set the data.
this[`data`] = (DATA[`data`]) ? DATA[`data`] : (this[`data`] ? this[`data`] : {}); // Set the data.
this[`data`] = (DATA[`data`] && (typeof DATA[`data`]).includes(`obj`)) ? DATA[`data`] : (this[`data`] ? this[`data`] : {});
}
} }
async content() { async content() {
@ -78,59 +80,63 @@ class Page_Results extends Page {
Populate the contents. Populate the contents.
*/ */
async fill() { async fill() {
(this.elements) if (this.data) {
? (Object.keys(this.elements)).forEach(async (SOURCE) => { (this.elements)
if (SOURCE.indexOf(`*`) < SOURCE.length - 1) { ? (Object.keys(this.elements)).forEach(async (SOURCE) => {
let DATA = (nested.dictionary.get(this[`data`][`analysis`], SOURCE)); if (SOURCE.indexOf(`*`) < SOURCE.length - 1) {
let DATA = (nested.dictionary.get(this[`data`][`analysis`], SOURCE));
this.elements[SOURCE][(this.elements[SOURCE].nodeName.toLowerCase().includes(`input`) || this.elements[SOURCE].nodeName.toLowerCase().includes(`progress`)) ? `value` : `innerHTML`] = (DATA)
? (((typeof DATA).includes(`obj`) && !Array.isArray(DATA)) this.elements[SOURCE][(this.elements[SOURCE].nodeName.toLowerCase().includes(`input`) || this.elements[SOURCE].nodeName.toLowerCase().includes(`progress`)) ? `value` : `innerHTML`] = (DATA)
? JSON.stringify(DATA) ? (((typeof DATA).includes(`obj`) && !Array.isArray(DATA))
: String(DATA)) ? JSON.stringify(DATA)
: null; : String(DATA))
} else if (SOURCE.indexOf(`*`) >= SOURCE.length - 1) { : null;
let DATA = (nested.dictionary.get(this[`data`][`analysis`], SOURCE.split(`,`).slice(0, -1))); } else if (SOURCE.indexOf(`*`) >= SOURCE.length - 1) {
let DATA = (nested.dictionary.get(this[`data`][`analysis`], SOURCE.split(`,`).slice(0, -1)));
(!Array.isArray(DATA) && (typeof DATA).includes(`obj`) && DATA != null)
(!Array.isArray(DATA) && (typeof DATA).includes(`obj`) && DATA != null)
let ELEMENT_TYPES = {
"container": "section", let ELEMENT_TYPES = {
"content": "article", "container": "section",
"title": "p", "content": "article",
"body": "p" "title": "p",
}; "body": "p"
};
(Object.keys(DATA)).forEach((ITEM) => {
let ELEMENTS = {}; (DATA)
? (Object.keys(DATA)).forEach((ITEM) => {
// Create the elements. let ELEMENTS = {};
(Object.keys(ELEMENT_TYPES)).forEach((TYPE) => {
ELEMENTS[TYPE] = document.createElement(ELEMENT_TYPES[TYPE]); // Create the elements.
(Object.keys(ELEMENT_TYPES)).forEach((TYPE) => {
(([`content`, `action`, `title`].includes(TYPE) || TYPE.includes(`container`)) && this.elements[SOURCE][`target element type`]) ELEMENTS[TYPE] = document.createElement(ELEMENT_TYPES[TYPE]);
? ELEMENTS[TYPE].classList.add(this.elements[SOURCE][`target element type`].concat((!TYPE.includes(`container`))
? `-${TYPE}` (([`content`, `action`, `title`].includes(TYPE) || TYPE.includes(`container`)) && this.elements[SOURCE][`target element type`])
: ``)) ? ELEMENTS[TYPE].classList.add(this.elements[SOURCE][`target element type`].concat((!TYPE.includes(`container`))
: false; ? `-${TYPE}`
}); : ``))
: false;
ELEMENTS[`title`].innerText = String(ITEM).trim(); });
ELEMENTS[`title`].classList.add(`flow-text`);
ELEMENTS[`body`].innerText = String(DATA[ITEM]).trim(); ELEMENTS[`title`].innerText = String(ITEM).trim();
ELEMENTS[`title`].classList.add(`flow-text`);
// Inject the elements. ELEMENTS[`body`].innerText = String(DATA[ITEM]).trim();
[`title`, `body`].forEach((CONTENT) => {
ELEMENTS[`content`].appendChild(ELEMENTS[CONTENT]); // Inject the elements.
}); [`title`, `body`].forEach((CONTENT) => {
ELEMENTS[`container`].appendChild(ELEMENTS[`content`]); ELEMENTS[`content`].appendChild(ELEMENTS[CONTENT]);
this.elements[SOURCE].appendChild(ELEMENTS[`container`]); });
}) ELEMENTS[`container`].appendChild(ELEMENTS[`content`]);
} this.elements[SOURCE].appendChild(ELEMENTS[`container`]);
}) })
: false; : false
}
// Set the color. })
(nested.dictionary.get(this[`data`][`analysis`], [`Rating`, `Trust`]) && document.querySelector(`summary`)) ? document.querySelector(`summary`).setAttribute(`result`, (nested.dictionary.get(this[`data`][`analysis`], [`Rating`, `Trust`]))) : false; : false;
// Set the color.
(nested.dictionary.get(this[`data`][`analysis`], [`Rating`, `Trust`]) && document.querySelector(`summary`)) ? document.querySelector(`summary`).setAttribute(`result`, (nested.dictionary.get(this[`data`][`analysis`], [`Rating`, `Trust`]))) : false;
}
}; };
} }