2017-08-07 16:23:51 +00:00
|
|
|
function onError(error) {
|
|
|
|
console.log(`Error: ${error}`);
|
|
|
|
}
|
|
|
|
|
2017-08-08 20:19:08 +00:00
|
|
|
function shareURL(selectionContent,currentTab){
|
2017-07-14 05:11:06 +00:00
|
|
|
|
2017-08-12 16:25:57 +00:00
|
|
|
browser.storage.local.get(["instance_url","window_width","window_height","remove_querystrings","exceptUrlList"],function(item){
|
2017-08-07 16:23:51 +00:00
|
|
|
|
2017-08-08 20:19:08 +00:00
|
|
|
instance = item["instance_url"];
|
|
|
|
windowWidth = item["window_width"];
|
|
|
|
windowHeight = item["window_height"];
|
|
|
|
noQueryStrings = item["remove_querystrings"];
|
2017-08-12 16:25:57 +00:00
|
|
|
exceptUrlList = item["exceptUrlList"];
|
2017-07-22 14:28:03 +00:00
|
|
|
|
2017-07-14 15:34:31 +00:00
|
|
|
// manages Mozilla Firefox reader mode
|
2017-08-08 20:19:08 +00:00
|
|
|
var rawUrl = currentTab.url;
|
|
|
|
var partToRemove = "about:reader?url=";
|
2017-07-14 15:34:31 +00:00
|
|
|
if(rawUrl.includes(partToRemove)) {
|
|
|
|
rawUrl = rawUrl.substring(partToRemove.length);
|
|
|
|
rawUrl = decodeURIComponent(rawUrl);
|
2017-07-22 17:52:06 +00:00
|
|
|
}
|
2017-07-22 14:28:03 +00:00
|
|
|
|
2017-07-26 08:06:36 +00:00
|
|
|
// manages URL query strings
|
|
|
|
if (noQueryStrings == true) {
|
2017-08-12 16:25:57 +00:00
|
|
|
var flagRemove = true;
|
|
|
|
var urlList = exceptUrlList.split(/,\s*/);
|
|
|
|
urlList.forEach(function(baseUrl) {
|
|
|
|
if (rawUrl.startsWith(baseUrl)) {
|
|
|
|
flagRemove = false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (flagRemove) {rawUrl = rawUrl.split("?")[0];}
|
2017-07-26 08:06:36 +00:00
|
|
|
}
|
|
|
|
|
2017-08-08 20:19:08 +00:00
|
|
|
var url = instance + "/bookmarks.php?action=add&address=" + encodeURIComponent(rawUrl) + "&title=" + encodeURIComponent(currentTab.title) + "&description=" + encodeURIComponent(selectionContent);
|
2017-07-14 05:11:06 +00:00
|
|
|
widthInt = Number(windowWidth);
|
|
|
|
heightInt = Number(windowHeight);
|
|
|
|
|
|
|
|
browser.windows.create({
|
|
|
|
url: url,
|
|
|
|
width: widthInt,
|
|
|
|
height: heightInt,
|
|
|
|
type: "popup"
|
|
|
|
},(win)=>{
|
|
|
|
browser.tabs.onUpdated.addListener((tabId,changeInfo) =>{
|
|
|
|
if(tabId === win.tabs[0].id){
|
|
|
|
if(changeInfo.url){
|
|
|
|
var new_url
|
|
|
|
new_url = changeInfo.url
|
2017-07-14 14:11:27 +00:00
|
|
|
if((new_url.includes("action=add") == false) && (new_url.includes("edit.php") == false)){
|
2017-07-14 05:11:06 +00:00
|
|
|
browser.windows.remove(win.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
browser.contextMenus.create({
|
|
|
|
id: "semantic-scuttle",
|
|
|
|
title: "Add to (Semantic)Scuttle",
|
|
|
|
onclick: function(){
|
2017-08-08 20:19:08 +00:00
|
|
|
browser.tabs.query({ currentWindow: true, active: true }, function(tabs) {
|
|
|
|
tab = tabs[0];
|
2017-08-09 18:38:35 +00:00
|
|
|
if((tab.url.includes("about:reader?url=") == true) || (tab.url.includes("https://addons.mozilla.org/") == true)){
|
2017-08-09 18:17:11 +00:00
|
|
|
shareURL("",tab);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-08 20:19:08 +00:00
|
|
|
browser.tabs.sendMessage(tab.id, {method: "getSelection"}).then(response => {
|
|
|
|
shareURL(response.response,tab);
|
|
|
|
}).catch(onError);
|
2017-08-09 18:17:11 +00:00
|
|
|
}
|
2017-08-08 20:19:08 +00:00
|
|
|
});
|
2017-07-14 05:11:06 +00:00
|
|
|
},
|
|
|
|
contexts: ["all"]
|
|
|
|
});
|
|
|
|
|
2017-08-07 16:23:51 +00:00
|
|
|
browser.browserAction.onClicked.addListener((tab) => {
|
2017-08-09 19:00:23 +00:00
|
|
|
if((tab.url.includes("about:reader?url=") == true) || (tab.url.includes("https://addons.mozilla.org/") == true)){
|
2017-08-09 18:17:11 +00:00
|
|
|
shareURL("",tab);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 19:00:23 +00:00
|
|
|
browser.tabs.sendMessage(tab.id, {method: "getSelection"}).then(response => {
|
2017-08-08 20:19:08 +00:00
|
|
|
shareURL(response.response,tab);
|
2017-08-07 16:23:51 +00:00
|
|
|
}).catch(onError);
|
2017-08-09 18:17:11 +00:00
|
|
|
}
|
2017-07-14 05:11:06 +00:00
|
|
|
});
|