Last active
August 29, 2015 14:22
-
-
Save kendfrey/357c3b202c83232c5476 to your computer and use it in GitHub Desktop.
Title Shortener
This file contains hidden or 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 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