json-object-editor
Version:
JOE the Json Object Editor | Platform Edition
65 lines (61 loc) • 3.01 kB
JavaScript
;(function(){
// Creates navigation element with two rows of links and info display. Returns the nav DOM element.
function buildNav(){
var nav = document.createElement('nav');
nav.setAttribute('style','display:flex;flex-direction:column;gap:6px;margin-bottom:8px;font-size:14px;');
var infoRow = '<div id="mcp-nav-info" class="small" style="opacity:.8"></div>';
var linksRow1 = [
'<div style="display:flex;gap:10px;align-items:center">',
'<a href="/mcp-test.html" target="mcp_test_win">MCP Test</a>',
'<a href="/mcp-export.html" target="mcp_export_win">MCP Export</a>',
'<a href="/mcp-prompt.html" target="mcp_prompt_win">MCP Prompt</a>',
'<a href="/.well-known/mcp/manifest.json" target="mcp_manifest_win">MCP Manifest</a>',
'<span style="margin-left:auto"></span>',
'<a href="/privacy" target="privacy_win">Privacy</a>',
'<a href="/terms" target="terms_win">Terms</a>',
'</div>'
].join('');
var linksRow2 = [
'<div style="display:flex;gap:10px;align-items:center">',
'<a href="/mcp-schemas.html" target="mcp_schemas_win">Schemas</a>',
'<a href="/matrix.html" target="matrix_win">Matrix</a>',
'<a href="/ai-widget-test.html" target="ai_widget_test_win">AI Widget</a>',
'<a href="/intent-operator.html" target="intent_operator_win">Intent Operator</a>',
'<a href="/ai-jobs.html" target="ai_jobs_win">AI Jobs</a>',
'<a href="/plugins-test.html" target="plugins_test_win">Plugins</a>',
'</div>'
].join('');
nav.innerHTML = infoRow + linksRow1 + linksRow2;
return nav;
}
// Inserts navigation into DOM, replacing placeholder if present or prepending to body. No return value.
function insert(){
var placeholder = document.getElementById('mcp-nav');
var nav = buildNav();
if(placeholder){
placeholder.parentNode.replaceChild(nav, placeholder);
}else{
document.body.insertBefore(nav, document.body.firstChild);
}
}
// Fetches MCP manifest and updates info display with instance name, version, and hostname. No return value.
async function updateInstance(){
try{
var res = await fetch('/.well-known/mcp/manifest.json');
if(!res.ok) return;
var m = await res.json();
var info = document.getElementById('mcp-nav-info');
if(info && m && m.joe){
info.textContent = 'Name: '+(m.joe.name||'JOE')+' | Version: '+(m.joe.version||'')+' | Host: '+(m.joe.hostname||'');
}
}catch(e){}
}
if(document.readyState === 'loading'){
document.addEventListener('DOMContentLoaded', insert);
document.addEventListener('DOMContentLoaded', updateInstance);
}else{ insert(); updateInstance(); }
// Load favicon environment script for production detection
var faviconScript = document.createElement('script');
faviconScript.src = '/JsonObjectEditor/js/favicon-env.js';
document.head.appendChild(faviconScript);
})();