MCPcopy
hub / github.com/ChinaGodMan/UserScripts / login

Function login

missav-explorer/missav-explorer.user.js:1659–1699  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1657 }
1658 //登录
1659 async function login() {
1660 let retryCount = 2 // 设置重试次数为2次
1661
1662 while (retryCount > 0) {
1663 // 构建登录请求
1664 const LOGIN = {
1665 method: 'PROPFIND', // 使用 PROPFIND 方法检查根目录
1666 path: retryCount === 2 ? '/' : '', // 根据重试次数设置 path
1667 headers: {
1668 'Depth': '1',
1669 'Authorization': 'Basic ' + btoa(username + ':' + password),
1670 'Connection': 'Keep-Alive', // 保持连接
1671 'User-Agent': 'Mozilla/5.0' // 用户代理
1672 }
1673 }
1674
1675 // 发起登录请求
1676 const loginResponse = await GM_xhr(LOGIN)
1677
1678 // 判断登录结果
1679 if (loginResponse.status === 207) {
1680 console.log('登录成功')
1681 // 登录成功后,可以执行其他操作
1682 showModal('Webdav登录成功!', 1000)
1683 return true // 返回登录成功标志
1684 } else {
1685 console.error('登录失败:', loginResponse.status)
1686 if (retryCount === 1) {
1687 showModal('Webdav登录失败!' + loginResponse.status, 1000)
1688 return false // 返回登录失败标志
1689 } else {
1690 retryCount-- // 减少重试次数
1691 }
1692 }
1693 }
1694
1695 // 如果重试次数用尽仍未登录成功,执行其他操作(可根据实际情况添加代码)
1696 console.error('重试次数用尽,登录失败')
1697 showModal('Webdav登录失败!重试次数用尽', 1000)
1698 return false
1699 }
1700
1701 //刷新
1702 function updateConfig(newUrl, newUsername, newPassword) {

Callers 1

updateConfigFunction · 0.70

Calls 2

GM_xhrFunction · 0.85
showModalFunction · 0.85

Tested by

no test coverage detected