Skip to content

Instantly share code, notes, and snippets.

@iglvzx
Created June 27, 2012 21:19
Show Gist options
  • Save iglvzx/3006931 to your computer and use it in GitHub Desktop.
Save iglvzx/3006931 to your computer and use it in GitHub Desktop.
Input Focus Title Change
// ==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);
@iglvzx
Copy link
Author

iglvzx commented Jun 28, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment