Created
July 16, 2021 10:17
-
-
Save david-zw-liu/f83f2bff34fa43c9a2f50570ae00ffea to your computer and use it in GitHub Desktop.
tempermonkey script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Auto-Login Eyny | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Auto login for eyny site | |
// @author You | |
// @match *://*.eyny.com/* | |
// @require https://code.jquery.com/jquery-3.6.0.min.js | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
const username = 'username'; | |
const password = 'password'; | |
const interval = 3 * 1000; | |
const login = async () => { | |
const indexHTML = await $.get('/').promise(); | |
const $indexDOM = $(indexHTML); | |
const isLogin = $indexDOM.find('a:contains("退出")').length >= 1 | |
if (!isLogin) { | |
const loginHTML = await $.get('/member.php?mod=logging&action=login&referer=/index.php').promise(); | |
const $loginDOM = $(loginHTML); | |
const $loginForm = $loginDOM.find('form[name="login"]'); | |
const action = $loginForm.prop('action'); | |
$loginForm.find('input[name="username"]').val(username); | |
$loginForm.find('input[name="password"]').val(password); | |
const data = $loginForm.serialize(); | |
await $.ajax({ | |
type: 'POST', | |
url: action, | |
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, | |
contentType: 'application/x-www-form-urlencoded; charset=utf-8', | |
dataType: 'json', | |
data: data, | |
}).promise(); | |
} | |
} | |
const autoLogin = async () => { | |
await login(); | |
setTimeout(autoLogin, interval); | |
} | |
autoLogin(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment