v2.1.0: assets/js/admin.js

This commit is contained in:
2026-05-29 11:53:30 +00:00
parent af7ee5185e
commit 5c314a103c
+69
View File
@@ -0,0 +1,69 @@
/* 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);
});
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);
});
}
function updateCards(form){
form.querySelectorAll('.asktam-mcp-tool-card').forEach(function(card){
var cb=card.querySelector('input[type="checkbox"]');
card.classList.toggle('is-enabled',cb.checked);
card.classList.toggle('is-disabled',!cb.checked);
});
}
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();
});
}
function initCopyButtons(){
document.querySelectorAll('.asktam-mcp-copy-btn').forEach(function(btn){
btn.addEventListener('click',function(){
var id=this.getAttribute('data-target');
var src=document.getElementById(id);
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;
setTimeout(function(){btn.textContent=orig;},2000);
});
});
});
}
if(document.readyState==='loading'){
document.addEventListener('DOMContentLoaded',function(){initToolsForm();initCopyButtons();});
}else{
initToolsForm();initCopyButtons();
}
})();