2025-02-18 15:14:36 -06:00
|
|
|
// Checks to see what map files exist at /usb-butter/osm-map-files/ and displays them
|
|
|
|
|
// using the template hidden in the page
|
|
|
|
|
|
2025-02-18 15:32:45 -06:00
|
|
|
OSM_PACKAGE = "net.osmand";
|
|
|
|
|
|
2025-02-18 15:14:36 -06:00
|
|
|
const getMaps = async (folder_href) => {
|
|
|
|
|
async function populateSpan(response) {
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
console.error("Failed to fetch " + folder_href);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const text = await response.text();
|
|
|
|
|
const doc = new DOMParser().parseFromString(text, 'text/html');
|
|
|
|
|
const { files, folders } = extractDirectoryListing(doc);
|
|
|
|
|
renderMaps(files);
|
|
|
|
|
}
|
|
|
|
|
const response = fetch(folder_href).then(populateSpan);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getOsmObfDisplayName(name) {
|
|
|
|
|
const region = name.split('_')[0];
|
|
|
|
|
const words = region.split('-');
|
|
|
|
|
for (let i = 0; i < words.length; i++) {
|
|
|
|
|
words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1);
|
|
|
|
|
}
|
|
|
|
|
return words.join(" ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderMaps(files) {
|
|
|
|
|
template = document.getElementById('filerow-template');
|
|
|
|
|
fileList = template.parentElement;
|
|
|
|
|
for (let file of files) {
|
|
|
|
|
let clone = template.cloneNode(true);
|
|
|
|
|
const links = clone.querySelectorAll('a');
|
|
|
|
|
for (let link of links) {
|
|
|
|
|
link.href = '/usb-butter/osm-map-files/' + file.href;
|
|
|
|
|
link.download = file.name
|
|
|
|
|
}
|
|
|
|
|
const upperText = clone.querySelector('.upper-text');
|
|
|
|
|
const lowerText = clone.querySelector('.lower-text');
|
|
|
|
|
upperText.textContent = getOsmObfDisplayName(file.name);
|
|
|
|
|
lowerText.textContent = file.name;
|
|
|
|
|
fileList.appendChild(clone);
|
|
|
|
|
clone.removeAttribute('id');
|
|
|
|
|
clone.classList.remove("template");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-18 15:32:45 -06:00
|
|
|
// If OSM is in the F-Droid repo, show the download button
|
|
|
|
|
// and point to proper apk with proper size.
|
|
|
|
|
const getOsm = async () => {
|
|
|
|
|
repoRoot = '/usb-butter/appstore/fdroid/repo/';
|
|
|
|
|
json_url = repoRoot + 'index-v1.json';
|
|
|
|
|
const response = fetch(json_url).then(async (response) => {
|
|
|
|
|
const ix = await response.json();
|
|
|
|
|
if (ix.packages && ix.packages[OSM_PACKAGE] && ix.packages[OSM_PACKAGE].length > 0) {
|
|
|
|
|
const button = document.getElementById('osm-dl-button');
|
|
|
|
|
const links = button.querySelectorAll('a');
|
|
|
|
|
const apkName = ix.packages[OSM_PACKAGE][0]['apkName'];
|
|
|
|
|
const size = ix.packages[OSM_PACKAGE][0]['size'];
|
|
|
|
|
const sizeInMB = Math.floor(size / 1024 / 1024);
|
|
|
|
|
for (let link of links) {
|
|
|
|
|
link.href = repoRoot + apkName;
|
|
|
|
|
}
|
|
|
|
|
const cta = button.querySelector('.button-sub-text');
|
|
|
|
|
cta.textContent = `${sizeInMB} MB`;
|
|
|
|
|
button.classList.remove('hidden');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getOsm()
|
2025-02-18 15:14:36 -06:00
|
|
|
getMaps('/usb-butter/osm-map-files/');
|