v2.1.0: assets/js/admin.js
This commit is contained in:
+71
-31
@@ -1,35 +1,23 @@
|
|||||||
/* AskTam MCP Admin JS */
|
/* AskTam MCP Admin JS */
|
||||||
(function(){
|
(function(){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function initToolsForm(){
|
function initToolsForm(){
|
||||||
var form=document.getElementById('asktam-mcp-tools-form');
|
var form=document.getElementById('asktam-mcp-tools-form');
|
||||||
if(!form)return;
|
if(!form)return;
|
||||||
var enableAll=form.querySelector('.asktam-mcp-enable-all');
|
var en=form.querySelector('.asktam-mcp-enable-all');
|
||||||
var disableAll=form.querySelector('.asktam-mcp-disable-all');
|
var dis=form.querySelector('.asktam-mcp-disable-all');
|
||||||
if(enableAll)enableAll.addEventListener('click',function(){
|
if(en)en.addEventListener('click',function(){form.querySelectorAll('input[type="checkbox"]').forEach(function(cb){cb.checked=true;});updateCards(form);});
|
||||||
form.querySelectorAll('input[type="checkbox"]').forEach(function(cb){cb.checked=true;});
|
if(dis)dis.addEventListener('click',function(){form.querySelectorAll('input[type="checkbox"]').forEach(function(cb){cb.checked=false;});updateCards(form);});
|
||||||
updateCards(form);
|
|
||||||
});
|
|
||||||
if(disableAll)disableAll.addEventListener('click',function(){
|
|
||||||
form.querySelectorAll('input[type="checkbox"]').forEach(function(cb){cb.checked=false;});
|
|
||||||
updateCards(form);
|
|
||||||
});
|
|
||||||
form.querySelectorAll('.asktam-mcp-category').forEach(function(cat){
|
form.querySelectorAll('.asktam-mcp-category').forEach(function(cat){
|
||||||
var en=cat.querySelector('.asktam-mcp-cat-enable-all');
|
var ce=cat.querySelector('.asktam-mcp-cat-enable-all');
|
||||||
var dis=cat.querySelector('.asktam-mcp-cat-disable-all');
|
var cd=cat.querySelector('.asktam-mcp-cat-disable-all');
|
||||||
if(en)en.addEventListener('click',function(){
|
if(ce)ce.addEventListener('click',function(){cat.querySelectorAll('input[type="checkbox"]').forEach(function(cb){cb.checked=true;});updateCards(form);});
|
||||||
cat.querySelectorAll('input[type="checkbox"]').forEach(function(cb){cb.checked=true;});
|
if(cd)cd.addEventListener('click',function(){cat.querySelectorAll('input[type="checkbox"]').forEach(function(cb){cb.checked=false;});updateCards(form);});
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
|
form.addEventListener('change',function(e){if(e.target.type==='checkbox')updateCards(form);});
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateCards(form){
|
function updateCards(form){
|
||||||
form.querySelectorAll('.asktam-mcp-tool-card').forEach(function(card){
|
form.querySelectorAll('.asktam-mcp-tool-card').forEach(function(card){
|
||||||
var cb=card.querySelector('input[type="checkbox"]');
|
var cb=card.querySelector('input[type="checkbox"]');
|
||||||
@@ -37,15 +25,67 @@ function updateCards(form){
|
|||||||
card.classList.toggle('is-disabled',!cb.checked);
|
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){
|
function copyToClipboard(text){
|
||||||
if(navigator.clipboard&&navigator.clipboard.writeText)return navigator.clipboard.writeText(text);
|
if(navigator.clipboard&&navigator.clipboard.writeText)return navigator.clipboard.writeText(text);
|
||||||
return new Promise(function(resolve){
|
return new Promise(function(resolve){
|
||||||
var ta=document.createElement('textarea');
|
var ta=document.createElement('textarea');ta.value=text;ta.style.position='fixed';ta.style.opacity='0';
|
||||||
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();
|
||||||
document.body.appendChild(ta);ta.select();document.execCommand('copy');
|
|
||||||
document.body.removeChild(ta);resolve();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function initCopyButtons(){
|
function initCopyButtons(){
|
||||||
document.querySelectorAll('.asktam-mcp-copy-btn').forEach(function(btn){
|
document.querySelectorAll('.asktam-mcp-copy-btn').forEach(function(btn){
|
||||||
btn.addEventListener('click',function(){
|
btn.addEventListener('click',function(){
|
||||||
@@ -54,16 +94,16 @@ function initCopyButtons(){
|
|||||||
if(!src)return;
|
if(!src)return;
|
||||||
var copied=(typeof asktamMcpAdmin!=='undefined'&&asktamMcpAdmin.copied)?asktamMcpAdmin.copied:'Copied!';
|
var copied=(typeof asktamMcpAdmin!=='undefined'&&asktamMcpAdmin.copied)?asktamMcpAdmin.copied:'Copied!';
|
||||||
copyToClipboard(src.value).then(function(){
|
copyToClipboard(src.value).then(function(){
|
||||||
var orig=btn.textContent;
|
var orig=btn.textContent;btn.textContent=copied;
|
||||||
btn.textContent=copied;
|
|
||||||
setTimeout(function(){btn.textContent=orig;},2000);
|
setTimeout(function(){btn.textContent=orig;},2000);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(document.readyState==='loading'){
|
if(document.readyState==='loading'){
|
||||||
document.addEventListener('DOMContentLoaded',function(){initToolsForm();initCopyButtons();});
|
document.addEventListener('DOMContentLoaded',function(){initToolsForm();initConnectionConfigs();initCopyButtons();});
|
||||||
}else{
|
}else{
|
||||||
initToolsForm();initCopyButtons();
|
initToolsForm();initConnectionConfigs();initCopyButtons();
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user