Skip to content

Instantly share code, notes, and snippets.

@uuf6429
Created January 8, 2017 03:41
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 uuf6429/8064cd6ac75a79bc9a14287d748ada5a to your computer and use it in GitHub Desktop.
Save uuf6429/8064cd6ac75a79bc9a14287d748ada5a to your computer and use it in GitHub Desktop.
Title Scroller (create bookmarlet with: http://mrcoles.com/bookmarklet/)
(function () {
var options = {
textScrollInterval: 400,
textPrefix: "\u25B6 ",
textReplace: /\u25B6\s?/g,
textSpace: "\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0"
};
var isTitleChanging = false,
sourceTitle = document.title.replace(options.textReplace, ""),
movingTitle = sourceTitle,
titleChanged = function () {
if (isTitleChanging) return;
isTitleChanging = true;
sourceTitle = document.title.replace(options.textReplace, "");
movingTitle = sourceTitle,
isTitleChanging = false;
},
oldWindowLoad = window.onload;
window.onload = function () {
var titleEl = document.getElementsByTagName("title")[0];
var docEl = document.documentElement;
if (docEl && docEl.addEventListener) {
docEl.addEventListener("DOMSubtreeModified", function (evt) {
var t = evt.target;
if (t === titleEl || (t.parentNode && t.parentNode === titleEl)) {
titleChanged();
}
}, false);
} else {
document.onpropertychange = function () {
if (window.event.propertyName == "title") {
titleChanged();
}
};
}
if (oldWindowLoad) {
oldWindowLoad();
}
};
setInterval(
function () {
isTitleChanging = true;
movingTitle = movingTitle.substr(2);
if (movingTitle.length < sourceTitle.length) {
movingTitle += options.textSpace + sourceTitle;
}
document.title = options.textPrefix + movingTitle;
isTitleChanging = false;
},
options.textScrollInterval
);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment