v2.1.0: assets/js/admin.js

This commit is contained in:
2026-05-29 12:29:45 +00:00
parent 02779a96a3
commit 28b9e0c28c
+71 -31
View File
@@ -1,35 +1,23 @@
/* AskTam MCP Admin JS */
(function(){
'use strict';
function initToolsForm(){
var form=document.getElementById('asktam-mcp-tools-form');
if(!form)return;
var enableAll=form.querySelector('.asktam-mcp-enable-all');
var disableAll=form.querySelector('.asktam-mcp-disable-all');
if(enableAll)enableAll.addEventListener('click',function(){
form.querySelectorAll('input[type="checkbox"]').forEach(function(cb){cb.checked=true;});
updateCards(form);
});
if(disableAll)disableAll.addEventListener('click',function(){
form.querySelectorAll('input[type="checkbox"]').forEach(function(cb){cb.checked=false;});
updateCards(form);
});
var en=form.querySelector('.asktam-mcp-enable-all');
var dis=form.querySelector('.asktam-mcp-disable-all');
if(en)en.addEventListener('click',function(){form.querySelectorAll('input[type="checkbox"]').forEach(function(cb){cb.checked=true;});updateCards(form);});
if(dis)dis.addEventListener('click',function(){form.querySelectorAll('input[type="checkbox"]').forEach(function(cb){cb.checked=false;});updateCards(form);});
form.querySelectorAll('.asktam-mcp-category').forEach(function(cat){
var en=cat.querySelector('.asktam-mcp-cat-enable-all');
var dis=cat.querySelector('.asktam-mcp-cat-disable-all');
if(en)en.addEventListener('click',function(){
cat.querySelectorAll('input[type="checkbox"]').forEach(function(cb){cb.checked=true;});
updateCards(form);
});
if(dis)dis.addEventListener('click',function(){
cat.querySelectorAll('input[type="checkbox"]').forEach(function(cb){cb.checked=false;});
updateCards(form);
});
});
form.addEventListener('change',function(e){
if(e.target.type==='checkbox')updateCards(form);
var ce=cat.querySelector('.asktam-mcp-cat-enable-all');
var cd=cat.querySelector('.asktam-mcp-cat-disable-all');
if(ce)ce.addEventListener('click',function(){cat.querySelectorAll('input[type="checkbox"]').forEach(function(cb){cb.checked=true;});updateCards(form);});
if(cd)cd.addEventListener('click',function(){cat.querySelectorAll('input[type="checkbox"]').forEach(function(cb){cb.checked=false;});updateCards(form);});
});
form.addEventListener('change',function(e){if(e.target.type==='checkbox')updateCards(form);});
}
function updateCards(form){
form.querySelectorAll('.asktam-mcp-tool-card').forEach(function(card){
var cb=card.querySelector('input[type="checkbox"]');
@@ -37,15 +25,67 @@ function updateCards(form){
card.classList.toggle('is-disabled',!cb.checked);
});
}
function setBlock(codeId,copyId,text){
var c=document.getElementById(codeId);
var t=document.getElementById(copyId);
if(c)c.textContent=text;
if(t)t.value=text;
}
function initConnectionConfigs(){
var btn=document.getElementById('asktam-generate-configs');
if(!btn)return;
btn.addEventListener('click',function(){
var keyInput=document.getElementById('asktam-api-key-input');
if(!keyInput||!keyInput.value.trim()){alert('Please enter your API key.');return;}
var apiKey=keyInput.value.trim();
var endpoint=(typeof asktamMcpAdmin!=='undefined')?asktamMcpAdmin.sseEndpoint:'';
var bearer='Bearer '+apiKey;
var configsDiv=document.getElementById('asktam-http-configs');
if(configsDiv)configsDiv.style.display='';
// claude.ai custom connector format
var claudeAiJson=JSON.stringify({
mcpServers:{wordpress:{url:endpoint,headers:{Authorization:bearer}}}
},null,2);
setBlock('asktam-claude-ai-code','asktam-claude-ai-copy',claudeAiJson);
// Claude Desktop claude_desktop_config.json
var desktopJson=JSON.stringify({
mcpServers:{wordpress:{url:endpoint,headers:{Authorization:bearer}}}
},null,2);
setBlock('asktam-desktop-code','asktam-desktop-copy',desktopJson);
// Cursor .cursor/mcp.json
var cursorJson=JSON.stringify({
mcpServers:{wordpress:{url:endpoint,headers:{Authorization:bearer}}}
},null,2);
setBlock('asktam-cursor-code','asktam-cursor-copy',cursorJson);
// Windsurf
var windsurfJson=JSON.stringify({
mcpServers:{wordpress:{serverUrl:endpoint,headers:{Authorization:bearer}}}
},null,2);
setBlock('asktam-windsurf-code','asktam-windsurf-copy',windsurfJson);
// npx mcp-remote
var remoteJson=JSON.stringify({
mcpServers:{wordpress:{command:'npx',args:['-y','mcp-remote',endpoint,'--header','Authorization: '+bearer]}}
},null,2);
setBlock('asktam-remote-code','asktam-remote-copy',remoteJson);
});
}
function copyToClipboard(text){
if(navigator.clipboard&&navigator.clipboard.writeText)return navigator.clipboard.writeText(text);
return new Promise(function(resolve){
var ta=document.createElement('textarea');
ta.value=text;ta.style.position='fixed';ta.style.opacity='0';
document.body.appendChild(ta);ta.select();document.execCommand('copy');
document.body.removeChild(ta);resolve();
var ta=document.createElement('textarea');ta.value=text;ta.style.position='fixed';ta.style.opacity='0';
document.body.appendChild(ta);ta.select();document.execCommand('copy');document.body.removeChild(ta);resolve();
});
}
function initCopyButtons(){
document.querySelectorAll('.asktam-mcp-copy-btn').forEach(function(btn){
btn.addEventListener('click',function(){
@@ -54,16 +94,16 @@ function initCopyButtons(){
if(!src)return;
var copied=(typeof asktamMcpAdmin!=='undefined'&&asktamMcpAdmin.copied)?asktamMcpAdmin.copied:'Copied!';
copyToClipboard(src.value).then(function(){
var orig=btn.textContent;
btn.textContent=copied;
var orig=btn.textContent;btn.textContent=copied;
setTimeout(function(){btn.textContent=orig;},2000);
});
});
});
}
if(document.readyState==='loading'){
document.addEventListener('DOMContentLoaded',function(){initToolsForm();initCopyButtons();});
document.addEventListener('DOMContentLoaded',function(){initToolsForm();initConnectionConfigs();initCopyButtons();});
}else{
initToolsForm();initCopyButtons();
initToolsForm();initConnectionConfigs();initCopyButtons();
}
})();