Google can't possibly compare your generated "crawlable" content to the actual content the user sees because of Javascript, therefore it can't detect whether the cloaking you're doing is ethical or not and it must assume the worst. What would prevent someone unethical to do exactly the same thing as you do except have the javascript display malicious content?
Second, you can't reliably detect search engines. Google is known to crawl pages with undetectable user-agents (ex: a regular-looking firefox user-agent) to make sure the content seen by Googlebot is the same as that seen by regular users. You can't just sniff crawlers reliably by their user-agent.
Sorry but I don't think this can possibly work in practice.