Created
April 8, 2010 09:29
-
-
Save xulapp/359934 to your computer and use it in GitHub Desktop.
IMESign.uc.js
This file contains hidden or 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 IMESign.uc.js | |
// @description changes background image of active textbox if IME state is open. | |
// @include * | |
// @compatibility Firefox 3.6+ | |
// @namespace http://twitter.com/xulapp | |
// @author xulapp | |
// @license MIT License | |
// @version 2010/10/11 22:20 +09:00 | |
// ==/UserScript== | |
// @version 2010/04/12 07:00 +09:00 | |
// @version 2010/04/08 18:00 +09:00 | |
(function IMESign() { | |
const {interfaces: Ci} = Components; | |
const BGIMAGE = '-moz-radial-gradient(0 0, circle, rgba(255, 128, 128, 0.8) 4px, rgba(255, 128, 128, 0) 16px)'; | |
function Watcher(textbox) { | |
this.textbox = textbox; | |
} | |
Watcher.prototype = { | |
constructor: Watcher, | |
isOpen: false, | |
init: function init() { | |
this.view = this.textbox.ownerDocument.defaultView; | |
this.util = this.view | |
.QueryInterface(Ci.nsIInterfaceRequestor) | |
.getInterface(Ci.nsIDOMWindowUtils); | |
this.textbox.addEventListener('blur', this, false, false); | |
this.view.addEventListener('unload', this, false, false); | |
this.timer = setInterval(let (self = this) function() self.effect(), 100); | |
this.effect(); | |
}, | |
destroy: function destroy() { | |
clearInterval(this.timer); | |
this.textbox.removeEventListener('blur', this, false); | |
this.view.removeEventListener('unload', this, false, false); | |
delete this.util; | |
}, | |
handleEvent: function handleEvent() { | |
this.destroy(); | |
this.effect(); | |
}, | |
effect: function effect() { | |
var {util} = this; | |
if (util) { | |
try { | |
var isOpen = util.IMEStatus === util.IME_STATUS_ENABLED && util.IMEIsOpen; | |
} catch (e) { | |
alert(e); | |
this.destroy(); | |
} | |
} | |
if (this.isOpen !== (this.isOpen = !!isOpen)) | |
this.textbox.style.backgroundImage = isOpen ? BGIMAGE : ''; | |
}, | |
}; | |
window.addEventListener('focus', function IMES_onFocus({originalTarget: target}) { | |
if (target instanceof HTMLTextAreaElement || target instanceof HTMLInputElement && /^(?:text|password)?$/.test(target.type)) | |
new Watcher(target).init(); | |
}, true, false); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment