-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventPAge.js
67 lines (51 loc) · 1.76 KB
/
eventPAge.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
var menuItem = {
"id": "Ark",
"title": "Papyrus - Add in the Notepad",
"contexts": ["selection"]
};
const key = "thisisthelegitkeyforthisproject";
chrome.contextMenus.create(menuItem);
function updateStore(storeKey, data) {
let obj = {};
obj[storeKey] = JSON.stringify(data);
chrome.storage.sync.set(obj);
var notifOptions = {
type: "basic",
iconUrl: "icon48.png",
title: "Text Added!",
message: "The selected text was added to Papyrus Notepad"
};
chrome.notifications.create('AddedNotify', notifOptions);
}
chrome.contextMenus.onClicked.addListener(function (clickData) {
if (clickData.menuItemId == "Ark" && clickData.selectionText) {
if ((clickData.selectionText)) {
chrome.storage.sync.get(key, result => {
let data = JSON.parse(result[key]);
let prevContent = data.notepadContent;
let obj = Object.assign(data, {
notepadContent: prevContent + ' ' + clickData.selectionText,
});
updateStore(key, obj)
});
}
}
});
// For Wikipedia
/* function fixedEncodeURI (str) {
return encodeURI(str).replace(/%5B/g, '[').replace(/%5D/g, ']');
}
chrome.contextMenus.onClicked.addListener(function(clickData){
if (clickData.menuItemId == "Wikit" && clickData.selectionText){
var wikiUrl = "https://en.wikipedia.org/wiki/" + fixedEncodeURI(clickData.selectionText);
var createData = {
"url": wikiUrl,
"type": "popup",
"top": 5,
"left": 5,
"width": screen.availWidth/2,
"height": screen.availHeight/2
};
chrome.windows.create(createData, function(){});
}
}); */