Skip to content

Instantly share code, notes, and snippets.

@azu
Created February 22, 2011 13:55
Show Gist options
  • Save azu/838690 to your computer and use it in GitHub Desktop.
Save azu/838690 to your computer and use it in GitHub Desktop.
Add an edit link for tumblr posts (very useful for colaborative blogs)
// ==UserScript==
// @name Tumblr - Edit link
// @namespace ivanmendoza.net
// @description Add an edit link for tumblr posts (very useful for colaborative blogs)
// @include http://jser.info/post/*
// ==/UserScript==
// origina from http://userscripts.org/scripts/show/65725
function getLink() {
var href = location.href;
var m = new RegExp('(http:\\/\\/)((?:[a-z][a-z\\.\\d\\-]+)\\.(?:[a-z][a-z\\-]+))(?![\\w\\.])(\\/post\\/)(\\d+)', ["i"]).exec(href);
var userID = m[m.length - 1];
return ("http://www.tumblr.com/edit/" + userID + "?redirect_to=" + encodeURIComponent(href));
}
function addLink() {
var edit_page = getLink();
var eLink = document.createElement("a");
eLink.setAttribute("id", "edit_link");
eLink.setAttribute("style", "position:absolute;top:5px;left:2px;padding:2px 0 0;width:40px;height:18px;display:block;overflow:hidden;-moz-border-radius:3px;background:#777;color:#fff;font-size:8pt;text-decoration:none;font-weight:bold;text-align:center;line-height:12pt;");
eLink.setAttribute("href", edit_page);
eLink.appendChild(document.createTextNode("Edit"));
var elBody = document.getElementsByTagName("body")[0];
elBody.appendChild(eLink);
}
addLink();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment