Skip to content

Instantly share code, notes, and snippets.

@codexss
Last active June 15, 2022 08:01
Show Gist options
  • Save codexss/fe332138c82e00220431d6c218ce9d2a to your computer and use it in GitHub Desktop.
Save codexss/fe332138c82e00220431d6c218ce9d2a to your computer and use it in GitHub Desktop.
v2ex.user.js
// ==UserScript==
// @name V2EX 助手
// @description 为V2EX添加自动签到、自动解析图片链接等功能
// @include https://*.v2ex.com/*
// @include https://v2ex.com/*
// @grant none
// ==/UserScript==
//自动签到 代码来自caoyue@v2ex
(function(){
var load, execute, loadAndExecute;
load = function(a, b, c) {
var d;
d = document.createElement("script"), d.setAttribute("src", a), b != null && d.addEventListener("load", b), c != null && d.addEventListener("error", c), document.body.appendChild(d);
return d;
}, execute = function(a) {
var b, c;
typeof a == "function" ? b = "(" + a + ")();" : b = a, c = document.createElement("script"), c.textContent = b, document.body.appendChild(c);
return c;
}, loadAndExecute = function(a, b) {
return load(a, function() {
return execute(b);
});
};
loadAndExecute("//lib.sinaapp.com/js/jquery/2.0/jquery.min.js", function() {
if ( !$("a[href='/signup']").length && !$("a[href='/signin']").length && document.body.innerHTML.indexOf(";<\/span> 创建新回复<\/div>") == -1 ) {
var uid=$.find('a[href^="/member/"]')[0].innerHTML;//用户名
var dateinfo=new Date().getUTCDate();//获得GMT时间今天几号
var SigninInfo=uid + ":" + dateinfo + "";
var daily = $('input[id="search"]');
if (daily.length && localStorage.SigninInfo != SigninInfo ) {
$.ajax({url:"/"});
daily.val("正在检测每日签到状态...");
$.ajax({
url: "/mission/daily",
success: function(data) {
var awards = $(data).find('input[value^="领取"]');
if (awards.length) {
// daily.val("正在" + awards.attr("value") + "...");
daily.val("正在领取今日的登录奖励......");
$.ajax({
url: awards.attr('onclick').match(/(?=\/).+?(?=\')/),
success: function(data) {
daily.val("正在提交...");
var days=data.split("已连续登")[1].split(" ")[1];
if ( $('a[href="/mission/daily"]').length==1 ) {$('a[href="/mission/daily"]').parent().parent().fadeOut(3000);}
$.ajax({
url: "/balance",
success: function(data) {
function p(s) {return s < 10 ? '0' + s: s;} //自动补0
var date2="" + new Date().getUTCFullYear() + p(new Date().getUTCMonth()+1) +p(new Date().getUTCDate());
if (data.indexOf(date2+" 的每日登录奖励")!="-1") {
daily.val( "已连续领取" + days + "天,本次领到" + data.split("每日登录")[2].split(" ")[1] + "铜币" );
localStorage.SigninInfo = SigninInfo;
} else {
daily.val( "自动领取遇到意外,你可以试试手动领。" );
}
}
});
},
error: function() {
daily.val("网络异常 :(");
}
});
}else{
if (data.indexOf("已领取") != -1) {
daily.val("今日奖励领取过了");
localStorage.SigninInfo = SigninInfo;
} else {
daily.val("无法辩识领奖按钮 :(");
}
}
},
error: function() {
daily.val("请手动领取今日的登录奖励!");
}
});
} else {
//console.log("");
}
}
});
})();
//新浪图床的图片反防盗链
(function (){
var images = document.images;
for (var i=0;i<images.length;i++){
var image = images[i];
if ( image.src && image.src.indexOf(".sinaimg.cn")!=-1 &&image.src.indexOf(".sinaimg.cn")<13 ) {
image.setAttribute("referrerPolicy","no-referrer");
image.src=image.src + "?";
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment