// ==UserScript== // @name sa.yona.la identicon // @namespace http://zuu9xi.sa.yona.la/ // @description sayonara identicon // @include http://sa.yona.la/* // @include http://*.sa.yona.la/* // ==/UserScript== window.addEventListener("load", function () { var authors = getElementsByXPath('//p[@class="entry-note"]/a[1]', null) var identiconSize = 15 var identiconStyle = { width: identiconSize + "px", height: identiconSize + "px", display: "inline-block", position: "relative", top: "-2px", right: "3px", } var addIdenticon = function (a) { var elem = document.createElement('img') elem.src = "http://identicon.relucks.org/" + a.textContent + "?size=" + identiconSize for (var key in identiconStyle) { elem.style[key] = identiconStyle[key] } a.parentNode.insertBefore(elem, a) } // add identicon to pagerized entry if (typeof window.AutoPagerize != "undefined") { window.AutoPagerize.addFilter( function (docs) { var authors = docs.map(function(d) { return getElementsByXPath('.//p[@class="entry-note"]/a[1]', d)[0] }) authors.forEach(addIdenticon) } ) } // add identicon to current page entry authors.forEach(addIdenticon) }, false) // copied from autopagerize (http://userscripts.org/scripts/show/8551) function getElementsByXPath(xpath, node) { var node = node || document var doc = node.ownerDocument ? node.ownerDocument : node var nodesSnapshot = doc.evaluate(xpath, node, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null) var data = [] for (var i = 0; i < nodesSnapshot.snapshotLength; i++) { data.push(nodesSnapshot.snapshotItem(i)) } return data }