自动登录和切换账号,带有手动切换按钮
当前为
// ==UserScript==
// @name RawChat 自动账号登录
// @namespace https://www.runningcheese.com
// @version 1.0
// @description 自动登录和切换账号,带有手动切换按钮
// @author Kai, RunningCheese
// @match https://chat.rawchat.cc/login
// @icon https://t1.gstatic.cn/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&size=32&url=https://chat.rawchat.cc
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 初始账号列表
let accounts = JSON.parse(localStorage.getItem('accounts')) || [
'[email protected]:80979852851y',
'[email protected]:Soccerisgr8!',
'[email protected]:Michael01!',
// 添加更多账号
];
// 获取当前账号索引
let currentAccountIndex = parseInt(localStorage.getItem('currentAccountIndex') || '0', 10);
function fillCredentials(account) {
const [username, password] = account.split(':');
// 输入用户名和密码
document.querySelector('input[name="username"]').value = username;
document.querySelector('input[name="password"]').value = password;
document.querySelector('input[name="password"]').dispatchEvent(new Event('input', { bubbles: true })); // 触发事件确保密码框填入
// 模拟按下Enter键以实现自动登录
document.querySelector('input[name="password"]').dispatchEvent(new KeyboardEvent('keydown', {key: 'Enter', bubbles: true}));
}
function switchAccount() {
currentAccountIndex++;
if (currentAccountIndex >= accounts.length) {
currentAccountIndex = 0; // 循环使用账号
}
localStorage.setItem('currentAccountIndex', currentAccountIndex);
fillCredentials(accounts[currentAccountIndex]);
}
function addSwitchButton() {
const button = document.createElement('button');
button.innerText = '切换账号';
button.style.cssText = 'max-width: 320px;margin-bottom: 10px;padding: 8px 15px;border: none;border-radius: 6px;color: white;cursor: pointer;font-size: 16px;width: 100%;text-align: center;background-color: #28a745;position: fixed;left: 50%;top: 50%;transform: translate(-50%, -50%);';
button.style.position = 'fixed';
button.style.top = '25px';
button.style.right = '40%';
button.style.zIndex = 1000;
button.addEventListener('click', handleButtonClick);
document.body.appendChild(button);
}
function addAccountButton() {
const button = document.createElement('button');
button.innerText = '添加账号';
button.style.cssText = 'max-width: 320px;margin-bottom: 10px;padding: 8px 15px;border: none;border-radius: 6px;color: white;cursor: pointer;font-size: 16px;width: 100%;text-align: center;background-color: #007bff;position: fixed;left: 50%;top: 50%;transform: translate(-50%, -50%);';
button.style.position = 'fixed';
button.style.top = '65px';
button.style.right = '40%';
button.style.zIndex = 1000;
button.addEventListener('click', showAddAccountForm);
document.body.appendChild(button);
}
function showAddAccountForm() {
const form = document.createElement('div');
form.style.position = 'fixed';
form.style.top = '170px';
form.style.right = '44%';
form.style.padding = '20px';
form.style.zIndex = 1000;
form.style.display = 'flex';
form.style.flexDirection = 'column';
form.style.alignItems = 'center'; // 水平居中
const accountLabel = document.createElement('label');
accountLabel.style.marginBottom = '10px'; // 增加下方间距
const accountInput = document.createElement('input');
accountInput.type = 'text';
accountInput.style.cssText = 'max-width: 320px;margin-bottom: 10px;padding: 8px 15px;border-radius: 6px;cursor: pointer;font-size: 16px;width: 100%;text-align: center;position: fixed;left: 50%;top: 5%;transform: translate(-50%, -50%);';
accountInput.style.top = '110px';
accountInput.style.width = '320px';
accountInput.style.height = '40px';
accountInput.style.borderRadius = '7px';
accountInput.style.marginBottom = '10px'; // 增加下方间距
accountInput.placeholder = '格式: username:password'; // 设置占位符
const saveButton = document.createElement('button');
saveButton.innerText = '保存';
saveButton.style.cssText = 'max-width: 320px;margin-bottom: 10px;padding: 8px 15px;border: none;border-radius: 6px;color: white;cursor: pointer;font-size: 16px;width: 100%;text-align: center;background-color: #ffc107;position: fixed;left: 50%;top: 5%;transform: translate(-50%, -50%);';
saveButton.style.top = '160px';
saveButton.style.width = '320px';
saveButton.addEventListener('click', () => {
const newAccount = accountInput.value;
accounts.push(newAccount);
localStorage.setItem('accounts', JSON.stringify(accounts));
document.body.removeChild(form);
});
form.appendChild(accountLabel);
form.appendChild(accountInput);
form.appendChild(saveButton);
document.body.appendChild(form);
}
function handleButtonClick() {
const currentURL = window.location.href;
if (currentURL.includes('https://chat.rawchat.cc/login')) {
switchAccount();
} else if (currentURL === 'https://chat.rawchat.cc/') {
currentAccountIndex++;
if (currentAccountIndex >= accounts.length) {
currentAccountIndex = 0; // 循环使用账号
}
localStorage.setItem('currentAccountIndex', currentAccountIndex);
window.open('https://chat.rawchat.cc/login', '_blank');
}
}
window.addEventListener('load', () => {
const currentURL = window.location.href;
if (currentURL.includes('https://chat.rawchat.cc/login')) {
fillCredentials(accounts[currentAccountIndex]);
}
addSwitchButton();
addAccountButton();
});
})();