Update ECMAScript accordingly.

This commit is contained in:
Schimon Jehudah, Adv. 2024-09-04 15:50:11 +03:00
parent b5762e90ef
commit b26958acae

View file

@ -9,6 +9,7 @@ window.onload = async function(){
//let feedUrl = location.href.replace(/^https?:/, 'feed:');
let feedUrl = `feed://${location.host}/atom?pubsub=${pubsub}&node=${node}`;
follow.href = feedUrl;
follow.type = `application/atom+xml`;
follow.addEventListener ('click', function() {
window.open(feedUrl, "_self");
});
@ -81,11 +82,9 @@ window.onload = async function(){
}
// Build a journal list
if (locationHref.pathname.startsWith('/atom') && node) {
itemsList = await openJson(node)
if (locationHref.pathname.startsWith('/atom') && pubsub && node && !node.includes('/')) {
itemsList = await openJson(pubsub, node)
if (itemsList && locationHref.searchParams.get('item')) {
node = locationHref.searchParams.get('node')
pubsub = locationHref.searchParams.get('pubsub')
let elementDiv = document.createElement('div');
elementDiv.id = 'journal';
let elementH3 = document.createElement('h3');
@ -96,13 +95,15 @@ window.onload = async function(){
elementDiv.appendChild(elementH4);
let elementUl = document.createElement('ol');
elementDiv.appendChild(elementUl);
for (let item of itemsList) {
for (let item of itemsList.reverse()) {
let elementLi = document.createElement('li');
let elementA = document.createElement('a');
elementA.textContent = item.title;
elementA.href = item.link;
elementLi.appendChild(elementA);
elementUl.appendChild(elementLi);
console.log(elementLi.length)
if (elementUl.children.length > 9) {break};
}
let elementB = document.createElement('b');
elementB.textContent = 'Actions';
@ -111,19 +112,24 @@ window.onload = async function(){
elementDiv.appendChild(elementUl2);
links = [
{'text' : 'Subscribe from an XMPP client.',
'href' : `xmpp:${pubsub}?pubsub;action=subscribe;node=${node}`},
'href' : `xmpp:${pubsub}?pubsub;action=subscribe;node=${node}`,
'type' : 'x-scheme-handler/xmpp'},
{'text' : 'Subscribe with a News Reader.',
'href' : `feed://${location.host}/atom?pubsub=${pubsub}&node=${node}`},
'href' : `feed://${location.host}/atom?pubsub=${pubsub}&node=${node}`,
'type' : 'application/atom+xml'},
{'text' : 'Browse the journal.',
'href' : `atom?pubsub=${pubsub}&node=${node}`},
'href' : `atom?pubsub=${pubsub}&node=${node}`,
'type' : 'application/atom+xml'},
{'text' : 'Browse the portal.',
'href' : `opml?pubsub=${pubsub}`}
'href' : `opml?pubsub=${pubsub}`,
'type' : 'text/x-opml'}
]
for (let link of links) {
let elementLi = document.createElement('li');
let elementA = document.createElement('a');
elementA.textContent = link.text;
elementA.href = link.href;
elementA.type = link.type;
elementLi.appendChild(elementA);
elementUl2.appendChild(elementLi);
}
@ -233,7 +239,7 @@ window.onload = async function(){
elementDiv.appendChild(elementP2);
let elementSpan = document.createElement('span');
elementSpan.id = 'return';
elementSpan.textContent = 'Return To PubSub';
elementSpan.textContent = 'Return';
elementSpan.addEventListener ('click', function() {
document.querySelector('#selection-page').remove();
});
@ -242,8 +248,8 @@ window.onload = async function(){
});
}
async function openJson(nodeId) {
return fetch(`/data/${nodeId}.json`)
async function openJson(pubsubJid, nodeId) {
return fetch(`/data/${pubsubJid}/${nodeId}.json`)
.then(response => {
if (!response.ok) {
throw new Error('HTTP Error: ' + response.status);