Skip to content

Instantly share code, notes, and snippets.

@raghavrv
Last active March 16, 2017 13:12
Show Gist options
  • Save raghavrv/eb2f44b43ef7d3287327a5fd5e3ee205 to your computer and use it in GitHub Desktop.
Save raghavrv/eb2f44b43ef7d3287327a5fd5e3ee205 to your computer and use it in GitHub Desktop.
Greasemonkey script to add URL to end of current page title
// ==UserScript==
// @name URL in title
// @version 0.1
// @description try to take over the world!
// @author Raghav RV
// @updateURL https://gist.githubusercontent.com/raghavrv/eb2f44b43ef7d3287327a5fd5e3ee205/raw/url_in_title.js
// @downloadURL https://gist.githubusercontent.com/raghavrv/eb2f44b43ef7d3287327a5fd5e3ee205/raw/url_in_title.js
// @include http://*/*
// @include https://*/*
// @grant unsafeWindow
// @grant GM_addStyle
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_xmlhttpRequest
// @grant GM_registerMenuCommand
// @grant GM_deleteValue
// @grant GM_listValues
// @grant GM_getResourceText
// @grant GM_getResourceURL
// @grant GM_log
// @grant GM_openInTab
// @grant GM_setClipboard
// @grant GM_info
// @grant GM_getMetadata
// @run-at document-load
// @connect *
// ==/UserScript==
var google = false;
function appendUrlToTitle() {
if (!document.title.endsWith("_____URL_")) {
if (document.title === "") {
setInterval(function() {
// Remove any existing URLs
document.title = (document.title.replace(/_____URL__.*_____URL_/, "") +
"_____URL__" + document.URL + "_____URL_");
// console.log("Title changed after 1s");
}, 1000);}
else {
document.title = (document.title.replace(/_____URL__.*_____URL_/, "") +
"_____URL__" + document.URL + "_____URL_");
// console.log("Title changed");
}
}
}
window.onload = function(){
appendUrlToTitle();
};
new MutationObserver(function(mutations) {
// console.log('Mutation observed');
setInterval(appendUrlToTitle, 1000);
}).observe(document.querySelector('title'), { subtree: true, characterData: true, childList: true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment