Created
June 27, 2012 21:19
-
-
Save iglvzx/3006931 to your computer and use it in GitHub Desktop.
Input Focus Title Change
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
// ==UserScript== | |
// @name InputFocusTitleChange | |
// @namespace http://igalvez.net | |
// @include * | |
// @author Izzy Galvez (iglvzx) | |
// @description Adds/Removes '[AHK]' to the Title when an input/textarea element gains/loses focus. | |
// @version 1.0 | |
// ==/UserScript== | |
// Import jQuery | |
function addJQuery(callback) { | |
var script = document.createElement("script"); | |
script.setAttribute("src", "https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"); | |
script.addEventListener('load', function() { | |
var script = document.createElement("script"); | |
script.textContent = "(" + callback.toString() + ")();"; | |
document.body.appendChild(script); | |
}, false); | |
document.body.appendChild(script); | |
} | |
// Script | |
function main() { | |
var title = document.title; | |
var elements = ['input', 'textarea']; | |
for (var i = 0; i < elements.length; i++) { | |
$(elements[i]).each(function() { | |
$(this).focus(function() { | |
document.title = title + ' [AHK]'; | |
}); | |
$(this).blur(function() { | |
document.title = title; | |
}); | |
}); | |
} | |
} | |
// Run | |
addJQuery(main); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See: http://superuser.com/a/442846/100787