-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
50 lines (44 loc) · 1.32 KB
/
Copy pathcontent.js
File metadata and controls
50 lines (44 loc) · 1.32 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
let selectedElement = null;
document.addEventListener('mousedown', function(event) {
if (event.button === 2) { // Right click
selectedElement = event.target;
}
});
function changeNumber(element, newValue) {
if (element) {
element.textContent = newValue;
// Save the change
chrome.storage.local.get(['changes'], function(result) {
let changes = result.changes || [];
changes.push({
selector: uniqueSelector(element),
newValue: newValue
});
chrome.storage.local.set({changes: changes});
});
}
}
function uniqueSelector(element) {
if (element.id) return '#' + element.id;
if (element.className) return '.' + element.className.split(' ').join('.');
return element.tagName.toLowerCase();
}
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "promptChange") {
const newValue = prompt("Enter new value:", request.selection);
if (newValue !== null) {
changeNumber(selectedElement, newValue);
}
}
});
// Load and apply saved changes
chrome.storage.local.get(['changes'], function(result) {
if (result.changes) {
result.changes.forEach(change => {
const element = document.querySelector(change.selector);
if (element) {
element.textContent = change.newValue;
}
});
}
});