-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
65 lines (57 loc) · 2.3 KB
/
content.js
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
console.log('Tab script:');
chrome.runtime.onMessage.addListener(
async function (request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
// document.body.style.backgroundColor = "orange";
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
const inputField = getElementByXpath("/html/body/div[1]/div/div[3]/div/div/div[2]/div/div/div[2]/div/div[1]/div/div[1]/div/div/div/div/input")
inputField.focus()
inputField.value = request.attendee.name
var event = new UIEvent("change", {
"view": window,
"bubbles": true,
"cancelable": true
});
inputField.dispatchEvent(event);
console.log('tunggu')
// await new Promise(resolve => setTimeout(resolve, 5000));
// console.log('nah')
// const checkField = getElementByXpath("/html/body/div[1]/div/div[3]/div/div/div[2]/div/div/div[2]/div/div[2]/div/div/div/div[1]/div[2]/div/div/div/div[5]/div/span/span[1]/input")
// checkField.checked = true
// var event = new UIEvent("change", {
// "view": window,
// "bubbles": true,
// "cancelable": true
// });
// checkField.dispatchEvent(event);
// checkField.checked = true
// simulateMouseClick(checkField);
// checkField.dispatchEvent(
// new MouseEvent(mouseEventType, {
// view: window,
// bubbles: true,
// cancelable: true,
// buttons: 1
// })
// )
const mouseClickEvents = ['mousedown', 'click', 'mouseup'];
function simulateMouseClick(element) {
mouseClickEvents.forEach(mouseEventType =>
element.dispatchEvent(
new MouseEvent(mouseEventType, {
view: window,
bubbles: true,
cancelable: true,
buttons: 1
})
)
);
}
// if (request.attendee)
// sendResponse({ farewell: "goodbye" });
}
);