Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ucnv/385036 to your computer and use it in GitHub Desktop.
Save ucnv/385036 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name DegradeTwitterIcons
// @namespace http://polog.org/
// @include http://twitter.com/*
// @require http://gist.github.com/3242.txt
// @require http://www.bytestrom.eu/data/media/experiments/jpegencoder/examples/jpeg_encoder_basic.js
// ==/UserScript==
// using $X http://gist.github.com/3242 by os0x
function init(doc){
$X('.//img[contains(concat(" ",normalize-space(@class)," "), " photo fn ")] | .//a[contains(@class, "profile-pic")]/img', doc).forEach(function(img){
try{
base64ize(img, function(){degrade(img);});
} catch (e) {
log(e);
}
});
}
function degrade(img){
var encoder = new JPEGEncoder(1);
var jpeg = encoder.encode(getImageDataFromImage(img));
img.src = jpeg;
}
// from glitchmonkey, modified
function base64ize(element, after_func) {
GM_xmlhttpRequest({
method: "GET",
overrideMimeType: "text/plain; charset=x-user-defined",
url: element.src,
onload: function (res) {
var type = contentType(res.responseHeaders);
var oldsrc = element.src;
element.addEventListener('error', function() {
this.src = oldsrc;
}, false);
element.src =
[
'data:',
type,
';base64,',
base64encode(res.responseText)
].join('');
setTimeout(after_func, 1000);
}
});
}
function contentType(headers) {
return headers.match(/Content-Type: (.*)/i)[1];
}
function base64encode(data) {
return btoa(data.replace(/[\u0100-\uffff]/g, function(c) {
return String.fromCharCode(c.charCodeAt(0) & 0xff);
}));
}
function log(s){
//unsafeWindow.console.log(s);
}
init(document);
if(window.AutoPagerize)
window.AutoPagerize.addFilter(function(docs){
docs.forEach(function(doc){
init(doc);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment