HPUhushicheng 发表于 2023-8-14 13:35:51

河南理工大学校园网自动登录


1. 🔥QQ:2140463102🔥
3. 👆👆👆👆👆👆👆安装脚本之后,进入管理面板,进入此脚本,编辑,填写你的学号和密码,保存。
4. 🔥 此脚本适合绝大多数web端验证的校园网,只需要修改"@include"和element 🔥
5. 🔥 没去过北校区,现在只适用于南校区! 🔥
6. 🔥 GitHub:https://github.com/HPUhushicheng/ Blog:https://site.hpuedd.top/🔥

李恒道 发表于 2023-8-14 14:47:51

可以变量提升一下

   ```
   const username='填写你的学号'
   const password='填写你的密码'
   if (window.location.href.includes('gportal/web/login')) {
      document.getElementById('first_name').value = username
      document.getElementById('first_password').value = password
      var loginButton = document.querySelector('.form-input.submit_btn')
      if (loginButton) {
            loginButton.click()
      }
    } else if (window.location.href.includes('srun_portal_success')) {
      document.getElementById('username').value = username
      document.getElementById('password').value = password
      var secondLoginButton = document.querySelector('.btn-login')
      if (secondLoginButton) {
            secondLoginButton.click()
      }
    }
    ```

李恒道 发表于 2023-8-14 14:48:01

选择器也可以考虑再精简精简

李恒道 发表于 2023-8-14 15:03:10

我的个人想法
```js
const username = "填写你的学号";
const password = "填写你的密码";
const currentHref = window.location.href;
function generateFormSelector() {
let retObj = undefined;
if (currentHref.includes("gportal/web/login")) {
    retObj = {
      userSelector: "first_name",
      passSelector: "first_password",
      btnSelector: ".form-input.submit_btn",
    };
} else if (currentHref.includes("srun_portal_success")) {
    retObj = {
      userSelector: "username",
      passSelector: "password",
      btnSelector: ".btn-login",
    };
}
return retObj;
}
function main() {
if (
    currentHref.includes("gportal/web/login") ||
    currentHref.includes("srun_portal_success")
) {
    const formSelector = generateFormSelector();
    document.getElementById(formSelector.userSelector).value = username;
    document.getElementById(formSelector.passSelector).value = password;
    const secondLoginButton = document.querySelector(formSelector.btnSelector);
    if (secondLoginButton) {
      secondLoginButton.click();
    }
}
}
main()
```

HPUhushicheng 发表于 2023-8-14 15:23:26

好的,谢谢大佬提醒,因为当时没想太多,谢了{:4_94:}

HPUhushicheng 发表于 2023-8-14 15:56:39

大佬,我看了你的代码,又重新改了一下,将填充表单和登录的操作封装到 autoFillAndLogin 函数中,这样的封装可以让代码块可以在其他地方被重复使用。const username = "填写你的学号";
const password = "填写你的密码";

const currentHref = window.location.href;
const selectorConfigs = {
"gportal/web/login": {
    userSelector: "first_name",
    passSelector: "first_password",
    btnSelector: ".form-input.submit_btn",
},
"srun_portal_success": {
    userSelector: "username",
    passSelector: "password",
    btnSelector: ".btn-login",
},
};

function getSelectorConfig(currentHref) {
const matchedKey = Object.keys(selectorConfigs).find(key => currentHref.includes(key));
return selectorConfigs;
}

function autoFillAndLogin() {
const formSelector = getSelectorConfig(currentHref);
if (formSelector) {
    document.getElementById(formSelector.userSelector).value = username;
    document.getElementById(formSelector.passSelector).value = password;
    const loginButton = document.querySelector(formSelector.btnSelector);
    if (loginButton) {
      loginButton.click();
    }
}
}

李恒道 发表于 2023-8-14 16:02:41

HPUhushicheng 发表于 2023-8-14 15:56
大佬,我看了你的代码,又重新改了一下,将填充表单和登录的操作封装到 autoFillAndLogin 函数中,这样的封 ...

nice~比第一版好看多了

李恒道 发表于 2023-8-14 16:05:22

HPUhushicheng 发表于 2023-8-14 15:56
大佬,我看了你的代码,又重新改了一下,将填充表单和登录的操作封装到 autoFillAndLogin 函数中,这样的封 ...

还有就是喊人最好@或者在对方回复下回复
不然别人借不到消息的
大概率会导致冷场

HPUhushicheng 发表于 2023-8-14 16:15:02

李恒道 发表于 2023-8-14 16:05
还有就是喊人最好@或者在对方回复下回复
不然别人借不到消息的
大概率会导致冷场 ...

哦哦,好的,还不太熟悉论坛规则,感谢大佬{:4_94:}

weisili 发表于 2023-10-1 20:46:59

最近一直在学油猴脚本,总算找到了组织
页: [1]
查看完整版本: 河南理工大学校园网自动登录