// ==UserScript== // @name bahamut commend enhanced // @namespace http://userscripts/user // @include http://forum.gamer.com.tw/C.php?* // @include http://forum.gamer.com.tw/Co.php?* // @description 可調整巴哈姆特哈啦討論區留言的顯示順序(新留言在上或舊留言在上)、加入留言樓層數字、單獨開啟關閉某篇文章圖片影像 // @version 1.05.1 // @grant GM_getValue // @grant GM_setValue // @grant GM_addStyle // @downloadURL none // ==/UserScript== //滑鼠移上留言時背景底色變化 GM_addStyle(".FM-cbox10 p:hover { background-color : #eaeaea !important;}"); //記錄最後使用的留言排列順序 var BHCOA; var BHCO = GM_getValue("BHCO",false); var rk = GM_getValue("BHCO",false); var oldmoreCommend = unsafeWindow.moreCommend; var oldallCommend = unsafeWindow.allCommend; var oldcloseallCommend = unsafeWindow.closeallCommend; var oldforumShowAllMedia = unsafeWindow.forumShowAllMedia; //在原函式 moreCommend 中加入新功能 function moreCommend(bsn,snB,where){ var cptext = "Commendlist_"+snB; var cptmp = unsafeWindow.document.getElementById(cptext).getElementsByTagName("p"); var ntmp = parseInt(unsafeWindow.document.getElementById("showoldCommend_"+snB).innerHTML.substring(6)) + parseInt(unsafeWindow.document.getElementById("Commendlist5_"+snB).childNodes.length)-1; oldmoreCommend(bsn,snB,where); BHC1000Wait(cptmp,ntmp,snB); BHCOA = BHCO; } //在原函式 allCommend 中加入新功能 function allCommend(bsn,snB,where){ var cptext = "Commendlist_"+snB; var cptmp = unsafeWindow.document.getElementById(cptext).getElementsByTagName("p"); var ntmp = parseInt(unsafeWindow.document.getElementById(where).innerHTML.substring(6))+cptmp.length; if(unsafeWindow.document.getElementById(where).previousSibling) BHCWait(cptmp,ntmp,unsafeWindow.document.getElementById(where).previousSibling.firstChild.innerHTML.substring(5)); else if(BHCO) BHCWait(cptmp,ntmp,"↑"); else BHCWait(cptmp,ntmp,"↓"); oldallCommend(bsn,snB,where); BHCOA = BHCO; } //在原函式 closeallCommend 中加入新功能 function closeallCommend(bsn,snB,where){ oldcloseallCommend(bsn,snB,where); var cptext = "Commendlist_"+snB; var cptmp = unsafeWindow.document.getElementById(cptext).getElementsByTagName("p"); if(BHCO == BHCOA) CommendOrder(cptmp,false); else CommendOrder(cptmp,true); } //在原函式 forumShowAllMedia 中加入新功能 forumShowAllMedia = function (a){ GamerChangeAllBtnToClose(); return oldforumShowAllMedia(a); } //開啟超過1000則的舊留言,在讀取完留言後進行新功能 function BHC1000Wait(cps,num,snB){ if(unsafeWindow.document.getElementById("CommendMore_"+snB).style.display != "none") unsafeWindow.setTimeout(function(){BHC1000Wait(cps,num,snB)}, 50); else { var cptext = "Commendlist_"+snB; var cptmp = unsafeWindow.document.getElementById(cptext).getElementsByTagName("p"); var newnode; for(i=num-1000;i>0;i--){ newnode = unsafeWindow.document.createElement("span"); newnode.innerHTML = i + " :"; newnode.setAttribute("style","color:#585858;margin:0 5px 0 -2px;"); cptmp[i-1].insertBefore(newnode,cptmp[i-1].firstChild); if(BHCO) cptmp[i-1].parentNode.appendChild(cptmp[i-1]); } } } //開啟所有舊留言,在讀取完留言後進行新功能 function BHCWait(cps,num,ud){ if(cps.length1000) l=num-1000; else l=0; var k = BHpA.length; if(k>0){ var nodetmp,nodeIdtmp,nodeNametmp,j,m,nodeid,nodeName; var BHpp = BHpA[0].parentNode.parentNode.getElementsByTagName("p"); if(BHpp[0].className == "FM-cbox10D" && k < 6 && (BHpp[0].firstChild.tagName == "A" || BHpp[0].firstChild.tagName == "a")) m = parseInt(BHpp[0].firstChild.innerHTML.substring(6)); else m = l; for(j = 0;j 2){ GamerChangeBtnToClose(BHPA[i].lastChild); } } } //開啟單篇文章的圖片、影像 function GamerOpenImage(event){ var EDivA = event.currentTarget.parentNode.parentNode.parentNode.getElementsByTagName("div"); GamerChangeBtnToClose(event.currentTarget); var i,j,Mid; for(i = 0;i < EDivA.length;i++){ if(EDivA[i].className.substring(0,8) == "FM-cbox7"){ var EAA = EDivA[i].getElementsByTagName("a"); if(EAA){ for (j = 0; j < EAA.length; j++) { if(EAA[j].name == "attachImgName") unsafeWindow.attachIMG(EAA[j], 'show'); if(EAA[j].name == "attachMovieName") unsafeWindow.attachMOVIE(EAA[j]); } } } } } //關閉單篇文章的圖片、影像 function GamerCloseImage(event){ var EDivA = event.currentTarget.parentNode.parentNode.parentNode.getElementsByTagName("div"); GamerChangeBtnToOpen(event.currentTarget); var i,j; for(i = 0;i < EDivA.length;i++){ if(EDivA[i].className.substring(0,8) == "FM-cbox7"){ var EAA = EDivA[i].getElementsByTagName("a"); if(EAA){ for (j = 0; j < EAA.length; j++) { if(EAA[j].name == "attachImgName") EAA[j].innerHTML = '點選觀圖'; if(EAA[j].name == "attachMovieName"){ EAA[j].href = EAA[j].firstChild.getAttribute("src"); EAA[j].innerHTML = '點選觀影'; } } } } } } //單篇文章的影像、圖片若已全部開啟,將開啟圖像改為關閉圖像 function GamerImgOpenCheck(event){ var i,ImgOpenF = true; var CTAA; if(event.currentTarget.parentNode.className=="FM-P2") CTAA = event.currentTarget.parentNode.getElementsByTagName("a"); else if(event.currentTarget.parentNode.parentNode.className=="FM-P2") CTAA = event.currentTarget.parentNode.parentNode.getElementsByTagName("a"); else if((event.currentTarget.parentNode.parentNode.parentNode.className=="FM-P2")) CTAA = event.currentTarget.parentNode.parentNode.parentNode.getElementsByTagName("a"); for(i = 0; i < CTAA.length; i++){ if((CTAA[i].name == "attachImgName" || CTAA[i].name == "attachMovieName") && CTAA[i].firstChild.tagName == "SCRIPT"){ ImgOpenF = false; break; } } if(ImgOpenF){ var CTPA,CTPNA = event.currentTarget.parentNode.parentNode.parentNode.parentNode.parentNode; if(CTPNA.className != "FM-cbox1") CTPNA = event.currentTarget.parentNode.parentNode.parentNode.parentNode; if(CTPNA.className != "FM-cbox1") CTPNA = event.currentTarget.parentNode.parentNode.parentNode; CTPA = CTPNA.getElementsByTagName("p"); for (i = 0; i < CTPA.length; i++){ if(CTPA[i].className == "FM-cbox4" && CTPA[i].childNodes.length > 2) GamerChangeBtnToClose(CTPA[i].lastChild); } } } //加入改變留言順序的連結點 function BHCES(){ unsafeWindow.BHCWait = exportFunction(BHCWait,unsafeWindow); unsafeWindow.moreCommend = exportFunction(moreCommend,unsafeWindow); unsafeWindow.allCommend = exportFunction(allCommend,unsafeWindow); unsafeWindow.closeallCommend = exportFunction(closeallCommend,unsafeWindow); unsafeWindow.GamerCommendReverse = exportFunction(GamerCommendReverse,unsafeWindow); unsafeWindow.GamerOpenImage = exportFunction(GamerOpenImage,unsafeWindow); unsafeWindow.GamerCloseImage = exportFunction(GamerCloseImage,unsafeWindow); unsafeWindow.GamerImgOpenCheck = exportFunction(GamerImgOpenCheck,unsafeWindow); unsafeWindow.forumShowAllMedia = exportFunction(forumShowAllMedia,unsafeWindow); GamerCommendReverse(); var BHDivA = unsafeWindow.document.getElementsByTagName("div"); for(i = 0;i < BHDivA.length;i++){ if(BHDivA[i].className == "FM-cbox10"){ var j,pchecked1 = false,pchecked2 = false; var tmp = (BHCO) ? "↑" : "↓"; for(j = 0;j < BHDivA[i].childNodes.length;j++){ if(BHDivA[i].childNodes[j].className == "FM-cbox10D") pchecked1 = true; if(BHDivA[i].childNodes[j].className == "FM-msgbg" && BHDivA[i].childNodes[j].childNodes.length > 2) pchecked2 = true; } if(!pchecked1 && pchecked2){ BHDivA[i].innerHTML = '

