PageRenderTime 29ms CodeModel.GetById 15ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/CVox/res/raw/email.js

http://eyes-free.googlecode.com/
JavaScript | 57 lines | 43 code | 5 blank | 9 comment | 19 complexity | bf1c9e9220ac1c0596dde79d5104b8e6 MD5 | raw file
 1
 2// ==UserScript==
 3// @name          Pick E-mail address
 4// @description   Fill forms by picking an E-mail address from Android contacts
 5// @author        Jeffrey Sharkey
 6// @include       http://*digg.com/register*
 7// @include       http://*facebook.com*
 8// @include       http://*m.yahoo.com/p/mail/compose*
 9// @include       http://*m.half.com*
10// ==/UserScript==
11
12function insertAfter(newElement,targetElement) {
13	var parent = targetElement.parentNode;
14	if(parent.lastchild == targetElement) {
15		parent.appendChild(newElement);
16	} else {
17		parent.insertBefore(newElement, targetElement.nextSibling);
18	}
19}
20
21function generate(item) {
22	var helper = document.createElement('input');
23	helper.type = 'button';
24	helper.value = 'Pick Android contact...';
25	helper.style.background = '#cfc';
26	helper.style.color = '#484';
27	helper.style.border = '1px solid #484';
28	helper.style.padding = '5px';
29	helper.style.marginLeft = '10px';
30	helper.addEventListener('click', function(event) {
31		var result = window.intentHelper.startActivityForResult(JSON.stringify({
32			action:'ACTION_GET_CONTENT',
33			type:'vnd.android.cursor.item/email'
34		}));
35		result = JSON.parse(result);
36		item.value = result['data']['data'];
37	}, false);
38	return helper;
39}
40
41var append = [];
42var items = document.body.getElementsByTagName('input');
43for(i in items) {
44	var item = items[i];
45	var digg = (item.name == 'email' || item.name == 'emailverify');
46	var facebook = (item.name == 'reg_email__');
47	var yahoo = (item.className == 'd' && (item.name.substr(0,2) == 'to' || item.name.substr(0,2) == 'cc'));
48	var half = (item.name == 'email');
49	if(digg || facebook || yahoo || half)
50		append.push([item,generate(item)]);
51}
52
53for(i in append) {
54	var target = append[i][0];
55	var generated = append[i][1];
56	insertAfter(generated, target);
57}