// ==UserScript==
// @name JableTV Automatic login
// @name:zh-CN JableTV 自动登录
// @description:zh-CN 检测 JableTV 状态,并且在未登录时自动登录
// @name:ar JableTV تسجيل الدخول التلقائي
// @description:ar كشف JableTV ولاية,وتسجيل الدخول تلقائيًا في حالة عدم تسجيل الدخول
// @name:bg JableTV Автоматично влизане
// @description:bg Откриване JableTV състояние,и автоматично влизане, когато не сте влезли
// @name:cs JableTV Automatické přihlášení
// @description:cs Detekce JableTV stát,a automaticky se přihlásit, když nejste přihlášeni
// @name:da JableTV Automatisk login
// @description:da Opdagelse JableTV tilstand,og logger automatisk på, når du ikke er logget ind
// @name:de JableTV Automatische Anmeldung
// @description:de Erkennung JableTV Zustand,und melden Sie sich automatisch an, wenn Sie nicht angemeldet sind
// @name:el JableTV Αυτόματη σύνδεση
// @description:el Ανίχνευση JableTV κατάσταση,και αυτόματα συνδέεστε όταν δεν είστε συνδεδεμένοι
// @name:en JableTV Automatic login
// @description:en Detection JableTV state,and automatically log in when not logged in
// @name:eo JableTV Aŭtomata ensaluto
// @description:eo Detekto JableTV stato,kaj aŭtomate ensalutu kiam ne ensalutinta
// @name:es JableTV Inicio de sesión automático
// @description:es Detección JableTV estado,e iniciar sesión automáticamente cuando no haya iniciado sesión
// @name:fi JableTV Automaattinen sisäänkirjautuminen
// @description:fi Havaitseminen JableTV osavaltio,ja kirjaudu sisään automaattisesti, kun et ole kirjautunut sisään
// @name:fr JableTV Connexion automatique
// @description:fr Détection JableTV État,et connectez-vous automatiquement lorsque vous n’êtes pas connecté
// @name:he JableTV כניסה אוטומטית
// @description:he איתור JableTV מְדִינָה,והתחבר אוטומטית כאשר לא מחובר
// @name:hr JableTV Automatska prijava
// @description:hr Otkrivanje JableTV stanje,i automatski se prijavite kada niste prijavljeni
// @name:hu JableTV Automatikus bejelentkezés
// @description:hu Érzékelés JableTV állami,és automatikusan bejelentkezik, ha nincs bejelentkezve
// @name:id JableTV Masuk otomatis
// @description:id Deteksi JableTV negara,dan secara otomatis login ketika tidak login
// @name:it JableTV Accesso automatico
// @description:it Rilevamento JableTV stato,e accedi automaticamente quando non sei loggato
// @name:ja JableTV 自動ログイン
// @description:ja 検出 JableTV 州,ログインしていない場合は自動的にログインします
// @name:ka JableTV ავტომატური შესვლა
// @description:ka გამოვლენა JableTV სახელმწიფო,და ავტომატურად შედით სისტემაში, როდესაც არ ხართ შესული
// @name:ko JableTV 자동 로그인
// @description:ko 발각 JableTV 상태,로그인하지 않으면 자동으로 로그인됩니다.
// @name:nl JableTV Automatisch inloggen
// @description:nl Detectie JableTV staat,en automatisch inloggen als je niet ingelogd bent
// @name:nb JableTV Automatisk pålogging
// @description:nb Oppdagelse JableTV tilstand,og logger automatisk på når du ikke er pålogget
// @name:pl JableTV Automatyczne logowanie
// @description:pl Wykrywanie JableTV państwo,i automatycznie loguj się, gdy nie jesteś zalogowany
// @name:pt-BR JableTV Login automático
// @description:pt-BR Detecção JableTV estado,e faça login automaticamente quando não estiver conectado
// @name:ro JableTV Conectare automată
// @description:ro Detectare JableTV stat,și conectați-vă automat când nu sunteți autentificat
// @name:ru JableTV Автоматический вход
// @description:ru Обнаружение JableTV состояние,и автоматически входить в систему, когда вы не вошли в систему
// @name:sk JableTV Automatické prihlásenie
// @description:sk Detekcia JableTV štátu,a automaticky sa prihlásiť, keď nie ste prihlásení
// @name:sr JableTV Аутоматско пријављивање
// @description:sr Детецтион JableTV држава,и аутоматски се пријављује када нисте пријављени
// @name:sv JableTV Automatisk inloggning
// @description:sv Upptäckt JableTV ange,och logga in automatiskt när du inte är inloggad
// @name:th JableTV เข้าสู่ระบบอัตโนมัติ
// @description:th การตรวจจับ JableTV สถานะ,และเข้าสู่ระบบอัตโนมัติเมื่อไม่ได้เข้าสู่ระบบ
// @name:tr JableTV Otomatik giriş
// @description:tr Algılama JableTV durum,ve oturum açmadığınızda otomatik olarak oturum açın
// @name:ug JableTV ئاپتوماتىك كىرىش
// @description:ug بايقاش JableTV ئىشتات,ھەمدە كىرمىگەندە ئاپتوماتىك كىرىدۇ
// @name:uk JableTV Автоматичний вхід
// @description:uk виявлення JableTV стан,і автоматично ввійти, якщо ви не ввійшли
// @name:vi JableTV Đăng nhập tự động
// @description:vi Phát hiện JableTV tình trạng,và tự động đăng nhập khi chưa đăng nhập
// @name:zh-TW JableTV 自動登入
// @description:zh-TW 偵測 JableTV 狀態,並且在未登入時自動登入
// @name:zh-HK JableTV 自動登入
// @description:zh-HK 偵測 JableTV 狀態,並且在未登入時自動登入
// @name:fr-CA JableTV Connexion automatique
// @description:fr-CA Détection JableTV État,et connectez-vous automatiquement lorsque vous n’êtes pas connecté
// @description Detection JableTV state,and automatically log in when not logged in
// @namespace https://github.com/ChinaGodMan/UserScripts
// @author 人民的勤务员 <[email protected]>
// @match https://jable.tv/*
// @grant GM_registerMenuCommand
// @grant GM_setValue
// @grant GM_getValue
// @version 1.0.0.4
// @icon https://pic.616pic.com/ys_bnew_img/00/35/79/Gv93yQh7v6.jpg
// @supportURL https://github.com/ChinaGodMan/UserScripts/issues
// @homepageURL https://github.com/ChinaGodMan/UserScripts
// @license MIT
// ==/UserScript==
const translate = (function () {
const userLang = (navigator.languages && navigator.languages[0]) || navigator.language || 'en'
const strings = {
'en': {
Accountnull: 'Error: UserEmail or UserPassword is empty.',
loginSuccess: 'Login successful, refreshing the page.',
Networkfailed: 'Status code error.',
Loginfailed: 'Login failed, incorrect email or password. Check console for error details.',
},
'zh-CN': {
Accountnull: '邮箱或密码为空',
loginSuccess: '登录成功,即将刷新页面。',
Networkfailed: '状态码错误',
Loginfailed: '登录失败,邮箱或密码错误,可以在控制台查看错误信息。',
},
'zh-TW': {
Accountnull: '郵箱或密碼為空',
loginSuccess: '登錄成功,即將刷新頁面。',
Networkfailed: '狀態碼錯誤',
Loginfailed: '登錄失敗,郵箱或密碼錯誤,可以在控制台查看錯誤信息。',
},
'ja': {
Accountnull: 'エラー:メールアドレスまたはパスワードが空です。',
loginSuccess: 'ログイン成功、ページを更新します。',
Networkfailed: 'ステータスコードエラー',
Loginfailed: 'ログインに失敗しました。メールアドレスまたはパスワードが間違っています。エラーの詳細はコンソールで確認できます。',
},
'vi': {
Accountnull: 'Lỗi: Email hoặc mật khẩu trống.',
loginSuccess: 'Đăng nhập thành công, đang làm mới trang.',
Networkfailed: 'Lỗi mã trạng thái.',
Loginfailed: 'Đăng nhập không thành công, email hoặc mật khẩu không chính xác. Xem chi tiết lỗi trên bảng điều khiển.',
}
}
return (id, lang = '') => {
const selectedLang = lang || userLang
return (strings[selectedLang] || strings.en)[id] || strings.en[id]
}
}());
(function () {
'use strict'
var messages = []
let UserEmail = GM_getValue("UserEmail", "Woshindiaaaa")
let UserPassword = GM_getValue("UserPassword", "Woshindiaaaa")
var style = document.createElement('style')
GM_registerMenuCommand("Set Account", showuserInfoModal)
function showuserInfoModal() {
let modalHtml = `
<div id="userInfoModal" style="position: fixed; z-index: 10000; background: white; padding: 20px; border-radius: 8px; box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5); top: 20%; left: 50%; transform: translate(-50%, -20%); max-width: 300px;">
<h2 style="margin-top: 0;">Set Account </h2>
<div style="margin-bottom: 10px;">
<label for="UserEmail" style="display: block; margin-bottom: 5px;">UserEmail:</label>
<input id="UserEmail" style="width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px;" value="${UserEmail}" />
</div>
<div style="margin-bottom: 20px;">
<label for="UserPassword" style="display: block; margin-bottom: 5px;">UserPassword:</label>
<input id="UserPassword" style="width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px;" value="${UserPassword}" />
</div>
<div style="text-align: right;">
<button id="saveUserInfo" style="background-color: #4CAF50; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer;">Save</button>
<button id="closeUserModal" style="background-color: #f44336; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer; margin-left: 10px;">Close</button>
</div>
</div>`
let modalDiv = document.createElement('div')
modalDiv.innerHTML = modalHtml
document.body.appendChild(modalDiv)
document.getElementById("saveUserInfo").addEventListener("click", function () {
UserEmail = document.getElementById("UserEmail").value
UserPassword = document.getElementById("UserPassword").value
GM_setValue("UserEmail", UserEmail)
GM_setValue("UserPassword", UserPassword)
closeUserModal()
})
document.getElementById("closeUserModal").addEventListener("click", closeUserModal)
}
function closeUserModal() {
let modal = document.getElementById("userInfoModal")
if (modal) {
modal.remove()
}
}
function login(username, password) {
if (!username || !password) {
alert("xxx")
showMessage(translate('Accountnull'), 2000, '#000000', '#ffeb3b')
return
}
const formData = new URLSearchParams({
username: username,
pass: password,
remember_me: 1,
action: 'login',
email_link: 'https://jable.tv/email/',
format: 'json',
mode: 'async',
}).toString()
fetch('https://jable.tv/email/', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: formData,
})
.then(response => {
if (!response.ok) {
return response.text().then(text => {
console.error('Login error:', {
status: response.status,
statusText: response.statusText,
responseText: text,
})
showMessage('Login failed: ' + text, 2000, '#000000', '#ffeb3b')
throw new Error(translate('Networkfailed'))
})
}
if (response.headers.get('Content-Type')?.includes('application/json')) {
return response.json()
} else {
return response.text().then(text => {
console.error(translate('Loginfailed'), {
status: response.status,
statusText: response.statusText,
responseText: text,
})
showMessage(translate('Loginfailed'), 2000, '#000000', '#ffeb3b')
throw new Error(translate('Loginfailed'))
})
}
})
.then(data => {
console.log('Success:', data)
showMessage(translate('loginSuccess'), 2000, '#67c23a', '#f0f9eb')
setTimeout(function () {
location.reload()
}, 1000)
})
.catch(error => {
showMessage('An error occurred: ' + error.message, 2000, '#000000', '#ffeb3b')
})
}
function checkUserId() {
var scripts = document.getElementsByTagName('script')
var userIdPattern = /userId:\s*'(\d+)'/
var userIdFound = false
for (var i = 0; i < scripts.length; i++) {
var scriptContent = scripts[i].textContent
var match = scriptContent.match(userIdPattern)
if (match) {
var userId = match[1]
console.log("找到 userId:", userId)
if (userId) {
userIdFound = true
break
}
}
}
if (userIdFound) {
//已经登录
} else {
login(UserEmail, UserPassword)
}
}
checkUserId()
function createMessageStyles() {
const style = document.createElement('style')
style.type = 'text/css'
style.innerHTML = `
.message {
position: fixed;
left: 50%;
transform: translateX(-50%);
padding: 10px 20px;
border-radius: 4px;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
font-size: 14px;
z-index: 9999;
opacity: 0;
transition: opacity 0.5s ease, top 0.5s ease;
}
.message-show {
opacity: 1;
}
`
document.head.appendChild(style)
}
function showMessage(message, duration = 3000, textColor = '#67c23a', backgroundColor = '#f0f9eb') {
const messageDiv = document.createElement('div')
messageDiv.className = 'message'
messageDiv.innerText = message
messageDiv.style.color = textColor
messageDiv.style.backgroundColor = backgroundColor
document.body.appendChild(messageDiv)
const offset = messages.length * 50 + 20
messageDiv.style.top = `${offset}px`
getComputedStyle(messageDiv).opacity
messageDiv.classList.add('message-show')
messages.push(messageDiv)
setTimeout(() => {
messageDiv.classList.remove('message-show')
setTimeout(() => {
document.body.removeChild(messageDiv)
messages.splice(messages.indexOf(messageDiv), 1)
updateMessagePositions()
}, 500)
}, duration)
}
function updateMessagePositions() {
messages.forEach((msg, index) => {
const offset = index * 50 + 20
msg.style.top = `${offset}px`
})
}
createMessageStyles()
})()