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 17, 2005, 11:32pm 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.

ShenmeShenme at Jun 01, 2005, 06: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);

allowed HTML: a, blockquote, ul, ol, li, dl, dt, dd, b, i, strong, em, code, abbr, acronym, sub, sup, span, pre

allowed HTML: a, blockquote, ul, ol, li, dl, dt, dd, b, i, strong, em, code, abbr, acronym, sub, sup, span, pre