Tieba Sign

贴吧签到

נכון ליום 21-06-2014. ראה הגרסה האחרונה.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name	Tieba Sign
// @namespace	http://gera2ld.blog.163.com/
// @author	Gerald <[email protected]>
// @icon	http://s.gravatar.com/avatar/a0ad718d86d21262ccd6ff271ece08a3?s=80
// @version	1.3.4.1
// @description	贴吧签到
// @homepage	http://geraldl.ml/userjs/TiebaSign
// @include	http://tieba.baidu.com/*
// @exclude	http://tieba.baidu.com/tb/*
// @require	https://greatest.deepsurf.us/scripts/144/code.user.js
// ==/UserScript==

/*
 * 0: 签到成功
 * 1: 已签到
 * 2: 未开通签到
 * 3: 网络错误
 * 4: 未知错误
 */
// 模拟WAP签到
function wapSign(n,callback){
	var R={err:4};
	function error(){R.err=3;R.msg='网络错误';callback(R);}
	$.get('/mo/?kw='+encodeURIComponent(n)+'&ie=utf-8',function(d){
		var m,s;
		if(s=d.match(/<(\w+) style="text-align:right;">(.*?)<\/\1>/)) {
			if(s=s[2]) {
				if(m=s.match(/<a href="(.*?)">签到<\/a>/))
					return $.get(m[1].replace(/&amp;/g,'&'),function(d){
						if(m=d.match(/<span class="light">(.*?)<div/)) {
							R.msg=m[1].replace(/<[^>]*>/g,'');
							if(/^签到成功/.test(R.msg)) R.err=0;
						}
						callback(R);
					},'html').fail(error);
				if(s.match(/<span >已签到<\/span>/)) {R.err=1;R.msg='已签到';}
			} else R.err=2;
		}
		callback(R);
	},'html').fail(error);
}
// 普通签到
function htmlSign(n,callback){
	var R={err:4};
	function error(){R.err=3;R.msg='网络错误';callback(R);}
	$.get('/f?kw='+encodeURIComponent(n)+'&ie=utf-8',function(d){
		var r=d.match(/"is_sign_in":(\d+),"user_sign_rank":(\d+),/);
		if(r&&r[1]=='1') {
			R.err=0;R.msg='签到成功,排名'+r[2];
		} else if(r=d.match(/PageData\.tbs = "(.*?)";/))
			return $.post('/sign/add',{ie:'utf-8',kw:n,tbs:r[1]},function(r) {
				if(!r.no) {
					R.err=0;R.msg='签到成功,排名'+r.data.uinfo.user_sign_rank;
				} else R.msg=r.no+': '+r.error;
				callback(R);
			},'json').fail(error);
		callback(R);
	},'html').fail(error);
}
// 访问时自动签到
function visitSign(j){
	if(j.length&&!$('#balv_dolike').length) {	// “喜欢”才签到
		if(utils.getObj('wap',true))
			wapSign(PageData.forum.name,function(d){
				if(d.err) return;
				j.removeClass('j_cansign signstar_btn').addClass('signstar_signed').html(function(i,o){return '<span class="sign_keep_span">WAP成功</span>'+o;});
				$('#signstar_wrapper').addClass('signstar_wrapper_signed sign_box_bright_signed');
			});
		else $('.j_cansign').click();
	}
}
// 从贴吧个人中心自动签到所有爱逛的贴吧
function hSign(){
	function init(){
		b.prop('disabled',false);
		b.html('全部签到');
	}
	function work(){
		b.prop('disabled',true);
		b.html('正在签到...');
		i=0;sign();
	}
	function mark(r){
		var o=$('a.unsign[data-fid='+a[i].forum_id+']');
		if(r.err>1) {
			if(r.err==2) {r.color='blue';r.msg='未开通签到';}
			else {r.color='red';r.msg=r.msg||'未知错误';}
		} else {
			a[i].is_sign=1;o.removeClass('unsign').addClass('sign');
		}
		o.prop('title',r.msg);i++;setTimeout(sign,1000);
	}
	function sign(){
		var o;
		while((o=a[i])&&o.is_sign) i++;
		if(!o) return init();
		b.html('正在签到...'+o.forum_name);
		(utils.getObj('wap',true)?wapSign:htmlSign)(o.forum_name,mark);
	}
	var b=$('<button>').appendTo('.ihome_title').click(work),
			a=unsafeWindow.ihome.forumGroup._forumArr,i;
	init();
}
// 设置
function showOptions(){
	utils.popup.show({
		html:'\
<h3>设置 - 百度贴吧签到脚本</h3>\
<label><input type=checkbox id=gs_wap>模拟WAP签到</label><br>\
<label><input type=checkbox id=gs_sign>访问已关注的贴吧时自动签到</label><br>\
',
		className:'ge_opt',
		init:function(d){
			utils.bindProp($(d).find('#gs_wap'),'checked','wap',true);
			utils.bindProp($(d).find('#gs_sign'),'checked','sign',true);
		},
	});
}

if(PageData&&PageData.user&&PageData.user.is_login) {
	GM_registerMenuCommand('签到脚本设置',showOptions);
	if(unsafeWindow.ihome&&$('.userinfo_scores').length) hSign();
	else if(utils.getObj('sign',true)&&!PageData.user.is_black) visitSign($('#sign_mod .j_cansign'));
}