YX-Auto-login

For auto login, data are stored locally

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         YX-Auto-login
// @namespace    http://tampermonkey.net/
// @version      2024-10-15T11
// @description  For auto login, data are stored locally
// @author       Movelocity
// @match        http://1.1.1.3/ac_portal/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
  'use strict';

  const xorEncryptDecrypt = (input, key) => {
    let output = '';
    for (let i = 0; i < input.length; i++) {
      output += String.fromCharCode(input.charCodeAt(i) ^ key.charCodeAt(i % key.length));
    }
    return output;
  };

  const base64Encode = (str) => btoa(unescape(encodeURIComponent(str)));
  const base64Decode = (str) => decodeURIComponent(escape(atob(str)));

  const scheduleRun = (func, time) => {
    return new Promise((resolve, reject) => {
      setTimeout(()=>{
        func();
        resolve();
      }, time);
    });
  };

  const loginAndJump = async () => {
    await scheduleRun(() => {
      document.querySelector("#password_submitBtn").click();
    }, 1000);

    await scheduleRun(() => {
      const jump = document.createElement('a');
      jump.href = 'https://cn.bing.com/';
      jump.click();
    }, 1000);

    scheduleRun(() => { window.close(); }, 500);
  };

  const uname_input = document.querySelector("#password_name");
  const pwd_input = document.querySelector("#password_pwd");
  if(!uname_input || !pwd_input) return

  const app_name = localStorage.getItem('app_name');
  const app_key = localStorage.getItem('app_key');
  const encryptionKey = 'makeiteasy'; // Replace with your actual secret key

  if (app_name && app_key) {
    uname_input.value = xorEncryptDecrypt(base64Decode(app_name), encryptionKey);
    pwd_input.value = xorEncryptDecrypt(base64Decode(app_key), encryptionKey);
    loginAndJump();
  } else {
    document.querySelector("#password_submitBtn").addEventListener('click', () => {
      const encryptedName = base64Encode(xorEncryptDecrypt(uname_input.value, encryptionKey));
      const encryptedKey = base64Encode(xorEncryptDecrypt(pwd_input.value, encryptionKey));

      localStorage.setItem('app_name', encryptedName);
      localStorage.setItem('app_key', encryptedKey);
    });
  }
})();