芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/.trash/media.2/plg_system_webauthn/js/management-es5.min.js
!function(){"use strict";window.Joomla=window.Joomla||{},function(e,t){var n=function e(t,n){void 0===n&&(n="");var a="";return Object.keys(t).forEach((function(r){if("object"!=typeof t[r])return a.length>0&&(a+="&"),void(a+=""===n?encodeURIComponent(r)+"="+encodeURIComponent(t[r]):encodeURIComponent(n)+"["+encodeURIComponent(r)+"]="+encodeURIComponent(t[r]));a+=""+e(t[r],r)})),a},a=function(t){e.renderMessages({error:[t]})};e.plgSystemWebauthnCreateCredentials=function(r,i){if("credentials"in navigator){var l=t.getElementById(r);if(l){var o=JSON.parse(atob(l.dataset.public_key)),u=atob(l.dataset.postback_url),d=function(e){return btoa(String.fromCharCode.apply(String,e))},c=function(e){var t=e.replace(/-/g,"+").replace(/_/g,"/"),n=t.length%4;if(n){if(1===n)throw new Error("InvalidLengthError: Input base64url string is the wrong length to determine padding");t+=new Array(5-n).join("=")}return t};o.challenge=Uint8Array.from(window.atob(c(o.challenge)),(function(e){return e.charCodeAt(0)})),o.user.id=Uint8Array.from(window.atob(o.user.id),(function(e){return e.charCodeAt(0)})),o.excludeCredentials&&(o.excludeCredentials=o.excludeCredentials.map((function(e){return e.id=Uint8Array.from(window.atob(c(e.id)),(function(e){return e.charCodeAt(0)})),e}))),navigator.credentials.create({publicKey:o}).then((function(r){var l={id:r.id,type:r.type,rawId:d(new Uint8Array(r.rawId)),response:{clientDataJSON:d(new Uint8Array(r.response.clientDataJSON)),attestationObject:d(new Uint8Array(r.response.attestationObject))}},o={option:"com_ajax",group:"system",plugin:"webauthn",format:"raw",akaction:"create",encoding:"raw",data:btoa(JSON.stringify(l))};e.request({url:u,method:"POST",data:n(o),onSuccess:function(n){var a=t.querySelectorAll(i);a&&(a[0].outerHTML=n,e.plgSystemWebauthnInitialize())},onError:function(e){a(e.status+" "+e.statusText)}})})).catch((function(e){a(e)}))}}else e.renderMessages({error:[e.Text._("PLG_SYSTEM_WEBAUTHN_ERR_NO_BROWSER_SUPPORT")]})},e.plgSystemWebauthnEditLabel=function(r,i){var l=t.getElementById(i);if(!l)return!1;var o=atob(l.dataset.postback_url),u=r.parentElement.parentElement,d=u.dataset.credential_id,c=u.querySelectorAll("td"),s=c[0],m=c[1].querySelectorAll("button"),p=m[0],b=m[1],_=s.innerText,g=t.createElement("input");g.type="text",g.name="label",g.defaultValue=_;var E=t.createElement("button");E.className="btn btn-success btn-sm",E.innerText=e.Text._("PLG_SYSTEM_WEBAUTHN_MANAGE_BTN_SAVE_LABEL"),E.addEventListener("click",(function(){var t=g.value;if(""!==t){var r={option:"com_ajax",group:"system",plugin:"webauthn",format:"json",encoding:"json",akaction:"savelabel",credential_id:d,new_label:t};e.request({url:o,method:"POST",data:n(r),onSuccess:function(t){var n=!1;try{n=JSON.parse(t)}catch(e){n="true"===t}!0!==n&&a(e.Text._("PLG_SYSTEM_WEBAUTHN_ERR_LABEL_NOT_SAVED"))},onError:function(t){a(e.Text._("PLG_SYSTEM_WEBAUTHN_ERR_LABEL_NOT_SAVED")+" -- "+t.status+" "+t.statusText)}})}return s.innerText=t,p.disabled=!1,b.disabled=!1,!1}),!1);var f=t.createElement("button");return f.className="btn btn-danger btn-sm",f.innerText=e.Text._("PLG_SYSTEM_WEBAUTHN_MANAGE_BTN_CANCEL_LABEL"),f.addEventListener("click",(function(){return s.innerText=_,p.disabled=!1,b.disabled=!1,!1}),!1),s.innerHTML="",s.appendChild(g),s.appendChild(E),s.appendChild(f),p.disabled=!0,b.disabled=!0,!1},e.plgSystemWebauthnDelete=function(r,i){var l=t.getElementById(i);if(!l)return!1;var o=atob(l.dataset.postback_url),u=r.parentElement.parentElement,d=u.dataset.credential_id,c=u.querySelectorAll("td")[1].querySelectorAll("button"),s=c[0],m=c[1];s.disabled=!0,m.disabled=!0;var p={option:"com_ajax",group:"system",plugin:"webauthn",format:"json",encoding:"json",akaction:"delete",credential_id:d};return e.request({url:o,method:"POST",data:n(p),onSuccess:function(t){var n=!1;try{n=JSON.parse(t)}catch(e){n="true"===t}!0===n?u.parentElement.removeChild(u):a(e.Text._("PLG_SYSTEM_WEBAUTHN_ERR_NOT_DELETED"))},onError:function(t){s.disabled=!1,m.disabled=!1,a(e.Text._("PLG_SYSTEM_WEBAUTHN_ERR_NOT_DELETED")+" -- "+t.status+" "+t.statusText)}}),!1},e.plgSystemWebauthnAddOnClick=function(t){return t.preventDefault(),e.plgSystemWebauthnCreateCredentials(t.currentTarget.getAttribute("data-random-id"),"#plg_system_webauthn-management-interface"),!1},e.plgSystemWebauthnEditOnClick=function(t){return t.preventDefault(),e.plgSystemWebauthnEditLabel(t.currentTarget,t.currentTarget.getAttribute("data-random-id")),!1},e.plgSystemWebauthnDeleteOnClick=function(t){return t.preventDefault(),e.plgSystemWebauthnDelete(t.currentTarget,t.currentTarget.getAttribute("data-random-id")),!1},e.plgSystemWebauthnInitialize=function(){var n=t.getElementById("plg_system_webauthn-manage-add");n&&n.addEventListener("click",e.plgSystemWebauthnAddOnClick);var a=[].slice.call(t.querySelectorAll(".plg_system_webauthn-manage-edit"));a.length&&a.forEach((function(t){t.addEventListener("click",e.plgSystemWebauthnEditOnClick)}));var r=[].slice.call(t.querySelectorAll(".plg_system_webauthn-manage-delete"));r.length&&r.forEach((function(t){t.addEventListener("click",e.plgSystemWebauthnDeleteOnClick)}))},e.plgSystemWebauthnInitialize()}(Joomla,document)}();