forked from burgyl/AddToShaarli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
42 lines (40 loc) · 1.54 KB
/
background.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
var shaarliInstance = "https://example.com/";
function addUrl(tab)
{
chrome.storage.sync.get({ savedShaarliInstance: "https://example.com/"}, function (items)
{
shaarliInstance = items.savedShaarliInstance;
const myCode = "!function(){var o=location.href,e=document.title||o;const popup=window.open(\"" + shaarliInstance + "?post=\"+encodeURIComponent(o)+\"&title=\"+encodeURIComponent(e)+\"&description=\"+encodeURIComponent(document.getSelection())+\"&source=bookmarklet\",\"_blank\",\"menubar=no,height=800,width=600,toolbar=no,scrollbars=yes,status=no,dialog=1\")}();";
chrome.tabs.query({
active: true
}, function(tab) {
chrome.tabs.executeScript({
code: myCode
});
});
});
}
function addNote()
{
chrome.storage.sync.get({
savedShaarliInstance: "https://example.com/"
}, function (items) {
shaarliInstance = items.savedShaarliInstance;
const mCode = "!function(){var o=location.href,e=document.title||o;const popup=window.open(\"" + shaarliInstance + "?post=\"+\"&description=\"+encodeURIComponent(document.getSelection()),\"_blank\",\"menubar=no,height=800,width=600,toolbar=no,scrollbars=yes,status=no,dialog=1\")}();";
chrome.tabs.query({
active: true
}, function(tab) {
chrome.tabs.executeScript({
code: mCode
});
});
});
}
chrome.commands.onCommand.addListener(function(command, tab) {
if (command == "add-url") {
addUrl(tab);
}
if (command == "add-note") {
addNote();
}
});