// ==UserScript==
// @name 生财有术航海实战证书获取-路人甲乙丙
// @namespace iblogc
// @version 1.3
// @description 支持获取自己或其它人参与过的所有历史航海的每天证书(问题反馈联系微信Byte4Me)
// @author 路人甲乙丙
// @match *://scys.com/*
// @license Apache License, Version 2.0
// @grant GM_xmlhttpRequest
// ==/UserScript==
"use strict";!function(){function e(e){try{var t=e.split(".")[1],o=t.replace(/-/g,"+").replace(/_/g,"/"),r=decodeURIComponent(atob(o).split("").map(function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)}).join(""));return JSON.parse(r)}catch(e){return console.error("JWT 解码失败:",e),null}}var t=localStorage.getItem("__user_token.v3");if(null!==t){var o=function(t){try{return e(t).number}catch(e){return console.error("解析__user_token.v3时出错:",e),null}}(t);if(null!==o){console.log("从__user_token.v3中获取的userid为:",o);var r=document.createElement("button");r.innerHTML="👉 获取航海实战证书",r.style.position="fixed",r.style.bottom="20px",r.style.right="20px",r.style.padding="10px 10px",r.style.backgroundColor="#006659",r.style.color="#fff",r.style.border="none",r.style.borderRadius="5px",r.style.cursor="pointer",r.onclick=function(){var e=new URLSearchParams(window.location.search),r=e.get("id");if(null==r&&(r=e.get("activity_id")),null===r||!window.location.href.startsWith("https://scys.com/mobile/activity/landing")&&!window.location.href.startsWith("https://scys.com/activity/landing"))return void alert("请进入航海实战页面后再点击获取");console.log("当前页面中的activity_id为:",r);var n=prompt("请输入生财编号(默认为当前登录用户生财编号):",o);if(null!==n){var s=n.trim()||o,l={form:{activity_id:r},page:1,perPage:10},a={method:"POST",headers:{"Content-Type":"application/json","X-Token":t},data:JSON.stringify(l)};GM_xmlhttpRequest({method:a.method,url:"https://scys.com/search/activity/stage/ajax/search",headers:a.headers,data:a.data,onload:function(e){console.log("请求成功:",e.responseText);var o=JSON.parse(e.responseText),n=o.data.items[0].stage_id;console.log("从响应数据中获取的stage_id为:",n);var l="https://scys.com/search/activity/project/submit/poster?id="+r+"&number="+s+"&stage="+n;GM_xmlhttpRequest({method:"GET",url:l,headers:{"X-Token":t},onload:function(e){if(console.log("获取图片结果:",e.responseText),null==JSON.parse(e.responseText).data)return void alert("获取数据异常,请检查输入的生财编号是否正确,或确认此编号是否有参加此航海。");var o=JSON.parse(e.responseText).data.poster,l=document.createElement("div");l.style.position="fixed",l.style.top="0",l.style.left="0",l.style.width="100%",l.style.height="100%",l.style.backgroundColor="rgba(0, 0, 0, 0.7)",l.style.zIndex="9999";var a=document.createElement("img");a.src=o,a.style.position="absolute",a.style.top="50%",a.style.left="50%",a.style.transform="translate(-50%, -50%)",a.style.maxWidth="30%",l.onclick=function(e){e.target===l&&(document.body.removeChild(l),document.body.removeChild(i),dayButtons.forEach(function(e){return document.body.removeChild(e)}))},l.appendChild(a),document.body.appendChild(l);var i=document.createElement("button");i.innerHTML="🚀 获取逐天证书",i.style.position="fixed",i.style.bottom="60px",i.style.right="20px",i.style.padding="10px 10px",i.style.backgroundColor="#006659",i.style.color="#fff",i.style.border="none",i.style.borderRadius="5px",i.style.cursor="pointer",i.onclick=function(){GM_xmlhttpRequest({method:"GET",url:"https://scys.com/search/activity/stage?activity_id="+r,headers:{"X-Token":t},onload:function(e){console.log("获取逐天证书结果:",e.responseText);var o=[],a=[];if(null==JSON.parse(e.responseText).data)for(var i=1;i<=21;i++)o.push(n+i-21);else{a=JSON.parse(e.responseText).data.project;for(var c=0;c<21;c++)o.push(a[0]+c)}var d=[],p=0;o.slice().reverse().forEach(function(e,n){var i=document.createElement("button");if(i.innerHTML="第"+(o.length-n)+"天",i.style.position="fixed",i.style.bottom=70+30*(n+1)+"px",i.style.right="20px",i.style.padding="5px 10px",i.style.backgroundColor="#006659",i.style.color="#fff",i.style.border="none",i.style.borderRadius="5px",i.style.cursor="pointer",a.includes(e)){var c=" ("+(a.length-p++)+"/21)";i.textContent+=c}i.onclick=function(){GM_xmlhttpRequest({method:"GET",url:"https://scys.com/search/activity/project/submit/poster?id="+r+"&number="+s+"&stage="+e,headers:{"X-Token":t},onload:function(e){console.log("获取第",o.length-n,"天图片成功:",e.responseText);var t=JSON.parse(e.responseText).data.poster,r=document.createElement("div");r.style.position="fixed",r.style.top="0",r.style.left="0",r.style.width="100%",r.style.height="100%",r.style.backgroundColor="rgba(0, 0, 0, 0.7)",r.style.zIndex="9999";var s=document.createElement("img");s.src=t,s.style.position="absolute",s.style.top="50%",s.style.left="50%",s.style.transform="translate(-50%, -50%)",s.style.maxWidth="30%",r.onclick=function(e){e.target===r&&l.removeChild(r)},r.appendChild(s),l.appendChild(r),document.body.appendChild(l)},onerror:function(e){console.error("获取第",n+1,"天图片失败:",e)}})},d.push(i),l.appendChild(i),document.body.appendChild(l)})},onerror:function(e){console.error("获取逐天证书失败:",e)}})},l.appendChild(a),l.appendChild(i),document.body.appendChild(l)},onerror:function(e){console.error("获取图片失败:",e)}})},onerror:function(e){console.error("请求失败:",e)}})}},document.body.appendChild(r)}else console.log("无法解析userid,__user_token.v3的值可能不是有效的JWT")}else console.log("__user_token.v3 的值不存在")}();