theme selector

light blue screenshot grey screenshot navy screenshot dark green screenshot red and black screenshot
 

by Tony Chang
tony@ponderer.org

All opinions on this site are my own and do not represent those of my employer.

Creative Commons Attribution License

my first user script

Feb 18, 2005, 12:32am EST

 

 

My first (real) greasemonkey user script is for adding user pics to livejournal user links. That is, if you hover over a livejournal user link (like this one: [info]idealisms), the user’s userpic appear above your cursor.

Futhermore, the script use XMLHttpRequests and doesn’t require user intervention because all the requests are made to livejournal.com.

I had actually done something similar in my livejournal S2 style, but I gave up when I realized that there was no way to get userpic urls for most user links in S2. I was reminded of the idea today when I read about a related PHP script.

Hmm, it’s unclear to me whether I should have posted this here on my tech blog or on my more personal livejournal.

nitrofin at Feb 18, 2005, 03:53am EST

awesomeness. i tried it.

i dont know what practical use it is, but you always come up with great things.


tony at Feb 18, 2005, 04:14am EST

Well, for example, it’s useful when I’m reading a comments page that is collapsed because of too many comments. I like to see the uesrpics of the people commenting before clicking on a thread.

I also like it when viewing rating communities. If there’s a members list, you can see user pics without having to browse to userinfo pages.

Or perhaps you want to see user pics of people who are interested in “cute”?


Wetzel at Feb 23, 2005, 10:31pm EST

That’s some neat little code, but I seem to have run into a problem. The code seems to break the javascript menu at the top of the main livejournal page and other pages on the website - sometimes it works and sometimes it doesn’t.

Also, I’ve found the plugin to be somewhat inconsistent. Sometimes no longer how long I hover over a name, their image doesn’t show up. Just thought I’d let you know.


tony at Feb 24, 2005, 05:13am EST

Can you be more specific about how it breaks the menus? I’m having a hard time reproducing the error.

Also, images don’t show up if the user doesn’t have a userpic. Have you found the script to be inconsistent with users who do have a user pic?


Wetzel at Feb 24, 2005, 11:08am EST

When I try to use the menu at the top of http://www.livejournal.com/, it tries to load my userpic when I move the cursor over “journal” instead of drawing the submenu below it with “Update, Recent, Archive” etc. in it. If I click on journal, then the submenu appears, but by then it’s too late to select something from it.

I’m running the normal firefox 1.0 build from mozilla. But, I do have 20 extensions installed (with five or six greasemonkey scripts), and it could be a combination of extensions interfering here - but still when I disable your code in greasemonkey, the menu works again.

And I think you’re right, maybe I was just finding users without userpics, Doh!


tony at Feb 24, 2005, 02:24pm EST

Ah, I see. Sorry about that. I’ve updated the script so it won’t do that anymore. Thanks!


Wetzel at Feb 24, 2005, 08:37pm EST

Fantastic! thank you. That’s a neat little bit of code.


Jeremy Dunck at Feb 27, 2005, 12:12am EST

Tony, I just added this script the directory


George Hotelling at Mar 15, 2005, 11:49am EST

I love the script but I have one quick suggestion: you should change the included pages to http://*.livejournal.com/*

Paid users can access their LiveJournals at username.livejournal.com.


tony at Mar 15, 2005, 12:00pm EST

That won’t work. I’m using XMLHttpRequest objects which can only be sent to the same domain. So if I’m on foo.livejournal.com, I can’t get the pictures for any user other than foo.


bpt at Apr 10, 2005, 07:05pm EDT

Actually, according to GreaseMonkey’s “Writing User Scripts” page, Greasemonkey has a special GM_xmlhttpRequest function that allows cross-domain requests.

I also suggest that you post a link to this userscript on the lj_nifty community.


tony at Apr 10, 2005, 11:36pm EDT

At the time I wrote this, GM_xmlhttpRequest didn’t exist. Once the feature was added, I wrote a user script to use it, but haven’t gone back and updated this script yet.


ShenmeShenme at Jun 01, 2005, 07:40pm EDT

This adds more places where once can see the picture e.g. all the names in the useinfo page.

06/01/05 Wed 03:33:26 776 % more more.diff.txt

*** /tmp/lj_usericon.user.js Wed Jun 1 15:28:39 2005

—- /tmp/ShenmeShenme/livejournaluserpicadder.user.js Wed Jun 1 15:01:34 2005

***************

*** 19,25 ****

// ==/UserScript==

(function() {

! var regex = new RegExp(“^http://www.livejournal.com/(users|community)/[a-z0-9_]+/?$”, “i”);

function xpath(expr, doc) {

if (!doc) {

—- 19,26 ——

// ==/UserScript==

(function() {

! var regex1 = new RegExp(“^http://www.livejournal.com/(users|community)/[a-z0-9_]+/?$”, “i”);

! var regex2 = new RegExp(“^http://www.livejournal.com/userinfo.bml.user=[a-z0-9_]+$”, “i”);

function xpath(expr, doc) {

if (!doc) {

***************

*** 62,67 ****

—- 63,72 ——

// url of the rss feed

var url = this.href;

+ if (url.match(regex2))

+ {

+ url = url.replace(/^.*=/g, “http://www.livejournal.com/users/”)

+ }

if (url.charAt(url.length-1) != ‘/’)

url += ‘/’;

url += ‘data/rss’;

***************

*** 108,114 ****

for (var i = 0; i < links.length; i++)

{

var link = links[i];

! if (link.hasAttribute(‘href’) && link.href.match(regex))

{

link.addEventListener(‘mouseover’, mouseover, false);

link.addEventListener(‘mouseout’, mouseout, false);

—- 113,119 ——

for (var i = 0; i < links.length; i++)

{

var link = links[i];

! if (link.hasAttribute(‘href’) && (link.href.match(regex1) || link.href.match(regex2)))

{

link.addEventListener(‘mouseover’, mouseover, false);

link.addEventListener(‘mouseout’, mouseout, false);


tony at Jun 03, 2005, 01:22am EDT

Can you email me the patch file? Thanks.

tony [] ponderer [] org


ShenmeShenme at Jun 04, 2005, 04:00am EDT

A slight fix around line 65 for people who are using some “always show full user info script” or viewing info in full user info mode otherwise

if (url.match(info_regex)) {

// take care of http://www.livejournal.com/userinfo.bml?user=someone&mode=full

url = url.replace(/\&mode=[a-z0-9_]+$/, “”)

url = url.replace(/^.*=/, “http://www.livejournal.com/users/”)

}


RustyDragon at Oct 13, 2005, 01:12pm EDT

Hi!

It’s a very cool script! Thanks a lot for it! I feel a little guilty because I used it as a part of mine… Basically mine does the same thing plus shows some useful links in a popup.

I also improved fetching algorythm a bit. Now on slow connection, if user hovers a link twice (like “move out” - “move in” again) before userpic is loaded - no unneeded and duplicating fetches are performed.

http://userscripts.com/scripts/show/1945