Created
January 8, 2017 03:41
-
-
Save uuf6429/8064cd6ac75a79bc9a14287d748ada5a to your computer and use it in GitHub Desktop.
Title Scroller (create bookmarlet with: http://mrcoles.com/bookmarklet/)
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
(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