-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent-script.js
More file actions
62 lines (49 loc) · 1.43 KB
/
content-script.js
File metadata and controls
62 lines (49 loc) · 1.43 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
// Mendix Role Inspector Content Script
function getRoleInfo() {
const info = {
roles: [],
error: null
};
try {
const bodyElement = document.body;
if (bodyElement && bodyElement.classList) {
const classList = Array.from(bodyElement.classList);
info.roles = classList
.filter(className => className.startsWith('role-'))
.map(className => className.replace('role-', ''))
.filter(role => role.length > 0);
}
if (info.roles.length === 0) {
info.error = chrome.i18n ? chrome.i18n.getMessage('roleNotFound') : "Role information not found";
}
} catch (error) {
const errorMsg = chrome.i18n ? chrome.i18n.getMessage('error') : "Error";
info.error = `${errorMsg}: ${error.message}`;
}
return info;
}
function sendRoleInfoToPopup() {
const roleInfo = getRoleInfo();
chrome.runtime.sendMessage({
type: 'ROLE_INFO',
data: roleInfo
});
}
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.type === 'GET_ROLE_INFO') {
const roleInfo = getRoleInfo();
sendResponse(roleInfo);
}
});
let lastRoles = [];
function checkForRoleChanges() {
const currentInfo = getRoleInfo();
const currentRoles = JSON.stringify(currentInfo.roles);
if (currentRoles !== JSON.stringify(lastRoles)) {
lastRoles = currentInfo.roles;
sendRoleInfoToPopup();
}
}
setTimeout(() => {
sendRoleInfoToPopup();
}, 1000);