PDA

View Full Version : Greasemonkey preview script


affenhubert
04-05-08, 21:07
Hi everybody,

I have created a script for the firefox greasemonkey addon (http://addons.mozilla.org/de/firefox/addon/748). The script shows the mouseover preview images directly in the forum page, so that you don't have to mouseover every link.

http://img225.imagevenue.com/loc212/th_31392_pg_123_212lo.jpg (http://img225.imagevenue.com/img.php?image=31392_pg_123_212lo.jpg)

I don't know, if such a script is appreciated, because it will increase the traffic, but if it is not appreciated, just delete this post.

Here is the script:
// ==UserScript==
// @name Proving Grounds preview tweak
// @namespace affenhubert
// @include http://www.proving-grounds.net/forum/*
// ==/UserScript==

window.addEventListener(
'load',
function() {
var links = document.getElementsByTagName('a');
for(i=0; i<links.length; i++) {
var link = links[i];
if(link.getAttribute('id') && link.getAttribute('id').indexOf("thread_title_") >= 0) {
if(link.getAttribute('onmouseover')) {
var text = link.getAttribute('onmouseover');

if(link.parentNode) {
link.parentNode.appendChild(document.createElement ("br"));
}

// this would be cooler with regexp
var start = -1;
while( (start = text.indexOf('img src')) >= 0) {
text = text.substr(start+10, text.length);
stop = text.indexOf("\'");
var thumb = text.substring(0, stop-1);
if(link.parentNode) {
var image = document.createElement("img");
image.setAttribute("src", thumb);
image.setAttribute("alt", "no thumb available ");
link.parentNode.appendChild(image);
}
}

//break;
}
}
}
},
true);

nudejanet
05-05-08, 00:22
i will give that a go...thanks :)

kant
05-05-08, 00:34
i WILL give it a try. Well worthi it! Good enginnering!

maa
05-05-08, 03:45
Very nice ! I just add a setAttribute() to your script to disable the mouse over :

// ==UserScript==
// @name Proving Grounds preview tweak
// @namespace affenhubert
// @include http://www.proving-grounds.net/forum/*
// ==/UserScript==

window.addEventListener(
'load',
function() {
var links = document.getElementsByTagName('a');
for(i=0; i<links.length; i++) {
var link = links[i];
if(link.getAttribute('id') && link.getAttribute('id').indexOf("thread_title_") >= 0) {
if(link.getAttribute('onmouseover')) {
var text = link.getAttribute('onmouseover');
link.setAttribute('onmouseover','');

if(link.parentNode) {
link.parentNode.appendChild(document.createElement ("br"));
}

// this would be cooler with regexp
var start = -1;
while( (start = text.indexOf('img src')) >= 0) {
text = text.substr(start+10, text.length);
stop = text.indexOf("\'");
var thumb = text.substring(0, stop-1);
if(link.parentNode) {
var image = document.createElement("img");
image.setAttribute("src", thumb);
image.setAttribute("alt", "no thumb available ");
link.parentNode.appendChild(image);
}
}

//break;
}
}
}
},
true);

jolioshmolio
05-05-08, 17:49
Great stuff, affenhubert & maa. Thanks!

serendipityguy
05-05-08, 18:29
I heard that grease monkey crashes G-Mail.....did you test this in other environments? , thanks for your efforts..

dalemation
07-05-08, 10:13
Thanks alot.
Thats a cool script!

jjjshabadoo
24-05-08, 18:58
I heard that grease monkey crashes G-Mail.....did you test this in other environments? , thanks for your efforts..I've been using Greasemonkey for months and haven't had any GMail issues. It's very likely that there are lots of scripts that might crash GMail, but when I'm installing a script, I'm careful about where I get it etc.

I actually use the "Better Gmail" script and I haven't had any issues. That said, buyer beware - I wouldn't use a script that hadn't been around for a few weeks at least and that I didn't get from a reputable source. Also, any script that you're not totally sure of, look at the code or post the code to a forum where other programmers can look at it. It wouldn't be hard to add a password sniffer or something else nefarious - but since the code is visible to the users and it's usually short and simple, it's easy to spot stuff like that.

Good luck.

hucks
19-06-08, 00:43
Thanks you so much affenhubert and maa:)

barabbas
23-08-08, 15:09
Thanks a lot, this really is a great help. But could you change it so the pictures work as a link to the thread too?

affenhubert
04-11-08, 14:34
New version for the new board software

// ==UserScript==
// @name Proving Grounds preview tweak
// @namespace affenhubert
// @include http://www.proving-grounds.net/forum/*
// ==/UserScript==

window.addEventListener(
'load',
function() {
var links = document.getElementsByTagName('a');
for(i=0; i<links.length; i++) {
var link = links[i];
if(link.getAttribute('id') && link.getAttribute('id').indexOf("thread_title_") >= 0) {
var tdId = link.id.replace(/thread_title_/g,"td_threadtitle_");
var td = document.getElementById(tdId);
var text = td.getAttribute('onmouseover');
if(text) {
if(link.parentNode) {
link.parentNode.appendChild(document.createElement ("br"));
}

// this would be cooler with regexp
var start = -1;
while( (start = text.indexOf('img src')) >= 0) {
text = text.substr(start+10, text.length);
stop = text.indexOf("\'");
var thumb = text.substring(0, stop-1);
if(link.parentNode) {
var imageLink = document.createElement("a");
imageLink.href = link.href;
var image = document.createElement("img");
image.setAttribute("src", thumb);
image.setAttribute("alt", "no thumb available ");
image.setAttribute("onerror", "this.setAttribute('style', 'display:none')");
image.setAttribute("style", "border: none");

imageLink.appendChild(image)
link.parentNode.appendChild(imageLink);
}
}

td.removeAttribute('onmouseover');
td.removeAttribute('onmouseoout');
}
}
}
},
true);

shopman089
04-11-08, 21:43
Thanks for the update. This script makes the site a lot better.

jjjshabadoo
05-11-08, 00:23
Yes, thanks. I loved the functionality, so it's nice to see someone updated it. Kudos.

v1ru5
13-11-08, 05:05
Awesome! :) Thanks for the update - I've really missed having everything on screen together... It makes for much easier spam hunting! ;)

I've stickied this thread by the way... :)

zolseb
26-04-09, 14:17
Hi Guys,
I'm came across this sticky and installed Greasemonkey but I'm having trouble installing the script. I'm not sure how it's done. I have had a look at userscripts.org but I couldn't find the script for this preview tweak. I also tried copy and paste but obviously that doesn't work.
I would really appreciate if someone could point me in the right direction. Much appreciated.


Edit: I managed to install the script but it still doesn't seem to work. Obviously I'm doing something wrong.