Graal Forums  

Go Back   Graal Forums > Development Forums > Future Improvements
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #91  
Old 08-30-2009, 01:09 PM
Crono Crono is offline
:pluffy:
Join Date: Feb 2002
Location: Sweden
Posts: 20,000
Crono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond repute
Quote:
Originally Posted by Darlene159 View Post
I dont see the big deal, especially to get angry about.
Because it's, once again, a prime example of cyberjoueurs completely ignoring it's playerbase.
__________________
Reply With Quote
  #92  
Old 08-30-2009, 03:09 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
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.

Last edited by Loriel; 08-31-2009 at 12:37 AM..
Reply With Quote
  #93  
Old 08-30-2009, 03:18 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Here is a screenshot of it in action.

Click image for larger version

Name:	hooray.png
Views:	250
Size:	67.3 KB
ID:	49263
Reply With Quote
  #94  
Old 09-01-2009, 08:11 PM
BigBear3 BigBear3 is offline
Zormite
BigBear3's Avatar
Join Date: Jan 2007
Location: Lynn, MA
Posts: 2,551
BigBear3 has a reputation beyond reputeBigBear3 has a reputation beyond reputeBigBear3 has a reputation beyond reputeBigBear3 has a reputation beyond reputeBigBear3 has a reputation beyond reputeBigBear3 has a reputation beyond reputeBigBear3 has a reputation beyond reputeBigBear3 has a reputation beyond reputeBigBear3 has a reputation beyond repute
Quote:
Originally Posted by Loriel View Post
Here is a screenshot of it in action.

Attachment 49263
Next.. the world.
Reply With Quote
  #95  
Old 09-03-2009, 04:47 PM
Liberated Liberated is offline
not doing alot
Liberated's Avatar
Join Date: Feb 2008
Posts: 1,366
Liberated has a spectacular aura about
how to apply that script?
__________________
Quote:
Originally Posted by Tigairius View Post
I promise when I get rich I'll send you an iPhone. I'll send everyone an iPhone.
Reply With Quote
  #96  
Old 09-03-2009, 04:51 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by Liberated View Post
how to apply that script?
You need the Greasemonkey plugin for Firefox.
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:23 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.