-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
89 lines (85 loc) · 2.17 KB
/
background.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
chrome.runtime.onInstalled.addListener(() => {});
let locators;
let options = [
"Locators",
"XPath",
"unique",
"CSharp",
"Python",
"Ruby",
"Java",
];
chrome.contextMenus.onClicked.addListener((x) => {
const re = /locators-(\d+)-(\d+)/gm;
console.log(x.menuItemId);
let matches;
if ((matches = re.exec(x.menuItemId)) !== null) {
console.log("sending copy to tab", matches);
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
type: "copy",
data: locators[matches[1]][matches[2]],
});
});
}
});
chrome.runtime.onMessage.addListener(function (message) {
if (message.type == "locators") {
data = message.data;
locators = data;
chrome.contextMenus.removeAll();
chrome.contextMenus.create({
id: "parent",
title: "Web element inspector",
contexts: ["all"],
});
chrome.contextMenus.create({
id: "Locators",
parentId: "parent",
title: "Locators",
contexts: ["all"],
});
chrome.contextMenus.create({
id: "XPath",
parentId: "parent",
title: "XPath",
contexts: ["all"],
});
chrome.contextMenus.create({
id: "CSharp",
parentId: "parent",
title: "C#",
contexts: ["all"],
});
chrome.contextMenus.create({
id: "Python",
parentId: "parent",
title: "Python",
contexts: ["all"],
});
chrome.contextMenus.create({
id: "Ruby",
parentId: "parent",
title: "Ruby",
contexts: ["all"],
});
chrome.contextMenus.create({
id: "Java",
parentId: "parent",
title: "Java",
contexts: ["all"],
});
for (let i = 0; i < data.length; i++) {
for (let j = 0; j < data[i].length; j++) {
if (i !== 2 && data[i][j] != "DISREGARD") {
chrome.contextMenus.create({
id: `locators-${i}-${j}`,
parentId: options[i],
title: (data[2][j] ? "\u2714\uFE0F " : "\u274C ") + data[i][j],
contexts: ["all"],
});
}
}
}
}
});