-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
24 lines (21 loc) · 959 Bytes
/
content.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
// content.js
document.addEventListener("keydown", function(event) {
if (event.altKey && event.key === "a") {
// Save the original clipboard content
chrome.runtime.sendMessage({ action: "saveClipboardContent" }, function(response) {
const selectedText = window.getSelection().toString().trim();
if (selectedText) {
const farsiDigits = selectedText.replace(/\d/g, function(digit) {
const persianDigits = ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"];
return persianDigits[digit];
});
// Copy the modified text to clipboard
document.execCommand('copy');
// Paste the modified text back to the active element
document.execCommand('insertText', false, farsiDigits);
// Restore the original clipboard content
chrome.runtime.sendMessage({ action: "restoreClipboardContent" });
}
});
}
});