Tieba Sign

贴吧签到

目前為 2014-07-13 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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.2
// @description	贴吧签到
// @homepageURL	http://geraldl.ml/userjs/TiebaSign
// @include	http://tieba.baidu.com/*
// @exclude	http://tieba.baidu.com/tb/*
// @require	https://greasyfork.org/scripts/144/code.user.js
// @grant GM_registerMenuCommand
// ==/UserScript==

function main(utils,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.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;
	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'));
}
}
if(firefox) injectScript(main.toString(),['ihome']); else main(utils,unsafeWindow.ihome);

// 设置
function showOptions(utils){
	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);
		},
	});
}
GM_registerMenuCommand('签到脚本设置',function(){
	if(firefox) injectScript(showOptions.toString()); else showOptions(utils);
});