Skip to content

Instantly share code, notes, and snippets.

@kendfrey
Last active August 29, 2015 14:22
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 kendfrey/357c3b202c83232c5476 to your computer and use it in GitHub Desktop.
Save kendfrey/357c3b202c83232c5476 to your computer and use it in GitHub Desktop.
Title Shortener
// ==UserScript==
// @name Title Shortener
// @namespace http://kendallfrey.com/
// @version 1.0
// @description Removes cruft from page titles
// @author Kendall Frey
// @include *
// @grant none
// ==/UserScript==
var observer = new MutationObserver(updateTitle);
observer.observe(document.head, { childList: true, subtree: true, characterData: true });
updateTitle();
function updateTitle()
{
var title;
if ("StackExchange" in window && document.location.pathname.match(/^\/questions\//))
{
title = document.title.replace(/^[^-]+ - (.*) - .*/, "$1"); // special handling for Stack Exchange questions, which put tag names before the question title
}
else
{
title = document.title.replace(/\s+[-|]\s+.*/, "");
}
if (title !== document.title)
{
document.title = title;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment