forked from CompositeLight/currentRMS-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_field_alert
52 lines (39 loc) · 1.72 KB
/
custom_field_alert
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
// Dan Ridd's custom field alert box
// This is a basic code for creating an alert popup based on a custom field.
// Copy this to the bottom of content.js
// Custom field alert box FAO Dan Ridd
// Copy this to the bottom of content.js
var customField = "Example Field"; // Enter the name of the custom field here.
//
function findNextSpanByText(text) {
// Find all span elements with class "field_value"
var customFields = document.querySelectorAll('.field_label');
// Loop through each found element
for (var i = 0; i < customFields.length; i++) {
// Check if the inner text of the current element matches the specified text
if (customFields[i].textContent.trim().includes(text)) {
// Get the next sibling element (immediately following span)
var nextSpan = customFields[i].nextElementSibling;
// Check if the next sibling exists and is a span element
if (nextSpan && nextSpan.tagName.toLowerCase() === 'span') {
return nextSpan;
}
}
}
// Return null if no matching element is found
return null;
}
var alertSpan1 = findNextSpanByText(customField);
var orderView = document.querySelectorAll('a[name="activities"][class="anchor"]');
var orderView = document.querySelectorAll('a[name="activities"][class="anchor"]');
if (orderView.length != 0){
orderView = true;
} else {
orderView = false;
}
console.log(orderView);
// Check if a matching span was found
if (orderView && alertSpan1 && alertSpan1.textContent.trim().length > 0){ // potentially add other or different conditionals here, like alertSpan1.textContent == "This value"
// potentially add other conditionals here
alert(alertSpan1.textContent);
}