// ==UserScript== // @name RawChat 账号池助手 // @namespace https://www.runningcheese.com // @version 1.4 // @description 自动登录和切换账号,让你实现 GPT-4o 自由。 // @author RunningCheese,Kai // @match https://chat.rawchat.cc/* // @icon https://t1.gstatic.cn/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&size=32&url=https://chat.rawchat.cc // @grant GM_xmlhttpRequest // @grant GM_log // @grant GM_setClipboard // @downloadURL none // ==/UserScript== (function() { 'use strict'; // 获取存储的账号信息 if (window.location.href.includes('https://chat.rawchat.cc/login')) { let accounts = JSON.parse(localStorage.getItem('accounts')) || []; let currentAccountIndex = parseInt(localStorage.getItem('currentAccountIndex') || '0', 10); // 检查是否有存储的账号信息,如果没有,提示用户输入 if (accounts.length === 0) { showAddAccountForm(); } else { checkAndAddButtons(); } 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 = Math.floor(Math.random() * accounts.length); // 随机使用账号 localStorage.setItem('currentAccountIndex', currentAccountIndex); fillCredentials(accounts[currentAccountIndex]); } function addSwitchButton() { const button = document.createElement('button'); button.id = 'switchAccountButton'; 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 = '35px'; button.style.right = '40%'; button.style.zIndex = 1000; button.addEventListener('click', handleButtonClick); document.body.appendChild(button); } function addAccountButton() { const button = document.createElement('button'); button.id = 'addAccountButton'; 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 = '80px'; 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 = '180px'; 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 = '130px'; accountInput.style.width = '320px'; accountInput.style.height = '40px'; accountInput.style.borderRadius = '7px'; accountInput.style.marginBottom = '10px'; // 增加下方间距 accountInput.placeholder = '格式 = 帐号:密码,多个账号用空格分隔'; // 设置占位符 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: #F23822;position: fixed;left: 50%;top: 5%;transform: translate(-50%, -50%);'; saveButton.style.top = '180px'; saveButton.style.width = '320px'; saveButton.addEventListener('click', () => { const newAccounts = accountInput.value; addMultipleAccounts(newAccounts); localStorage.setItem('accounts', JSON.stringify(accounts)); document.body.removeChild(form); showAlert('添加成功'); checkAndAddButtons(); }); form.appendChild(accountLabel); form.appendChild(accountInput); form.appendChild(saveButton); document.body.appendChild(form); } function addMultipleAccounts(newAccounts) { const accountArray = newAccounts.split(' ').filter(account => account.includes(':')); accountArray.forEach(account => { if (!accounts.includes(account)) { accounts.push(account); } }); } function handleButtonClick() { const currentURL = window.location.href; if (currentURL.includes('https://chat.rawchat.cc/login')) { if (accounts.length === 0) { showAlert('请先添加账号'); } else { switchAccount(); } } else if (currentURL === 'https://chat.rawchat.cc/') { currentAccountIndex = Math.floor(Math.random() * accounts.length); // 随机使用账号 localStorage.setItem('currentAccountIndex', currentAccountIndex); window.open('https://chat.rawchat.cc/login', '_blank'); } } function showAlert(message) { const alert = document.createElement('div'); alert.innerText = message; alert.style.cssText = 'position: fixed; top: 20px; left: 50%; transform: translateX(-50%); background-color: #F23822; color: white; padding: 10px 20px; border-radius: 5px; z-index: 9000; font-size: 16px;'; document.body.appendChild(alert); setTimeout(() => { document.body.removeChild(alert); }, 1500); } function checkAndAddButtons() { if (!document.getElementById('switchAccountButton')) { addSwitchButton(); } if (!document.getElementById('addAccountButton')) { addAccountButton(); } } window.addEventListener('load', () => { const currentURL = window.location.href; if (currentURL.includes('https://chat.rawchat.cc/login')) { if (accounts.length > 0) { fillCredentials(accounts[currentAccountIndex]); } } if (accounts.length > 0) { checkAndAddButtons(); } }); } })(); (function() { 'use strict'; // 新建一个按钮 if ( !window.location.href.includes('https://chat.rawchat.cc/login') && !window.location.href.includes('https://chat.rawchat.cc/v') && !window.location.href.includes('https://chat.rawchat.cc/fc') ) { function createButton() { const button = document.createElement('button'); button.innerHTML = 'New'; button.style.position = 'fixed'; button.style.top = '50px'; button.style.right = '20px'; button.style.width = '32px'; button.style.height = '32px'; button.style.borderRadius = '50%'; button.style.backgroundColor = '#007bff'; button.style.color = 'white'; button.style.border = 'none'; button.style.cursor = 'pointer'; button.style.zIndex = '9999'; button.style.boxShadow = '0px 4px 8px rgba(0, 0, 0, 0.2)'; button.style.fontSize = '12px'; button.style.fontWeight = '500'; button.style.textAlign = 'center'; button.style.lineHeight = '32px'; document.body.appendChild(button); button.addEventListener('click', function() { getAccessToken(); }); } // 获取 accessToken function getAccessToken() { GM_xmlhttpRequest({ method: "GET", url: "https://chat.rawchat.cc/api/auth/session", onload: function(response) { // Parse the response let jsonResponse = JSON.parse(response.responseText); // Check if accessToken is present if (jsonResponse.accessToken) { let accessToken = jsonResponse.accessToken; GM_log("AccessToken: " + accessToken); // Optionally, copy the accessToken to clipboard GM_setClipboard(accessToken); if (confirm("已复制 AccessToken 到剪贴板!\n是否要打开 https://new.oaifree.com ?")) { window.location.href = "https://new.oaifree.com/"; } } else { GM_log("AccessToken not found in the response."); } }, onerror: function(error) { GM_log("Error fetching the session API: " + error); } }); } window.onload = createButton; } })();