-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
58 lines (57 loc) · 1.68 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
// Get selected text
/*function getSelectedText() {
if (window.getSelection) {
return window.getSelection().toString();
} else if (document.selection) {
return document.selection.createRange().text;
}
return "";
}
// Get selected text and replace with link
function replaceSelectedText(link) {
if (window.getSelection) {
var selection = window.getSelection();
if (selection.rangeCount) {
var range = selection.getRangeAt(0);
range.deleteContents();
var el = document.createElement("a");
el.appendChild(document.createTextNode(link));
el.href = link;
el.target = "_blank";
range.insertNode(el);
}
} else if (document.selection) {
var range = document.selection.createRange();
range.text = link;
}
}
chrome.tabs.executeScript(
{
code: "window.getSelection().toString();",
},
function (selection) {
document.getElementById("output").value = selection[0];
}
);
document.getElementById("uppercase").addEventListener("click", function () {
// var text = getSelectedText();
// replaceSelectedText(text.toUpperCase());
console.log("uppercase");
console.log(getSelectedText());
});
// console.log(getSelectedText());*/
// on clicking crtl+shift+l execute the code
// document.addEventListener("keydown", function (e) {
// if (e.ctrlKey && e.shiftKey && e.key == "l") {
// console.log("ctrl+shift+l");
// chrome.tabs.executeScript(
// {
// code: "window.getSelection().toString().toUpperCase();",
// },
// function (selection) {
// console.log(selection[0]);
// }
// );
// }
// }),
// chrome tabs execute script log the selected text on console on ctrl+shift+l