Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions assets/js/download.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use strict";

let fileinfo = {};

function setSnapshotFileInfo(key, name, size, url) {
fileinfo[`${key}_NAME`] = name;
fileinfo[`${key}_SIZE`] = size;
fileinfo[`${key}_URL`] = url;
fileinfo[`${key}_ASC_URL`] = `${url}.asc`;
fileinfo[`${key}_SHA256_URL`] = `${url}.sha256`;
fileinfo[`${key}_SHA512_URL`] = `${url}.sha512`;
}

const doCreateNews = () => {
for (const [fileid, value] of Object.entries(fileinfo)) {
if(fileid.endsWith('_URL')) {
document.querySelector(`a[id="${fileid}"]`)?.setAttribute('href', value);
} else {
const el = document.getElementById(fileid);
if(el) el.textContent = value;
}
}
};

const showReleaseCandidate = () => {
document.querySelector('#rc')?.style.removeProperty('display');
document.querySelector('#nav-rc')?.style.removeProperty('display');
};

// Failsafe loading pattern.
if(document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", doCreateNews);
} else {
doCreateNews();
}
162 changes: 107 additions & 55 deletions assets/js/home.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,115 @@
$(document).ready(function() {
"use strict";

var w = window.navigator.platform;
var bits = 32;
fi = function(s) {
return window.navigator.userAgent.indexOf(s) > -1;
};
if (fi('x86_64') || fi('x86-64') || fi('Win64') || fi('x64;') || fi('amd64') || fi('AMD64') || fi('WOW64') || fi('x64_64') || w === 'MacIntel' || w === 'Linux x86_64') {
bits = 64;
}

var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) {
OSName="Windows";
if (bits == 64) {
let fileinfo = {};

function setSnapshotFileInfo(key, name, size, url) {
fileinfo[`${key}_NAME`] = name;
fileinfo[`${key}_SIZE`] = size;
fileinfo[`${key}_URL`] = url;
fileinfo[`${key}_ASC_URL`] = `${url}.asc`;
fileinfo[`${key}_SHA256_URL`] = `${url}.sha256`;
fileinfo[`${key}_SHA512_URL`] = `${url}.sha512`;
}

const doUpdateDownloadLink = () => {
const armPatterns = ['arm', 'armv', 'aarch', 'aarch64', 'arm64;', 'android'];
const x64Patterns = ['x86_64', 'x86-64', 'win64', 'x64;', 'amd64', 'wow64', 'x64_64',];
const isArm = () => { return armPatterns.some((pattern) => userAgent.includes(pattern))};
const isX64 = () => { return x64Patterns.some((pattern) => userAgent.includes(pattern))};

const appVersion = navigator.appVersion.toLowerCase();
const userAgent = navigator.userAgent.toLowerCase();

let OSName = "Unknown OS";
let DLName = "OpenSCAD";
let downloadLink = "";
let downloadLinkDirect = false;

console.debug('Architecture detection:', isArm() ? 'arm' : isX64() ? 'x64' : 'unknown');

if(appVersion.includes("win")) {
OSName = "Windows";
if(isArm()) {
// Currently not available.
} else if(isX64()) {
DLName = fileinfo['WIN64_RELEASE_INSTALLER_NAME'];
downloadLink = fileinfo['WIN64_RELEASE_INSTALLER_URL'];
}
else {
downloadLinkDirect = true;
} else {
DLName = fileinfo['WIN32_RELEASE_INSTALLER_NAME'];
downloadLink = fileinfo['WIN32_RELEASE_INSTALLER_URL'];
}
}
else if (navigator.appVersion.indexOf("Mac")!=-1) {
OSName="Mac OS X";
DLName = fileinfo['MAC_RELEASE_NAME'];
downloadLink = fileinfo['MAC_RELEASE_URL'];
}
else if (navigator.appVersion.indexOf("X11")!=-1) {
OSName="Linux";
DLName = fileinfo['MAC_RELEASE_NAME'];
downloadLink = "downloads.html#linux";
downloadLinkDirect = true;
}
else if (navigator.appVersion.indexOf("Linux")!=-1) {
OSName="Linux";
DLName = fileinfo['MAC_RELEASE_NAME'];
downloadLink = "downloads.html#linux";
}

$("#home-download a#download-link").attr("href",downloadLink);
$("#home-download-link h4").text(DLName + " " + OSName);

var news, i;

$.get('news.html', function(data) {
$html = $(data)
$entries = $html.find('article section');

i=0;
} else if(appVersion.includes("mac")) {
OSName = "Mac OS X";
DLName = fileinfo['MAC_RELEASE_NAME'];
downloadLink = fileinfo['MAC_RELEASE_URL'];
downloadLinkDirect = true;
} else if(appVersion.includes("x11") || appVersion.includes("linux")) {
OSName = "Linux";
DLName = fileinfo['LIN64_RELEASE_NAME'];
downloadLink = "downloads.html#linux";
}

if(0 < downloadLink.length) {
document.querySelector('#home-download a#download-link').href = downloadLink;
}
if(downloadLinkDirect) {
document.querySelector('#home-download a#download-link').setAttribute('download', '');
}
document.querySelector('#home-download-link h4').textContent = `${DLName} for ${OSName}`;
}

$entries.each(function(){
$title = $(this).find('.title').html();
$date = $(this).find('.date').html();
$content = $(this).find('.entry').html();
$shortContent = jQuery.trim($content).substring(0, 150).split(" ").slice(0, -1).join(" ") + "...";
if(i<3){
$('#sidebar ul').append("<li style='padding-bottom:10px;'><strong><small>"+$date+"</small><strong><br/><a class='underline' href='news.html#"+$(this).attr("id")+"'>"+$title+"</a><br/><small>"+$shortContent+"</small></li><br clear='all'>");
}
i++;
});
}, "html");
const doCreateSidebarNews = async () => {
const sidebarList = document.querySelector('#sidebar ul');
if(!sidebarList) return;
let res;
try {
res = await fetch('news.html');
} catch (err) {
console.error('Failed to load news.html:', err);
return;
}
if(!res.ok) {
console.error(`Could not load news.html but got HTTP ${res.status}`);
return;
}

const text = await res.text();
const parser = new DOMParser();
const doc = parser.parseFromString(text, 'text/html');

const entries = doc.querySelectorAll('article section');

let i = 0;
for (const entry of entries) {
if(i >= 3) return;

const content = entry.querySelector('.entry')?.innerHTML ?? '';
const date = entry.querySelector('.date')?.innerHTML ?? '';
const id = entry.id ? `#${entry.id}` : '';
const title = entry.querySelector('.title')?.innerHTML ?? '';

const shortContent = content.trim().split(/\s+/).slice(0, 15).join(' ').replace(/\s+$/, '') + (content.trim().split(/\s+/).length > 15 ? '...' : '');

sidebarList.insertAdjacentHTML(
'beforeend',
`<li style="padding-bottom:10px;">
<strong><small>${date}</small></strong><br>
<a class="underline" href="news.html${id}">${title}</a><br>
<small>${shortContent}</small>
</li>
<br class="clear">`
);

i++;
}
};

});
if(document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', doUpdateDownloadLink);
document.addEventListener('DOMContentLoaded', doCreateSidebarNews);
} else {
doUpdateDownloadLink();
doCreateSidebarNews().then();
}
5 changes: 0 additions & 5 deletions assets/js/jquery-1.9.1.min.js

This file was deleted.

32 changes: 5 additions & 27 deletions downloads.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,18 @@
<link href="assets/fontawesome/css/fontawesome.min.css" rel="stylesheet">
<link href="assets/fonts/open-sans/all.css" rel="stylesheet">

<script src="assets/js/jquery-1.9.1.min.js"></script>

<script>
var fileinfo = {};
</script>
<script>
function setSnapshotFileInfo(key, name, size, url) {
fileinfo[key + "_NAME"] = name;
fileinfo[key + "_SIZE"] = size;
fileinfo[key + "_URL"] = url;
fileinfo[key + "_ASC_URL"] = url + ".asc";
fileinfo[key + "_SHA256_URL"] = url + ".sha256";
fileinfo[key + "_SHA512_URL"] = url + ".sha512";
}
jQuery(document).ready(function(){
for (var fileid in fileinfo) {
if (fileid.indexOf("_URL") >= 0) {
$("a[id="+fileid+"]").attr('href',fileinfo[fileid]);
} else {
$("#"+fileid).text(fileinfo[fileid]);
}
}
});
</script>
<script src="assets/js/download.js"></script>

<script src="inc/releases.js"></script>
<script type="text/javascript" src="https://files.openscad.org/rc/.rc.js" onload="jQuery(function(){ jQuery('#rc').show(); jQuery('#nav-rc').show(); });"></script>
<script type="text/javascript" src="https://files.openscad.org/rc/.rc.js" onload="showReleaseCandidate();"></script>
<script type="text/javascript" src="https://files.openscad.org/snapshots/.snapshots.js"></script>
</head>
<body>

<noscript>
<div style="text-align: center; background-color: #ffe8e8">
<p>Your browser has javascript disabled -- file links will go to a folder on <a href="https://files.openscad.org.">files.openscad.org</a></p>
<p>Please find your desired file inside the folder.</p>
<p>Your browser has JavaScript disabled -- file links will go to a folder on <a href="https://files.openscad.org.">files.openscad.org</a></p>
<p>Please find your desired file inside the folder.</p>
</div>
</noscript>

Expand Down
16 changes: 1 addition & 15 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,8 @@
<link href="assets/fontawesome/css/fontawesome.min.css" rel="stylesheet">
<link href="assets/fonts/open-sans/all.css" rel="stylesheet">


<script type="text/javascript">
var fileinfo = {};
function setSnapshotFileInfo(key, name, size, url) {
fileinfo[key + "_NAME"] = name;
fileinfo[key + "_SIZE"] = size;
fileinfo[key + "_URL"] = url;
fileinfo[key + "_ASC_URL"] = url + ".asc";
fileinfo[key + "_SHA256_URL"] = url + ".sha256";
fileinfo[key + "_SHA512_URL"] = url + ".sha512";
}
</script>
<script src="inc/releases.js"></script>

<script src="assets/js/jquery-1.9.1.min.js"></script>
<script src="assets/js/home.js"></script>
<script src="inc/releases.js"></script>
</head>
<body>

Expand Down
Loading