﻿JERENCEVAR1=1;

if (document.location.href.indexOf('http://blog.yam.com/msg/')==0) {
JERENCETIMER1=setInterval("AddShowUnreplyButton()",1000)
}

function AddShowUnreplyButton() {
try{_rsCI;} catch(e) {return;}
if (JERENCEVAR1==0) {clearInterval(JERENCETIMER1);return;}
try{
var par=document.getElementById("systemAnnouncebyyam");
par.lastChild.lastChild.insertAdjacentHTML('afterBegin','<li><a id="JERENCEBLOCK2" href="javascript:ShowUnreply()">【☆留言】顯示本頁未回覆</a></li><li><a href="javascript:ShowAllMsg()">【☆留言】顯示全部未回覆</a></li>');
JERENCEVAR1=0;
} catch(e) {}

var url=document.location.href;
if(url.indexOf('&page=-1')>0 || url.indexOf('&s=1')>0) ShowUnreply();

}

function ShowUnreply() {
try{document.getElementById('JERENCEBLOCK1').outerHTML=='';} catch(e) {}
try{
var acc=document.location.href+'';
acc=acc.replace(/\/article\/\d+/,'');
acc=(document.location.href+'').split('/');
acc=acc[acc.length-1];
acc=acc.split('&');
acc=acc[0]
if (document.location.href.indexOf('http://blog.yam.com/msg/'+acc)==-1) {alert('必須先進到留言板才能使用!');return;}

t=document.getElementsByTagName('table');
ary=[];
ary2=[];
for(var i=0;i<t.length;i++) {
if (t[i].style.wordBreak=="break-all") {ary.push(t[i])}
}

for(var i=0;i<ary.length;i++) {
var rl=ary[i].rows.length-2;
var str=ary[i].rows.item(rl).cells.item(0).innerHTML;
var cond='"http://blog.yam.com/msg/'+acc+'"';

if (str.indexOf(cond)==-1) {
ary[i].rows.item(rl).id="JERENCEANCHOR"+i;
var dat=ary[i].rows.item(rl).cells.item(1).innerText;
var cont='<tr>'+ary[i].rows(rl+1).innerHTML+'</tr>';
var contback='<table><tr>'+cont+'</tr></table>';
var back='<a href="javascript:ScrollInto(\'M_JERENCEANCHOR'+i+'\')">｡*＊. ♡回目錄♡. ＊*｡</a>';
ary[i].rows.item(rl+1).cells.item(0).insertAdjacentHTML('beforeEnd','<br>'+back+'<hr>');
var nod2=ary[i].rows.item(rl);
var mor=0;
//var op=0;
//var brl='';
while(rl>1) {
rl-=2;
var str2=ary[i].rows.item(rl).cells.item(0).innerHTML;
if (str2.indexOf(cond)!=-1) break;
//if(op==0) {op=50;brl='<hr style="FILTER:alpha(opacity=30)">';} else {op=0;brl='';}
cont='<tr>'+ary[i].rows(rl+1).innerHTML+'</tr><tr><td colspan=2><br><table width=100% style="FILTER:alpha(opacity=30)"><tr style="vertical-align:top"><td width=50><hr></td><td width=50><pre><b>【補充】</b></pre></td><td><hr></td></tr></table></td></tr>'+cont;
nod2=ary[i].rows.item(rl);
mor++;
}
if (mor>0) {
cont="<tr><td><table border=1><tr><td>本串有【<u style='background-color:white;color:red'>"+mor+"</u>】篇補充<br>（最後補充時間："+dat+"）</td></tr><tr><td><b><u>最後一次補充的內容：</u></b><br>"+contback+"</td></tr></table></td></tr>"+cont;
}
nod2.id="JERENCEANCHOR"+i;
nod2.cells.item(0).insertAdjacentHTML('afterBegin','<hr>'+back+'<br>');
var go='<tr><td colspan=2><a href="javascript:ScrollInto(\'JERENCEANCHOR'+i+'\',true)">｡*＊. ♡前往該留言串♡. ＊*｡</a></td></tr>';
ary2.push([dat,'<table width="100%" style="word-break:break-all" id="M_JERENCEANCHOR'+i+'"><tr><td>'+str+'</td><td align="right" width="160">'+dat+'</td></tr>'+go+cont+go+'</table><hr>']);
}
}
ary2.sort();
var str='';
for(var i=ary2.length-1;i>-1;i--) str+=ary2[i][1];
if (str=='') str='<b style="font-size:22px">無未回覆留言^^</b><hr>';
var nod=document.createElement('div');
nod.innerHTML='<hr><div><b>未回覆留言：</b> <a href="javascript:Hide(\'JERENCEBLOCK1\',\'none\')"><u>縮小</u></a>　<a href="javascript:Hide(\'JERENCEBLOCK1\',\'\')"><u>還原</u></a>　｜　<a href="javascript:ShowAllMsg()"><u>顯示全部未回覆留言</u></a>　｜　<a href="http://blog.yam.com/jerence0512/article/16208161" target="_blank"><u>如何套用本程式到您的留言板</u></a><hr></div><div id="JERENCEBLOCK1">'+str+'</div>';
var par=document.getElementById("articleBlock");
par.insertBefore(nod,par.firstChild);

} catch(e) {}

try{
document.getElementById("JERENCEBLOCK2").outerHTML='<a href="javascript:Hide(\'JERENCEBLOCK1\',\'none\')"><u>☆縮小</u></a>　<a href="javascript:Hide(\'JERENCEBLOCK1\',\'\')"><u>☆還原</u></a>';
} catch(e) {}
}

function Hide(id,val) {
document.getElementById(id).style.display=val;
}

function ShowAllMsg() {
var acc=document.location.href+'';
acc=acc.replace(/\/article\/\d+/,'');
acc=(document.location.href+'').split('/');
acc=acc[acc.length-1];
acc=acc.split('&');
acc=acc[0]

document.location.href='http://blog.yam.com/msg/'+acc+'&page=-1';
}

function ScrollInto(id,val) {
document.getElementById(id).scrollIntoView(val)
}