const invocation = new XMLHttpRequest(); const url = 'https://pad.xpub.nl/p/special_issue_8_cnn/export/txt'; function findCategories(data){ // Return categories that this page is part of // by doing a reversed dictionary lookup var current_url = window.location.href; var keys = Object.keys(data) var categories = []; for(var i=0; i 0 && categories.length < 2){ //if we have only one category we add another one at random var keys = Object.keys(data) keys.splice(categories[1], 1) categories.push(keys[Math.floor(Math.random() * keys.length)]) } // Select a pseudo-randomised category for buttonA var buttonA = categories[Math.floor(Math.random() * categories.length)]; document.querySelectorAll('#buttonA button')[0].textContent = buttonA; // Select another category for buttonB var indexA = categories.indexOf(buttonA); categories.splice(indexA, 1); var buttonB = categories[Math.floor(Math.random() * categories.length)]; document.querySelectorAll('#buttonB button')[0].textContent = buttonB; // Insert a link for each button // to another page of the same category var linksA = data[buttonA]; var linksB = data[buttonB]; linksA.splice(window.location.href, 1); linksB.splice(window.location.href, 1); document.getElementById("buttonA").href = linksA[Math.floor(Math.random() * linksA.length)]; document.getElementById("buttonB").href = linksB[Math.floor(Math.random() * linksB.length)]; } function readEtherpadJSON(){ if (invocation){ invocation.open( "GET", url, true ); invocation.onreadystatechange = function() { console.log('ready!'); if (invocation.readyState === 4 && invocation.status === 200) { console.log('invocation:', invocation); CategoryNetworkNavigator(invocation.responseText); } }; invocation.send(); } return invocation; } function insertCNN(cnn_template){ document.body.innerHTML = cnn_template + document.body.innerHTML; readEtherpadJSON(); } var cnn_template = '\
\ \ \ \
\ \ ' insertCNN(cnn_template);