Skip to content

Instantly share code, notes, and snippets.

@karteek
Created December 19, 2009 18:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save karteek/260200 to your computer and use it in GitHub Desktop.
Save karteek/260200 to your computer and use it in GitHub Desktop.
A way to enable custom 404 for Tumblr. Well, it 'kinda' works
<script type="text/javascript">
/* Works for me */
var text_posts = document.getElementsByClassName("regular");
var text_404 = "The URL you requested could not be found.";
var title_404 = "Not Found";
if(text_posts.length == 1){
var bodyNode = text_posts[0].lastChild;
if(bodyNode.previousSibling.textContent == text_404) {
// titleNode.innerHTML = "<a href='/'>Not Found</a>";
var blog_loc = "http://" + document.domain + "/";
var query = window.location.href.slice(blog_loc.length);
var tokens = query.toLowerCase().split('/');
var keyword = tokens.join(" ");
var bodyContent = "Looks like you came from an old bookmark, or just looking for a page that doesn't exist. Were you looking for <span class='tg'><a href='/search/"+ escape(keyword) +"'>"+keyword+"</a></span>";
bodyNode.previousSibling.innerHTML = bodyContent;
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment