米游社 原神 签到 (无需再次打开米游社)
// ==UserScript==
// @name 米游社 原神 签到 (无需再次打开米游社)
// @namespace https://space.bilibili.com/52159566
// @version 0.2
// @description 如果米游币整不了感觉应该整个水经验的
// @author 苏芣苡
// @match *://*/*
// @icon https://q.qlogo.cn/g?b=qq&s=100&nk=318328258
// @require https://cdn.jsdelivr.net/npm/js-md5@0.7.3/build/md5.min.js
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_registerMenuCommand
// @grant GM_notification
// @connect api-takumi.mihoyo.com
// @connect bbs-api.mihoyo.com
// @run-at document-end
// @grant unsafeWindow
// @license MIT
// ==/UserScript==
function ds() {
var s = 'h8w582wxwgqvahcdkpvdhbh2w9casgfl'
var t = Math.floor(Date.now() / 1000)
var r = Math.random().toString(36).slice( - 6)
var c = 'salt=' + s + '&t=' + t + '&r=' + r
var ds = t + ',' + r + ',' + md5(c)
return ds
}
var headers = {
'Referer': 'https://bbs.mihoyo.com/',
'DS': ds(),
'x-rpc-app_version': '2.3.0',
'x-rpc-client_type': '5',
'x-rpc-device_id': 'bd7f912e-908c-3692-a520-e70206823495',
}
function Multiline(string) {
var str = string.toString().split('\n')
return str.slice(1, str.length - 1).join('\n')
}
function su_style() {/*
#Su-1_kawaii{
position: fixed;
z-index: 999999999;
height: 100%;
width: 100%;
top: 0;
left: 0;
background: #44444488;
}
#Su-1_Out{
position: absolute;
z-index: 80;
height: 200px;
width: 660px;
margin-top: -100px;
margin-left: -330px;
top: 50%;
left: 50%;
background: #4e6ef2e8;
border-radius: 20px;
justify-content: center;
padding-top: 50px;
}
#Su-1_In{
height: 100%;
width: 100%;
line-height: 40px;
text-align: center;
cursor: pointer;
font-size: 24px;
text-shadow: #000 1px 0 0, #000 0 1px 0, #000 -1px 0 0, #000 0 -1px 0;
color: #fff;
}
#Su-1_kawaii a {
text-decoration: none;
color: #f00;
}
*/}
GM_addStyle(Multiline(su_style))
function ShowToast(str, s) {
var ele = '<div id="Su-1_kawaii"><div id="Su-1_Out"><div id="Su-1_In">' + str + '</div></div></div>'
let toast = document.createElement('su')
toast.innerHTML = ele
document.querySelector('body').append(toast)
if (s > 0) {
setInterval(function() { toast.remove() },s * 1000)
}
}
var host = window.location.href
var mihoyo = "bbs.mihoyo.com"
var ysweb = host.indexOf(mihoyo)
var ysurl = "https://bbs.mihoyo.com/ys/"
var date = new Date()
var today = date.toLocaleDateString()
var data, uid, region, region_name, nickname, level, message
GM_registerMenuCommand('再整一个号!',function(){GM_setValue('SignState','苏芣苡')})
GM_registerMenuCommand('加个关注呗!', function(){ window.open("https://space.bilibili.com/52159566")})
if (GM_getValue('SignState', '苏芣苡') != today) {
GM_xmlhttpRequest({
url: "https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie?game_biz=hk4e_cn",
method: "GET",
onload: function(xhr) {
var json = JSON.parse(xhr.responseText)
if (json.retcode !== 0) {
if (ysweb < 0) {
GM_notification({
title: "[米游社 原神签到]\n帐号未登录!",
text: "点击前往登录!",
ondone: () =>{ window.open(ysurl) },
})
ShowToast('[米游社 原神签到]<br>帐号未登录!<br><a target="_blank" href=' + ysurl + '>点击前往登录!</a>', 5)
} else {
GM_notification({
title: "[米游社 原神签到]\n帐号未登录!",
text: "请登录帐号!",
})
ShowToast('[米游社 原神签到]<br>帐号未登录!<br>请登录帐号!', 1)
}
} else {
var list = json.data.list
for (var i in list) {
uid = json.data.list[i].game_uid
region = json.data.list[i].region
region_name = json.data.list[i].region_name
nickname = json.data.list[i].nickname
level = json.data.list[i].level
data = '{"act_id":"e202009291139501","region":"' + region + '","uid":"' + uid + '"}'
/*----------------------------------------------------------------------------------------------*/
GM_xmlhttpRequest({
url: 'https://api-takumi.mihoyo.com/event/bbs_sign_reward/sign',
method: 'POST',
data: data,
headers: headers,
onload: function(xhr) {
var json = JSON.parse(xhr.responseText)
message = json.message
if (message == "OK") {
message = "今日打卡完成!"
}
var tips = '【' + region_name + '】[ Lv : ' + level + ']<br>[UID : ' + uid + ']【' + nickname + '】<br>' + message
GM_notification({
title: "[米游社 原神签到]\n签到成功!!",
text: '【' + region_name + '】[ Lv : ' + level + ']\n[UID : ' + uid + ']【' + nickname + '】\n' + message,
})
ShowToast(tips, 3)
GM_setValue('SignState', today)
}
})
/*----------------------------------------------------------------------------------------------*/
}
}
}
})
}