// ==UserScript== // @name 一款草率的V2EX右侧一键签到UI // @namespace http://tampermonkey.net/ // @version 0.1.1 // @description 网站右侧显示签到UI, 无需跳转直接签到成功 // @author echo // @match *://*.v2ex.com/* // @icon https://www.google.com/s2/favicons?sz=64&domain=v2ex.com // @grant none // @require https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js // @license GNU GPLv3 // @downloadURL none // ==/UserScript== (function() { 'use strict'; $(function(){ if(window.location.pathname=='/mission/daily')return; let position=$('#Rightbar .box:eq(0) .cell:eq(2)'); if(position==null)return; let code=0; let url=""; let before={txt:'签 到',c1:'#9EEB80',c2:'#90CC78'}; let after={txt:'今日已签到',c1:'#EBA380',c2:'#EBA380'}; let bar=$(`
`); let aFather=bar.children(); let a=aFather.children(); position.after(bar); let xhr=new XMLHttpRequest(); let div=document.createElement('div'); xhr.onload=function(e){ let cnt=new RegExp(".*<\/body>","is").exec(xhr.response); div.innerHTML=cnt; let btn=div.querySelector('#Main input'); if(btn==null||btn.value=="查看我的账户余额"){refresh(after);stopA();return;}else{refresh(before);} let txt=btn.getAttribute('onclick'); code=new RegExp("(?<=once=)\\d{5}").exec(txt)[0]; url=`/mission/daily/redeem?once=${code}`; a.one('click',function(e){$.get(url,function(rs){refresh(after)});setTimeout(()=>{stopA();},10);}); } xhr.open('get','/mission/daily'); xhr.send(); function refresh(signin){ a.html(signin.txt); aFather.css('backgroundColor',signin.c1); aFather.hover(function(){$(this).css('backgroundColor',signin.c2)},function(){$(this).css('backgroundColor',signin.c1)}); } function stopA(){ a.attr('href','/mission/daily'); } }); })();