-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmenu.js
More file actions
30 lines (25 loc) · 894 Bytes
/
menu.js
File metadata and controls
30 lines (25 loc) · 894 Bytes
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
var item = {
"id": "replit",
"title": "Try on repl.it",
"contexts": ["selection"]
}
chrome.contextMenus.create(item);
var replLang = "";
chrome.storage.sync.get('replLang', function(result) {
if(result){
console.log(result)
replLang = result.replLang;
}
});
chrome.contextMenus.onClicked.addListener(function(data){
if(data.menuItemId == "replit" && data.selectionText){
chrome.tabs.executeScript( {
code: "window.getSelection().toString();"
}, function(selection) {
var language = prompt("What language is this code in?", replLang).replace(/\s/g,'').toLowerCase();
chrome.storage.sync.set({replLang: language}, function() {});
var replLink = `https://repl.it/languages/${language}?code=${encodeURIComponent(selection)}`;
chrome.tabs.create({ url: replLink });
});
}
})