-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
135 lines (118 loc) · 4.77 KB
/
popup.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Sample fieldValues object
const fieldValues = {
email: {
keywords: ["email", "e-mail", "user email"],
value: "[email protected]",
},
name: {
keywords: ["name", "full name", "your name"],
value: "Rama Shankar Jha",
},
phone: {
keywords: ["phone", "phone number", "mobile number"],
value: "+918210601529",
},
telegram: {
keywords: ["telegram", "telegram username", "tg"],
value: "@iloveedgeware",
},
twitter: {
keywords: ["twitter", "twitter handle", "x handle", "x username"],
value: "https://x.com/rama_vats",
},
company: {
keywords: ["company", "workplace", "company name", "project name"],
value: "EdgewareDAO",
},
linkedin: {
keywords: ["linkedin", "linkedin profile", "linkedin username"],
value: "https://www.linkedin.com/in/rama-jha/",
},
designation: {
keywords: ["role", "designation", "company role"],
value: "JavaScript Developer",
},
ordinals_address: {
keywords: ["ordinals", "ordinals address"],
value: "bc1p99rj2a2es3pc87lsnkn3rcptn4sux4gzu49egawvhxpyv73qp7kqjscvnk",
},
customFields: [] // Array to hold custom fields
};
// Function to populate input fields with existing values
function populateFields() {
for (const field in fieldValues) {
if (field !== 'customFields') { // Skip customFields
const input = document.getElementById(field);
if (input) {
input.value = fieldValues[field].value; // Set the value of the input field
}
}
}
}
// Function to save the values from the input fields back to fieldValues
function saveValues() {
let allSaved = true; // Flag to check if all fields are saved successfully
const customFieldsContainer = document.getElementById('customFieldsContainer');
// Clear previous custom fields
fieldValues.customFields = [];
// Save predefined fields
for (const field in fieldValues) {
if (field !== 'customFields') { // Skip customFields
const input = document.getElementById(field);
if (input) {
fieldValues[field].value = input.value; // Update the value in fieldValues
}
}
}
// Save custom fields
const customFields = customFieldsContainer.getElementsByClassName('customField');
for (let i = 0; i < customFields.length; i++) {
const labelInput = customFields[i].querySelector('.customFieldLabel');
const keywordInput = customFields[i].querySelector('.customFieldKeywords');
const valueInput = customFields[i].querySelector('.customFieldValue');
const label = labelInput.value.trim();
const keywords = keywordInput.value.trim().split(',').map(k => k.trim());
const value = valueInput.value.trim();
if (label && value) {
fieldValues.customFields.push({ label, keywords, value }); // Add non-empty custom fields to the array
}
}
// Display save status message
const saveMessage = document.getElementById('saveMessage');
if (allSaved) {
saveMessage.textContent = 'All fields saved successfully!';
saveMessage.style.color = 'green';
} else {
saveMessage.textContent = 'Some fields were not saved. Please check your inputs.';
saveMessage.style.color = 'red';
}
console.log('Values saved:', fieldValues); // You can replace this with actual saving logic
}
// Function to add a custom field
function addCustomField() {
const customFieldsContainer = document.getElementById('customFieldsContainer');
const customFieldDiv = document.createElement('div');
customFieldDiv.className = 'customField';
const labelInput = document.createElement('input');
labelInput.type = 'text';
labelInput.className = 'customFieldLabel';
labelInput.placeholder = 'Custom Field Label';
const keywordInput = document.createElement('input');
keywordInput.type = 'text';
keywordInput.className = 'customFieldKeywords';
keywordInput.placeholder = 'Keywords (comma separated)';
const valueInput = document.createElement('input');
valueInput.type = 'text';
valueInput.className = 'customFieldValue';
valueInput.placeholder = 'Custom Field Value';
customFieldDiv.appendChild(labelInput);
customFieldDiv.appendChild(keywordInput);
customFieldDiv.appendChild(valueInput);
customFieldsContainer.appendChild(customFieldDiv);
}
// Event listener for the save button
document.getElementById('save').addEventListener('click', saveValues);
// Event listener for the add custom field button
document.getElementById('addCustomField').addEventListener('click', addCustomField);
// Populate fields when the popup is opened
populateFields();