Skip to content

Instantly share code, notes, and snippets.

@linusyu
Created August 28, 2014 10:02
Show Gist options
  • Save linusyu/6da0793d8d9aa732e2ee to your computer and use it in GitHub Desktop.
Save linusyu/6da0793d8d9aa732e2ee to your computer and use it in GitHub Desktop.
Tieba Sex
// ==UserScript==
// @name Tieba Sex
// @namespace http://tieba.baidu.com
// @include http://tieba.baidu.com/p/*
// @version 1
// @grant none
// ==/UserScript==
;(function($){
var cssText ='\
.userinfo_sex_male,.userinfo_sex_female {\
background-image: url("http://tb2.bdstatic.com/tb/static-ihome/img/icon_groups_26e15a2.png");\
display: inline-block;\
margin: 0 0 -2px 5px;\
height: 14px;\
width: 14px;}\
.userinfo_sex_female {background-position: 0 -63px;}\
.userinfo_sex_male {background-position: 0 -32px;}';
$(document.head).append("<style>" +cssText+ "</style>");
function sex(){
$(".l_post").each(function(){
if($(this).data("field").sex) return;
$(this).find(".d_name").append('<span class="' +
($(this).data("field").author.user_sex < 2 ?
'userinfo_sex_male' : 'userinfo_sex_female')+ '"></span>')
.end().data("field").sex ="1";
});
}
var MutationObserver = window.MutationObserver ||
window.WebKitMutationObserver || window.MozMutationObserver;
new MutationObserver(function(mutations) {
mutations.forEach(function() {
sex();
});
}).observe(document.querySelector("#j_p_postlist"),
{ attributes: true, childList: true, characterData: true });
sex();
})(unsafeWindow.jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment