Created
February 22, 2011 13:55
-
-
Save azu/838690 to your computer and use it in GitHub Desktop.
Add an edit link for tumblr posts (very useful for colaborative blogs)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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