From 8068c47cc237aaf19e94ad36fa6ffc2066c448e4 Mon Sep 17 00:00:00 2001 From: unlishema Date: Wed, 1 Oct 2025 20:03:09 -0400 Subject: [PATCH] Updated more for testing. --- dist/.htaccess | 2 +- dist/dev.html | 123 +++++++------------------------------------ src/.htaccess | 2 +- src/dev.html | 123 +++++++------------------------------------ src/index.ts | 2 +- src/modules/query.ts | 2 +- 6 files changed, 42 insertions(+), 212 deletions(-) diff --git a/dist/.htaccess b/dist/.htaccess index ea4f9f2..0110fd8 100644 --- a/dist/.htaccess +++ b/dist/.htaccess @@ -36,7 +36,7 @@ Options -Indexes Header set X-XSS-Protection "1; mode=block" Header set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" Header set Referrer-Policy "strict-origin-when-cross-origin" - Header set Content-Security-Policy "default-src 'self' https://runescape.wiki https://oldschool.runescape.wiki; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://oldschool.runescape.wiki; font-src 'self'; frame-ancestors http://unlishema.local https://unlishema.org https://*.unlishema.org" + Header set Content-Security-Policy "default-src 'self' https://runescape.wiki https://oldschool.runescape.wiki; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://runescape.wiki https://oldschool.runescape.wiki; font-src 'self'; frame-ancestors http://unlishema.local https://unlishema.org https://*.unlishema.org" Header set Permissions-Policy "geolocation=(), microphone=(), camera=()" # Set the Host header to ensure requests target slayer.unlishema.org diff --git a/dist/dev.html b/dist/dev.html index 665b5c3..169c688 100644 --- a/dist/dev.html +++ b/dist/dev.html @@ -129,11 +129,11 @@ - +
+ value="bucket('infobox_item').select('item_name','image','examine').limit(20).offset(0).run()">


@@ -172,11 +172,11 @@ - +
+ value="bucket('infobox_item').select('item_name','image','examine').limit(20).offset(0).run()">


@@ -210,7 +210,7 @@ document.addEventListener("DOMContentLoaded", async () => { // Populate the RS3 combobox with some default items const defaultItemsRS3 = [ - { name: "Items", query: "bucket('infobox_item').select('item_name','item_id','examine').limit(20).offset(0).run()" }, + { name: "Items", query: "bucket('infobox_item').select('item_name','image','examine').limit(20).offset(0).run()" }, { name: "Monsters", query: "bucket('infobox_monster').select('name', 'examine').limit(20).offset(0).run()" }, { name: "Locations", query: "bucket('infobox_location').select('page_name', 'is_members_only').limit(20).offset(0).run()" }, ]; @@ -218,12 +218,14 @@ // Populate the OSRS combobox with some default items const defaultItemsOSRS = [ - { name: "Items", query: "bucket('infobox_item').select('item_name','item_id','examine').limit(20).offset(0).run()" }, + { name: "Items", query: "bucket('infobox_item').select('item_name','image','examine').limit(20).offset(0).run()" }, { name: "Monsters", query: "bucket('infobox_monster').select('name', 'examine').limit(20).offset(0).run()" }, { name: "Construction", query: "bucket('infobox_construction').select('page_name', 'image').limit(20).offset(0).run()" }, { name: "Locations", query: "bucket('infobox_location').select('page_name', 'is_members_only').limit(20).offset(0).run()" }, ]; + const querySearch = document.getElementById("querySearch"); + const querySearchOldSchool = document.getElementById("querySearch-oldschool"); const limitRS3 = document.getElementById("limit"); const offsetRS3 = document.getElementById("offset"); const queryBoxRS3 = document.getElementById("querySelect"); @@ -249,6 +251,10 @@ queryBoxOSRS.appendChild(option); }); + // Add event listener to the querySearch box + querySearch.addEventListener("keydown", (event) => { if (event.key === "Enter") { fetchAndDisplayRS3(); } }); + querySearchOldSchool.addEventListener("keydown", (event) => { if (event.key === "Enter") { fetchAndDisplayOSRS(); } }); + // Add event listener to the limit & offset using arrow functions limitRS3.addEventListener("change", () => { handleNumberChange("limit", false); }); offsetRS3.addEventListener("change", () => { handleNumberChange("offset", false); }); @@ -375,103 +381,6 @@ // Main function to fetch and display data async function fetchAndDisplayData(query, updateItemList = true, oldschool = false) { - /* - if (!query) - query = document.getElementById(`querySearch${oldschool ? "-oldschool" : ""}`).value; - - const bucketName = extractBucketName(query); - const keys = extractSelectKeys(query); - - const extractedDataElement = document.getElementById(`extractedData${oldschool ? "-oldschool" : ""}`); - const rawDataElement = document.getElementById(`rawData${oldschool ? "-oldschool" : ""}`); - - extractedDataElement.innerHTML = "

Loading data...

"; - rawDataElement.innerHTML = "

Loading raw data...

"; - - const itemData = await requestBucket(query, oldschool); - - if (itemData) { - // Clear previous content - extractedDataElement.innerHTML = ""; - - // Set itemCount for for query results - let itemCount = document.getElementById(`itemCount${oldschool ? "-oldschool" : ""}`); - itemCount.innerText = `Items Found: ${itemData.bucket.length}`; - - // Hide/show previous button - if (parseInt(document.getElementById(`offset${oldschool ? "-oldschool" : ""}`).value) <= 0) - document.getElementById(`prevOffset${oldschool ? "-oldschool" : ""}`).style = "display: none"; - else - document.getElementById(`prevOffset${oldschool ? "-oldschool" : ""}`).style = "display: inline"; - - // Hide/show next button - if (itemData.bucket.length < parseInt(document.getElementById(`limit${oldschool ? "-oldschool" : ""}`).value)) - document.getElementById(`nextOffset${oldschool ? "-oldschool" : ""}`).style = "display: none"; - else - document.getElementById(`nextOffset${oldschool ? "-oldschool" : ""}`).style = "display: inline"; - - const maxCount = 500; // Limit the number of displayed items - let previousItemValue = null; - for (let i = 0; i < itemData.bucket.length; i++) { - const item = itemData.bucket[i]; - - // Add each item to the combobox if updateItemList is true - if (updateItemList && itemData.bucket.length > 1) { - let itemSelect = document.getElementById(`itemSelect${oldschool ? "-oldschool" : ""}`); - if (i == 0) { - itemSelect.innerHTML = ""; - const option = document.createElement(`option`); - option.value = query; - option.textContent = `--- Select an item ---`; - itemSelect.appendChild(option); - } - - // Add each item to the combobox - const option = document.createElement(`option`); - - // Build the select query dynamically based on keys - option.value = `bucket('${bucketName}').select(`; - for (const key of keys) - option.value += `'${key}',`; - option.value = option.value.slice(0, -1); // Remove trailing comma - option.value += `).where('${keys[0]}', '${item[keys[0]].replaceAll("'", "\\'")}').limit(20).offset(0).run()`; - - option.textContent = keys ? item[keys[0]] : "No KEYS"; - if (!previousItemValue || previousItemValue != item[keys[0]]) - itemSelect.appendChild(option); - - previousItemValue = item[keys[0]]; - } - if (i > maxCount) continue; // Only display the first item by default - - // Setup the table header row - if (i == 0) { - let rowEntry = document.createElement('tr'); - for (const key of keys) { - let cellEntry = document.createElement('th') - cellEntry.innerHTML = `${key}`; - rowEntry.appendChild(cellEntry); - } - extractedDataElement.appendChild(rowEntry); - } - - let rowEntry = document.createElement('tr'); - for (const key of keys) { - let cellEntry = document.createElement('td') - cellEntry.innerHTML = `${!(key in item) ? 'false' : (item[key] === '' ? 'true' : item[key])}`; - rowEntry.appendChild(cellEntry); - } - extractedDataElement.appendChild(rowEntry); - - } - - rawDataElement.innerHTML = `
${JSON.stringify(itemData, null, 2)}
`; - return parseInt(itemData.bucket.length); - } else { - extractedDataElement.textContent = "Failed to fetch data from the API."; - rawDataElement.textContent = "No raw data available."; - } - return 0;*/ const data = await gatherData(query, oldschool); return renderData(data, updateItemList); } @@ -572,7 +481,13 @@ let rowEntry = document.createElement('tr'); for (const key of keys) { let cellEntry = document.createElement('td'); - cellEntry.innerHTML = `${!(key in item) ? 'false' : (item[key] === '' ? 'true' : item[key])}`; + if (key === 'image' && item[key]) { + let rawName = String(item[key]); + let imageName = rawName.replaceAll('File:', '').replaceAll(' ', '_'); + let url = `https://${oldschool ? "oldschool." : ""}runescape.wiki/images/${imageName}`; + cellEntry.innerHTML = `${rawName}`; + } else + cellEntry.innerHTML = `${!(key in item) ? 'false' : (item[key] === '' ? 'true' : item[key])}`; rowEntry.appendChild(cellEntry); } extractedDataElement.appendChild(rowEntry); diff --git a/src/.htaccess b/src/.htaccess index ea4f9f2..0110fd8 100644 --- a/src/.htaccess +++ b/src/.htaccess @@ -36,7 +36,7 @@ Options -Indexes Header set X-XSS-Protection "1; mode=block" Header set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" Header set Referrer-Policy "strict-origin-when-cross-origin" - Header set Content-Security-Policy "default-src 'self' https://runescape.wiki https://oldschool.runescape.wiki; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://oldschool.runescape.wiki; font-src 'self'; frame-ancestors http://unlishema.local https://unlishema.org https://*.unlishema.org" + Header set Content-Security-Policy "default-src 'self' https://runescape.wiki https://oldschool.runescape.wiki; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://runescape.wiki https://oldschool.runescape.wiki; font-src 'self'; frame-ancestors http://unlishema.local https://unlishema.org https://*.unlishema.org" Header set Permissions-Policy "geolocation=(), microphone=(), camera=()" # Set the Host header to ensure requests target slayer.unlishema.org diff --git a/src/dev.html b/src/dev.html index 665b5c3..169c688 100644 --- a/src/dev.html +++ b/src/dev.html @@ -129,11 +129,11 @@ - +
+ value="bucket('infobox_item').select('item_name','image','examine').limit(20).offset(0).run()">


@@ -172,11 +172,11 @@ - +
+ value="bucket('infobox_item').select('item_name','image','examine').limit(20).offset(0).run()">


@@ -210,7 +210,7 @@ document.addEventListener("DOMContentLoaded", async () => { // Populate the RS3 combobox with some default items const defaultItemsRS3 = [ - { name: "Items", query: "bucket('infobox_item').select('item_name','item_id','examine').limit(20).offset(0).run()" }, + { name: "Items", query: "bucket('infobox_item').select('item_name','image','examine').limit(20).offset(0).run()" }, { name: "Monsters", query: "bucket('infobox_monster').select('name', 'examine').limit(20).offset(0).run()" }, { name: "Locations", query: "bucket('infobox_location').select('page_name', 'is_members_only').limit(20).offset(0).run()" }, ]; @@ -218,12 +218,14 @@ // Populate the OSRS combobox with some default items const defaultItemsOSRS = [ - { name: "Items", query: "bucket('infobox_item').select('item_name','item_id','examine').limit(20).offset(0).run()" }, + { name: "Items", query: "bucket('infobox_item').select('item_name','image','examine').limit(20).offset(0).run()" }, { name: "Monsters", query: "bucket('infobox_monster').select('name', 'examine').limit(20).offset(0).run()" }, { name: "Construction", query: "bucket('infobox_construction').select('page_name', 'image').limit(20).offset(0).run()" }, { name: "Locations", query: "bucket('infobox_location').select('page_name', 'is_members_only').limit(20).offset(0).run()" }, ]; + const querySearch = document.getElementById("querySearch"); + const querySearchOldSchool = document.getElementById("querySearch-oldschool"); const limitRS3 = document.getElementById("limit"); const offsetRS3 = document.getElementById("offset"); const queryBoxRS3 = document.getElementById("querySelect"); @@ -249,6 +251,10 @@ queryBoxOSRS.appendChild(option); }); + // Add event listener to the querySearch box + querySearch.addEventListener("keydown", (event) => { if (event.key === "Enter") { fetchAndDisplayRS3(); } }); + querySearchOldSchool.addEventListener("keydown", (event) => { if (event.key === "Enter") { fetchAndDisplayOSRS(); } }); + // Add event listener to the limit & offset using arrow functions limitRS3.addEventListener("change", () => { handleNumberChange("limit", false); }); offsetRS3.addEventListener("change", () => { handleNumberChange("offset", false); }); @@ -375,103 +381,6 @@ // Main function to fetch and display data async function fetchAndDisplayData(query, updateItemList = true, oldschool = false) { - /* - if (!query) - query = document.getElementById(`querySearch${oldschool ? "-oldschool" : ""}`).value; - - const bucketName = extractBucketName(query); - const keys = extractSelectKeys(query); - - const extractedDataElement = document.getElementById(`extractedData${oldschool ? "-oldschool" : ""}`); - const rawDataElement = document.getElementById(`rawData${oldschool ? "-oldschool" : ""}`); - - extractedDataElement.innerHTML = "

Loading data...

"; - rawDataElement.innerHTML = "

Loading raw data...

"; - - const itemData = await requestBucket(query, oldschool); - - if (itemData) { - // Clear previous content - extractedDataElement.innerHTML = ""; - - // Set itemCount for for query results - let itemCount = document.getElementById(`itemCount${oldschool ? "-oldschool" : ""}`); - itemCount.innerText = `Items Found: ${itemData.bucket.length}`; - - // Hide/show previous button - if (parseInt(document.getElementById(`offset${oldschool ? "-oldschool" : ""}`).value) <= 0) - document.getElementById(`prevOffset${oldschool ? "-oldschool" : ""}`).style = "display: none"; - else - document.getElementById(`prevOffset${oldschool ? "-oldschool" : ""}`).style = "display: inline"; - - // Hide/show next button - if (itemData.bucket.length < parseInt(document.getElementById(`limit${oldschool ? "-oldschool" : ""}`).value)) - document.getElementById(`nextOffset${oldschool ? "-oldschool" : ""}`).style = "display: none"; - else - document.getElementById(`nextOffset${oldschool ? "-oldschool" : ""}`).style = "display: inline"; - - const maxCount = 500; // Limit the number of displayed items - let previousItemValue = null; - for (let i = 0; i < itemData.bucket.length; i++) { - const item = itemData.bucket[i]; - - // Add each item to the combobox if updateItemList is true - if (updateItemList && itemData.bucket.length > 1) { - let itemSelect = document.getElementById(`itemSelect${oldschool ? "-oldschool" : ""}`); - if (i == 0) { - itemSelect.innerHTML = ""; - const option = document.createElement(`option`); - option.value = query; - option.textContent = `--- Select an item ---`; - itemSelect.appendChild(option); - } - - // Add each item to the combobox - const option = document.createElement(`option`); - - // Build the select query dynamically based on keys - option.value = `bucket('${bucketName}').select(`; - for (const key of keys) - option.value += `'${key}',`; - option.value = option.value.slice(0, -1); // Remove trailing comma - option.value += `).where('${keys[0]}', '${item[keys[0]].replaceAll("'", "\\'")}').limit(20).offset(0).run()`; - - option.textContent = keys ? item[keys[0]] : "No KEYS"; - if (!previousItemValue || previousItemValue != item[keys[0]]) - itemSelect.appendChild(option); - - previousItemValue = item[keys[0]]; - } - if (i > maxCount) continue; // Only display the first item by default - - // Setup the table header row - if (i == 0) { - let rowEntry = document.createElement('tr'); - for (const key of keys) { - let cellEntry = document.createElement('th') - cellEntry.innerHTML = `${key}`; - rowEntry.appendChild(cellEntry); - } - extractedDataElement.appendChild(rowEntry); - } - - let rowEntry = document.createElement('tr'); - for (const key of keys) { - let cellEntry = document.createElement('td') - cellEntry.innerHTML = `${!(key in item) ? 'false' : (item[key] === '' ? 'true' : item[key])}`; - rowEntry.appendChild(cellEntry); - } - extractedDataElement.appendChild(rowEntry); - - } - - rawDataElement.innerHTML = `
${JSON.stringify(itemData, null, 2)}
`; - return parseInt(itemData.bucket.length); - } else { - extractedDataElement.textContent = "Failed to fetch data from the API."; - rawDataElement.textContent = "No raw data available."; - } - return 0;*/ const data = await gatherData(query, oldschool); return renderData(data, updateItemList); } @@ -572,7 +481,13 @@ let rowEntry = document.createElement('tr'); for (const key of keys) { let cellEntry = document.createElement('td'); - cellEntry.innerHTML = `${!(key in item) ? 'false' : (item[key] === '' ? 'true' : item[key])}`; + if (key === 'image' && item[key]) { + let rawName = String(item[key]); + let imageName = rawName.replaceAll('File:', '').replaceAll(' ', '_'); + let url = `https://${oldschool ? "oldschool." : ""}runescape.wiki/images/${imageName}`; + cellEntry.innerHTML = `${rawName}`; + } else + cellEntry.innerHTML = `${!(key in item) ? 'false' : (item[key] === '' ? 'true' : item[key])}`; rowEntry.appendChild(cellEntry); } extractedDataElement.appendChild(rowEntry); diff --git a/src/index.ts b/src/index.ts index 696a8e4..2df3669 100644 --- a/src/index.ts +++ b/src/index.ts @@ -60,7 +60,7 @@ if (window.alt1) alt1.identifyAppUrl("./appconfig.json"); document.addEventListener("DOMContentLoaded", async () => { try { /* - let searchQuery = new query.QueryData("infobox_monster", ['name', 'slayer_level'], [], 20, 0); + let searchQuery = new query.QueryData("infobox_monster", ['name', 'slayer_level'], ['slayer_level', '>=', '99'], 5000, 0); console.log("Search Query Statement:", searchQuery.statement()); let queryData = await searchQuery.run(); console.log("Query Data Result:", queryData); diff --git a/src/modules/query.ts b/src/modules/query.ts index 21b6c46..57712cb 100644 --- a/src/modules/query.ts +++ b/src/modules/query.ts @@ -5,7 +5,7 @@ export class QueryData { limit: number; offset: number; - constructor(bucket = "infobox_item", select = ['*'], where = [], limit = 500, offset = 0) { + constructor(bucket = "infobox_item", select = ['page_name'], where = [], limit = 500, offset = 0) { this.bucket = bucket; this.select = select; this.where = where; -- 2.43.0