'+tmp+'留言順序'+tmp+'

' + BHDivA[i].innerHTML; BHDivA[i].firstChild.firstChild.addEventListener('click',unsafeWindow.GamerCommendReverse,true); } else if(pchecked1){ PA = BHDivA[i].getElementsByTagName("p"); PA[0].innerHTML = ''+tmp+'留言順序'+tmp+'' + PA[0].innerHTML; PA[0].firstChild.addEventListener('click',unsafeWindow.GamerCommendReverse,true); } } } //修改開啟圖片按鈕的連結點 var BHPA = unsafeWindow.document.getElementsByTagName("p"); for(i = 0;i < BHPA.length;i++){ if(BHPA[i].className == "FM-cbox4"){ BHPA[i].removeChild(BHPA[i].childNodes[2]); var BHPDivA = BHPA[i].parentNode.parentNode.getElementsByTagName("div"); var k,j,Iflag = false,Oflag = true; for(k = 0;k < BHPDivA.length;k++){ if(BHPDivA[k].className.substring(0,8) == "FM-cbox7"){ var EAA = BHPDivA[k].getElementsByTagName("a"); if(EAA){ for(j = 0; j < EAA.length; j++){ if(EAA[j].name == "attachImgName" || EAA[j].name == "attachMovieName"){ Iflag = true; EAA[j].addEventListener('click',unsafeWindow.GamerImgOpenCheck,true); if(EAA[j].firstChild.tagName == "SCRIPT") Oflag = false; } } } } } if(Iflag){ var newnode = unsafeWindow.document.createElement("a"); if(Oflag){ newnode.innerHTML="關圖"; newnode.addEventListener('click',unsafeWindow.GamerCloseImage,true); } else{ newnode.innerHTML="開圖"; newnode.addEventListener('click',unsafeWindow.GamerOpenImage,true); } newnode.setAttribute("href","javascript:;"); BHPA[i].insertBefore(newnode,BHPA[i].lastChild.nextSibling); } } } //將原有的開啟所有圖片按鈕移到上面的浮動功能列 var newLi = unsafeWindow.document.createElement("li"); newLi.innerHTML = '圖像全開'; newLi.addEventListener('click',unsafeWindow.forumShowAllMedia,true); var BHMenu = unsafeWindow.document.getElementById("BH-menu-path"); var BHMenuULA = BHMenu.getElementsByTagName("ul"); BHMenuULA[0].insertBefore(newLi,BHMenuULA[0].childNodes[6]); } BHCES();