Tieba Sign

贴吧签到

当前为 2014-10-18 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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.4
// @description	贴吧签到
// @homepageURL	http://geraldl.net/userjs/TiebaSign
// @include	http://tieba.baidu.com/*
// @exclude	http://tieba.baidu.com/tb/*
// @require	https://greasyfork.org/scripts/144/code.user.js
// @grant none
// ==/UserScript==

function main(ihome){
/*
 * 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.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=ihome.forumGroup._forumArr,i,
			c=$('<button>').appendTo('.ihome_title').click(showOptions).html('签到设置');
	init();
}
if(PageData&&PageData.user&&PageData.user.is_login) {
	if(ihome&&$('.userinfo_scores').length) hSign();
	else if(utils.getObj('sign',true)&&!PageData.user.is_black) visitSign($('#sign_mod .j_cansign'));
}
}
main(unsafeWindow.ihome);

// 设置
function showOptions(e){
	e.stopPropagation();
	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);
		},
	});
}