迁移站长登录验证码脚本
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// 站长登录页交互入口,集中管理验证码刷新,避免在 Blade 中暴露全局函数。
|
||||
|
||||
let adminLoginControlsBound = false;
|
||||
|
||||
/**
|
||||
* 为验证码图片追加随机参数,强制浏览器重新请求图片。
|
||||
*
|
||||
* @param {HTMLImageElement} captchaImage
|
||||
* @returns {void}
|
||||
*/
|
||||
function refreshCaptchaImage(captchaImage) {
|
||||
const refreshUrl = captchaImage.getAttribute("data-captcha-refresh-url") ?? "/captcha/default";
|
||||
captchaImage.src = `${refreshUrl}?${Math.random()}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定站长登录页验证码刷新事件。
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
function bindAdminLoginControls() {
|
||||
if (adminLoginControlsBound || typeof document === "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
adminLoginControlsBound = true;
|
||||
|
||||
document.addEventListener("click", (event) => {
|
||||
if (!(event.target instanceof HTMLImageElement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.target.hasAttribute("data-captcha-refresh-url")) {
|
||||
refreshCaptchaImage(event.target);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
bindAdminLoginControls();
|
||||
Reference in New Issue
Block a user