forked from yogeshmundada/appu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent_script_process_fpi.js
More file actions
93 lines (78 loc) · 2.98 KB
/
content_script_process_fpi.js
File metadata and controls
93 lines (78 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
function test_if_simulate_click_worked(mutations, observer, simulate_done_timer, css_selector) {
if ($(css_selector).length > 0) {
console.log("APPU DEBUG: Simulate click was successful");
observer.disconnect();
window.clearTimeout(simulate_done_timer);
var message = {};
message.type = "simulate_click_done";
chrome.extension.sendMessage("", message);
}
}
function execute_simulate_click(message, sender, send_response) {
var element_to_click = apply_css_filter(apply_css_selector($(document), message.css_selector),
message.css_filter);
var detect_change_css = message.detect_change_css;
//Hard timeout
//Wait for 60 seconds before sending event that click cannot be
//completed.
var simulate_done_timer = window.setTimeout(function() {
var message = {};
message.type = "simulate_click_done";
chrome.extension.sendMessage("", message);
}, 30 * 1000);
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var observer = new MutationObserver(function(mutations, observer) {
test_if_simulate_click_worked(mutations, observer, simulate_done_timer, detect_change_css);
});
//var config = { attributes: true, childList: true, characterData: true }
var config = { subtree: true, characterData: true, childList: true, attributes: true };
observer.observe(document, config);
//Now do the actual click
try {
//Commenting following as thats not foolproof
//$(element_to_click).trigger("click");
//Instead using following, thanks to SO: http://goo.gl/9zCJiu
//jsFiddle: http://jsfiddle.net/UtzND/26/
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent('click', true, true, window,
0, 0, 0, 0, 0, false, false,
false, false, 0, null);
$(element_to_click)[0].dispatchEvent(evt);
}
catch(e) {
console.log("Here here: " + JSON.stringify(e));
}
test_if_simulate_click_worked(undefined, observer, simulate_done_timer, detect_change_css);
}
function get_current_page_html(message, sender, send_response) {
window.setTimeout(function() {
//To give each element unique-id
$(function() { $('*').each(function(i) { $(this).attr('appu_uid', i);}); });
//To make each element visible or hidden
$(function() {
$('*').each(function(i) {
if ($(this).is(":visible")) {
$(this).attr('appu_rendering', "visible");
}
else {
$(this).attr('appu_rendering', "hidden");
}
});
});
var all_vals = {};
var all_input_elements = $(":input[type='text'], " +
":input[type='tel'], " +
":input[type='email'], " +
"select");
for (var i = 0; i < all_input_elements.length; i++) {
var uid = $(all_input_elements[i]).attr("appu_uid");
var val = $('[appu_uid='+ uid +']').val();
all_vals[uid] = val;
}
var html_data = $("html").html();
send_response({
'html_data' : html_data,
'all_vals' : all_vals
});
}, 2000);
}