Skip to content

Instantly share code, notes, and snippets.

@thejefflarson
Forked from esmooov/NYTCween.js
Created March 22, 2011 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thejefflarson/881301 to your computer and use it in GitHub Desktop.
Save thejefflarson/881301 to your computer and use it in GitHub Desktop.
function(){
var $$ = function(query){
!!(query && query.nodeType == 1) ?
this.dom = [query]
:
this.dom = [].slice.call(document.querySelectorAll(query));
};
$$.prototype.remove = function(){
this.dom[0].parentNode.removeChild(this.dom);
return this;
};
$$.prototype.css = function(rules){
for(i in rules)
this.dom[0].style[i] = rules[i];
return this;
};
$$.prototype.append = function(html){
var el = document.createElement("div");
el.innerHTML = html;
for(var i = 0; i < el.children.length; i++)
this.dom[0].appendChild(el.children[i]);
return this;
};
$$.prototype.enHatMan = function(){
var parent = this.dom[0].parentNode;
this.remove();
$(parent).append("<img src='" + enHatMan() + "'/>");
return $(parent.lastChild);
};
var $ = function(query){
return new $$(query);
};
$.getJSON = function(url, cb){
var name = "json" + (new Date()).getTime();
window[name] = function(data){
cb(eval(data));
delete window[name];
};
$(document.body).append("<script async src=" + url.replace("=?", "=" + name) + "></script>");
};
var tweet = function(message){
window.open("http://www.twitter.com/?status=" + encodeURIComponent(message));
};
var id;
var bounce = function(){
if(id) { id = setTimeout(bounce); return; }
//nyt whitelists twitter refers
bitlyfy(function(url) {
tweet("I just took down the paywall at NYTimes.com and so can you! " + url + " #stealing #imajerk");
})
id = null;
};
var bitlyfy = function(cb) {
var endpoint = "http://api.bitly.com/v3/shorten?longUrl=" + encodeURIComponent('http://' + window.location.host + window.location.pathname) + "&format=json";
$.getJSON(endpoint + "&callback=?", function(response) {
var hash = response['data']['hash'];
var shortUrl = "http://bit.ly/" + hash;
cb(shortUrl);
});
};
var enHatMan = function() {
var hatMen = [
'http://26.media.tumblr.com/tumblr_li7y79w7Ps1qzp87ao1_250.gif',
'http://davidcole.me/drop/nytwhat.gif',
'http://petervidani.com/images/nyt.gif'
];
var getRandomHatMan = function() {
return Math.floor(hatMen.length * Math.random());
};
return hatMen[getRandomHatMan()];
};
var liberate = function(el){
el.dom.innerHTML = text.replace(/(cost|price|expense|payment|money)\s/i,"freedom ");
};
var liberate_all = function(){
var collection = $('.articleBody p');
for(var i = 0; i < collection.dom.length; i++)
liberate($(collection.dom[i]));
};
var hide = {};
hide.the = function(el){
$("#" + el).enHatMan();
setTimeout(bounce);
return this;
};
hide.and = hide;
hide.the("overlay").and.the("gatewayCreative");
$(document.body).css({overflow:'scroll'});
// old school
$(document.body).append('<audio controls="no" preload="auto" autoplay style="display:none"><source src="http://thejefflarson.s3.amazonaws.com/new-sapps/themessage.mp3" /></audio>');
liberate_all();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment