2017-07-14 05:11:06 +00:00
|
|
|
var instance
|
|
|
|
var windowWidth
|
|
|
|
var windowHeight
|
2017-07-26 08:06:36 +00:00
|
|
|
var noQueryStrings
|
2017-07-14 05:11:06 +00:00
|
|
|
|
2017-07-22 19:57:50 +00:00
|
|
|
// prefs are not loaded once before shareURL it won't work on first click.
|
2017-07-26 08:06:36 +00:00
|
|
|
var gettingPrefs = browser.storage.local.get(["instance_url","window_width","window_height","remove_querystrings"]);
|
2017-07-22 19:57:50 +00:00
|
|
|
gettingPrefs.then(onGot,onError);
|
|
|
|
|
2017-07-14 05:11:06 +00:00
|
|
|
function shareURL(){
|
|
|
|
browser.tabs.query({active: true},function(tabs){
|
|
|
|
|
2017-07-22 19:57:50 +00:00
|
|
|
// prefs are loaded again when the function is called to manage changes in the options page.
|
2017-07-26 08:06:36 +00:00
|
|
|
let gettingPrefs = browser.storage.local.get(["instance_url","window_width","window_height","remove_querystrings"]);
|
2017-07-22 19:57:50 +00:00
|
|
|
gettingPrefs.then(onGot,onError);
|
2017-07-14 05:11:06 +00:00
|
|
|
|
|
|
|
var tab = tabs[0];
|
2017-07-22 14:28:03 +00:00
|
|
|
|
2017-07-14 15:34:31 +00:00
|
|
|
// manages Mozilla Firefox reader mode
|
|
|
|
var rawUrl = tab.url;
|
2017-07-22 17:52:06 +00:00
|
|
|
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) {
|
|
|
|
rawUrl = rawUrl.split("?")[0];
|
|
|
|
}
|
|
|
|
|
2017-07-22 14:28:03 +00:00
|
|
|
var url = instance + "/bookmarks.php?action=add&address=" + encodeURIComponent(rawUrl) + "&title=" + encodeURIComponent(tabs[0].title);
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function onError(error) {
|
|
|
|
console.log(`Error: ${error}`);
|
|
|
|
}
|
|
|
|
|
2017-07-22 17:47:25 +00:00
|
|
|
function onGot(item) {
|
|
|
|
instance = item["instance_url"];
|
|
|
|
windowWidth = item["window_width"];
|
|
|
|
windowHeight = item["window_height"];
|
2017-07-26 08:06:36 +00:00
|
|
|
noQueryStrings = item["remove_querystrings"];
|
2017-07-14 05:11:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
browser.contextMenus.create({
|
|
|
|
id: "semantic-scuttle",
|
|
|
|
title: "Add to (Semantic)Scuttle",
|
|
|
|
onclick: function(){
|
|
|
|
shareURL();
|
|
|
|
},
|
|
|
|
contexts: ["all"]
|
|
|
|
});
|
|
|
|
|
|
|
|
browser.browserAction.onClicked.addListener(() => {
|
|
|
|
shareURL();
|
|
|
|
});
|