Here is a greasemonkey script that implements like half the pavatar spec by following people's profile homepage links and checking for pavatar links and replacing the graal forum avatar with the pavatar found there.
Future improvements include limiting the size and dimensions as described in the pavatar spec or possibly being gimmicky and supporting svg, feel free to get on that.
Edit: Now limiting maximum dimensions, customisable at the end of the script.
NPC Code:
// ==UserScript==
// @name gforum-pavatars
// @namespace http://ilfirin.org/
// @description Follow homepage links and check for pavatars for every post
// @include http://forums.graalonline.com/forums/showthread.php?*
// @include http://forums.graal2001.com/forums/showthread.php?*
// @include http://forums.graalgraalonline.com/forums/showpost.php?*
// @include http://forums.graal2001.com/forums/showpost.php?*
// ==/UserScript==
function getUserId(postId) {
var reps = document.evaluate(
'//span[starts-with(@id, "repdisplay_' + postId + '_")]',
document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null)
for (var i = 0; i < reps.snapshotLength; ++i) {
var id = reps.snapshotItem(i).getAttribute('id')
var index = id.lastIndexOf('_')
if (index == -1) continue
return id.substr(index+1)
}
}
function getLink(td) {
var link = td.firstChild
if (!link || link.tagName != 'A') return
var textNode = link.firstChild
if (!textNode) return
var text = textNode.nodeValue
if (!text
|| text.substr(0, 6) != "Visit "
|| text.substr(text.length - 12) != "'s homepage!") return
return link.getAttribute('href')
}
function sanify(link) {
// what happened to find_first_of?
if (link.indexOf('?') != -1) return
if (link.indexOf('@') != -1) return
if (link.indexOf('forums.graal') != -1) return
if (link.substr(0, 7) != 'http://') return
return link
}
function getPavatar(resp) {
var r = /X-Pavatar:\s+([^\r\n]+)/i.exec(resp.responseHeaders)
if (r) return r[1]
var doc = new DOMParser().parseFromString(resp.responseText, 'text/xml')
//// xpath does not appear to work here?
//var links = doc.evaluate(
// '/html/head/link[@rel="pavatar"]',
// doc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null)
//for (var i = 0; i < links.snapshotLength; ++i) {
// var link = links.snapshotItem(i)
var links = doc.getElementsByTagName('link')
for (var i = 0; i < links.length; ++i) {
var link = links[i]
if (link.getAttribute('rel') != 'pavatar') continue
var href = link.getAttribute('href')
if (href) return href
}
}
function addClass(elem, className) {
// elem.classList.add("customAvatar") -- only FF 3.6 and up
var oldClassList = elem.getAttribute('class')
if (!oldClassList)
elem.setAttribute('class', className)
else
elem.setAttribute('class', oldClassList + ' ' + className)
}
function setPavatar(userId, pavatar) {
var avs = document.evaluate(
'//img[starts-with(@src, "image.php?u=' + userId + '&")]',
document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null)
for (var i = 0; i < avs.snapshotLength; ++i) {
var av = avs.snapshotItem(i)
av.setAttribute('src', pavatar)
av.removeAttribute('width')
av.removeAttribute('height')
addClass(av, 'customAvatar')
}
}
function combine(base, href) {
if (href.substr(0, 1) == '/') {
var i = base.indexOf('/', 8)
if (i == -1)
return base + href
else
return base.substr(0, i) + href
} else if (href.substr(0, 7) == 'http://') {
return href
} else {
return base + '/' + href
}
}
function onLoadCallback(link, userId) {
return function(resp) {
if (resp.status != 200) return
var pavatar = getPavatar(resp)
if (pavatar)
setPavatar(userId, combine(link, pavatar))
}
}
function checkAvatar(link, userId) {
link = sanify(link)
if (!link) return
GM_xmlhttpRequest({
'method': 'GET',
'url': link,
'headers': {'Accept': 'text/html,application/xhtml+xml'},
'onload': onLoadCallback(link, userId)
})
}
var handledUsers = {}
var tds = document.evaluate(
'//td[@class="vbmenu_option"]',
document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null)
for (var i = 0; i < tds.snapshotLength; ++i) {
var td = tds.snapshotItem(i)
var link = getLink(td)
if (!link) continue
var node
for (node = td.parentNode;
node && node.tagName != 'TABLE';
node = node.parentNode)
;
var postIdLabel = node.parentNode.getAttribute('id')
var postId = postIdLabel.substring(9, postIdLabel.length - 5)
var userId = getUserId(postId)
if (!userId || handledUsers[userId]) continue
handledUsers[userId] = true
checkAvatar(link, userId)
}
var style = document.createElement('style')
style.setAttribute('type', 'text/css')
style.appendChild(document.createTextNode(' \
.customAvatar { \
max-width: 192px ! important; \
max-height: 272px ! important; \
} \
'))
document.getElementsByTagName('head')[0].appendChild(style)
If there is a link somewhere in there, Skyld approved of it.