PageRenderTime 23ms CodeModel.GetById 15ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/CVox/res/raw/halfscan.js

http://eyes-free.googlecode.com/
JavaScript | 50 lines | 39 code | 5 blank | 6 comment | 7 complexity | a87049d63255b1067a8d05dc2cc48de8 MD5 | raw file
 1
 2// ==UserScript==
 3// @name          Scan barcode into Half.com
 4// @description   Add button to Half.com search box to scan barcode
 5// @author        Jeffrey Sharkey
 6// @include       http://*m.half.com*
 7// ==/UserScript==
 8
 9function insertAfter(newElement,targetElement) {
10	var parent = targetElement.parentNode;
11	if(parent.lastchild == targetElement) {
12		parent.appendChild(newElement);
13	} else {
14		parent.insertBefore(newElement, targetElement.nextSibling);
15	}
16}
17
18function generate(item) {
19	var helper = document.createElement('input');
20	helper.type = 'button';
21	helper.value = 'Scan barcode...';
22	helper.style.background = '#cfc';
23	helper.style.color = '#484';
24	helper.style.border = '1px solid #484';
25	helper.style.padding = '5px';
26	helper.style.marginLeft = '10px';
27	helper.addEventListener('click', function(event) {
28		var result = window.intentHelper.startActivityForResult(JSON.stringify({
29			action:'com.google.zxing.client.android.SCAN',
30			category:['CATEGORY_DEFAULT']
31		}));
32		result = JSON.parse(result);
33		item.value = result['extras']['SCAN_RESULT'];
34	}, false);
35	return helper;
36}
37
38var append = [];
39var items = document.body.getElementsByTagName('input');
40for(i in items) {
41	var item = items[i];
42	if(item.name == 'query')
43		append.push([item,generate(item)]);
44}
45
46for(i in append) {
47	var target = append[i][0];
48	var generated = append[i][1];
49	insertAfter(generated, target);
50}