") > -1) return i return false //error } //Given the XHTML of a post, remove stuff you don't want in the preview box function stripTags(post) { if (!isNaN(smiley.length)) post = post.replace(/.+?/g,smiley) if (!isNaN(image.length)) post = post.replace(/.+?/g,image) if (!isNaN(quote.length)) { post = post.replace(/.+?/g,quote) post = post.replace(/.+?/g,quote) } if (!isNaN(code.length)) { post = post.replace(/
CODE<\/div>
.+?<\/div>/gi,code) post = post.replace(/
HTML<\/div>
.+?<\/div>/gi,code) post = post.replace(/
SQL<\/div>
.+?<\/div>/gi,code) post = post.replace(/
CODE<\/div>
.+?<\/div>/gi,code) } return post } //Given the HTML of a thread, return the first and last post after removing all unneeded tags like images function parseThread(html) { lines = html.split("\n") /*The thread may contain more than 1 page, lofi has 50 posts per page. We cannot use the HTTP HEAD command to see if the pages exist because they are dynamic so instead we simply parse out the number of pages, multiply by 50 and get the page that way.*/ for (i=0; i") { document.getElementById('preview_div').innerHTML = "multiple pages found, loading newest" line = lines[i].split(".html'>") max_page = parseInt(line[line.length-1]) -1 //count from 0, not 1 max_page *= 50 link2 = "lofiversion/index.php/t"+topic+"-"+max_page+".html" //link to latest page var xhReq = new XMLHttpRequest(); xhReq.open("GET", link2, false); //false signifies a synchronous request, so it's done straight away. xhReq.send(null); html += xhReq.responseText //append html of last page } } lines = html.split("\n") // re-split because new stuff may have been added post1_html = lines[findPost(lines)+1] lines.reverse() post2_html = lines[findPost(lines)-1] //get rid of all tags post1_html = stripTags(post1_html) post2_html = stripTags(post2_html) posts = {post1:post1_html,post2:post2_html} return posts } //the main function function show_preview(obj,flag_first) { link = obj.alt //Get the url of the thread from the lofi version of the board topic_start = link.search(/\d+/) //Find where the number start temp = link.substring(topic_start,link.length).search(/\D/) //Find what's after the numbers topic_end = (temp>0)?temp:link.length-topic_start //since maybe nothing after numbers account for that topic = link.substr(topic_start,topic_end) //get the total thread number domain = location.href.substr(0,location.href.substring(8,location.href.length).indexOf("/")+8) //get the domain name link = domain+"/lofiversion/index.php/t"+topic+".html" //get the final link box = document.getElementById('preview_div') box.innerHTML = "loading..." //Build the object I'll send via GM_xmlhttpRequest() obj_thread = { method:"GET", url:link, headers:{"User-Agent":navigator.userAgent}, onload:function(details) { posts = parseThread(details.responseText) if (flag_first == true) //if we want to show the first post box.innerHTML = posts.post1 else //if we want to show the last post box.innerHTML = posts.post2 //Store into post_cache thread = {url:link,html:posts} post_cache[post_cache.length] = thread } } //Check if this page has already been requested found = -1 for (i=0; i

loading...

" //copy the functions into the document so event handlers can call it (thanks to http://blog.monstuff.com/archives/000274.html) unsafeWindow.eval("post_cache = new Array()") unsafeWindow.eval(show_preview.toString()) unsafeWindow.eval(findPos.toString()) unsafeWindow.eval(hide_preview.toString()) unsafeWindow.eval(hideMe.toString()) //Add some CSS GM_addStyle('#preview_div {display: none; position: absolute; width:'+width+'px; height:'+height+'px; overflow-y:scroll; background-color:'+background_colour+'; border: '+border_width+'px solid '+border_colour+';}') GM_addStyle('#preview_div * {margin-top:-2px;margin-left:1px;background:transparent;}') thread_links = document.getElementsByTagName('a') //returns an array of all link tags) //Create the eye image objects eye_first = document.createElement("img") eye_first.setAttribute("src","http://blog.whiteacid.org/wp-content/uploads/2006/04/eye.gif") eye_first.setAttribute("onmouseout","_this=this;timer2=setTimeout('hide_preview(this)',200);clearTimeout(timer)") eye_first.setAttribute("onmouseover","_this=this;timer=setTimeout('show_preview(_this,true)',300)") eye_last = document.createElement("img") eye_last.setAttribute("src","http://blog.whiteacid.org/wp-content/uploads/2006/04/eye.gif") eye_last.setAttribute("onmouseout","_this=this;timer2=setTimeout('hide_preview(this)',200);clearTimeout(timer)") eye_last.setAttribute("onmouseover","_this=this;timer=setTimeout('show_preview(_this,false)',300)") for (i=0; i -1) //If the link goes to a thread { eval("eye_f"+i+"=eye_first.cloneNode(false)") eval("eye_f"+i+".setAttribute('alt','"+link+"')") eval("thread_links[i].parentNode.insertBefore(eye_f"+i+",thread_links[i])") eval("thread_links[i].parentNode.insertBefore(thread_links[i],eye_f"+i+")") } if (link.search(/\?showtopic=\d+.+?view=getlastpost$/) > -1) //If the link goes to the last post of a thread { eval("eye_l"+i+"=eye_last.cloneNode(false)") eval("eye_l"+i+".setAttribute('alt','"+link+"')") eval("thread_links[i].parentNode.insertBefore(eye_l"+i+",thread_links[i])") eval("thread_links[i].parentNode.insertBefore(thread_links[i],eye_l"+i+")") } } //Functions I won't ever really change: //function to hide the preview box function hide_preview(obj) { document.getElementById('preview_div').style.display = 'none' document.getElementById('preview_div').innerHTML = "" } //Function to find the X and Y co-ordinates of where the box should go. Returns both within a struct, of sorts function findPos(obj) { var curtop = 0; var curleft = 0; if (obj.offsetParent) { while (obj.offsetParent) { curtop += obj.offsetTop curleft += obj.offsetLeft obj = obj.offsetParent; } } return {left:curleft,top:curtop} } //general function to hide an object, used on the box's onmouseout event function hideMe(obj) { obj.style.display='none' }