~libravatar/libravatar/master

306 by Francois Marier
Created a quick and dirty Greasemonkey script
1
// Libravatar Images
2
// version 0.1
3
// 2011-01-22
4
// Copyright (c) 2011, Francois Marier <fmarier@gmail.com>
5
// Released under the GNU GPL version 3 or later
6
// http://www.gnu.org/copyleft/gpl.html
7
//
8
// --------------------------------------------------------------------
9
// This is a Greasemonkey user script.  To install it, you need
10
// Greasemonkey 0.8 or later: http://greasemonkey.mozdev.org/
11
// Then restart Firefox and revisit this script.
12
// Under Tools, there will be a new menu item to "Install User Script".
13
// Accept the default configuration and install.
14
//
15
// To uninstall, go to Tools/Manage User Scripts,
16
// select "Libravatar Images", and click Uninstall.
17
// --------------------------------------------------------------------
18
//
19
// ==UserScript==
20
// @name          Libravatar Images
21
// @namespace     http://www.libravatar.org
22
// @description   Replace gravatar.com images with libravatar.org ones
23
// @include       *
24
// ==/UserScript==
25
26
(function() {
27
     images = document.evaluate('//img[contains(@src, "")]', document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
28
29
     for (var i=0; i < images.snapshotLength; i++) {
30
	 var image = images.snapshotItem(i);
31
	 var src = image.src;
32
33
	 if (!src) {
34
             continue;
35
         }
36
37
	 if (src.indexOf("http://www.gravatar.com/avatar/") != -1) {
38
             image.src = src.replace("http://www.gravatar.com/avatar/", "http://cdn.libravatar.org/avatar/");
39
         }
40
	 else if (src.indexOf("https://secure.gravatar.com/avatar/") != -1) {
41
             image.src = src.replace("https://secure.gravatar.com/avatar/", "https://seccdn.libravatar.org/avatar/");
42
         }
43
	 else if (src.indexOf("http://www.gravatar.com/avatar.php?gravatar_id=") != -1) {
44
             image.src = src.replace(new RegExp("^http://www\\.gravatar\\.com/avatar\\.php\\?gravatar_id=([a-f0-9A-F]+)&?"), "http://cdn.libravatar.org/avatar/$1?");
45
         }
46
     }
47
48
})();
49
50
// DEBUG: make sure the page has no errors
51
//alert('done');