Created
July 25, 2017 00:37
-
-
Save anonymous/454736ca5aff3cb5ba597c171dc943ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
if( location.hostname.indexOf('v2ex.com')+1 ) | |
{ | |
var list = function(nodelist){return Array.prototype.slice.call(nodelist);}; | |
['DOMNodeInserted', 'DOMContentLoaded'].forEach(function(str){ | |
window.addEventListener(str, function(e){ | |
if( e.target.nodeType % 8 != 1 ) return; | |
// 处理每个楼层 | |
list( e.target.querySelectorAll('div.cell[id^="r_"]') ).forEach(function(cell){ | |
// 只在楼层第一次插入时处理,人工插楼后忽略 | |
if( cell.parentNode.className != 'box' ) return; | |
// bbs 风格回复盖楼 | |
window.building = window.building || [] ; | |
window.building.unshift(cell); | |
var members = list( cell.querySelectorAll('.reply_content a[href^="/member/"]') ); | |
if( members.length != 1 ) return; | |
// 回复单个人的会话,插入被回复人最近的楼层 | |
window.building.some(function(e, idx){ | |
// 第一个元素为刚保存的自身,不和自身比较 | |
if( idx && e.querySelector('a[href^="/member/"]').href == members[0].href ) | |
{ | |
cell.style = 'border-bottom-width:0;border-top:1px solid #E2E2E2;'; | |
var reply_content = e.querySelector('.reply_content'); | |
reply_content.style = 'padding:5px 0 15px;'; | |
return reply_content.insertAdjacentElement( 'afterend' , cell ); | |
} | |
}); | |
}); | |
}); | |
}); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment