Last version introduced a regression. Seems Ok now.

This commit is contained in:
Laurent Espitallier 2017-08-08 22:19:08 +02:00
parent ea41fb41bf
commit 4940b0b874
2 changed files with 16 additions and 22 deletions

View File

@ -2,28 +2,18 @@ function onError(error) {
console.log(`Error: ${error}`); console.log(`Error: ${error}`);
} }
function onGot(item) { function shareURL(selectionContent,currentTab){
instance = item["instance_url"];
windowWidth = item["window_width"];
windowHeight = item["window_height"];
noQueryStrings = item["remove_querystrings"];
}
function shareURL(donnees){
browser.tabs.query({active: true},function(tabs){
browser.storage.local.get(["instance_url","window_width","window_height","remove_querystrings"],function(item){ browser.storage.local.get(["instance_url","window_width","window_height","remove_querystrings"],function(item){
let instance = item["instance_url"]; instance = item["instance_url"];
let windowWidth = item["window_width"]; windowWidth = item["window_width"];
let windowHeight = item["window_height"]; windowHeight = item["window_height"];
let noQueryStrings = item["remove_querystrings"]; noQueryStrings = item["remove_querystrings"];
let tab = tabs[0];
// manages Mozilla Firefox reader mode // manages Mozilla Firefox reader mode
let rawUrl = tab.url; var rawUrl = currentTab.url;
let partToRemove = "about:reader?url="; var partToRemove = "about:reader?url=";
if(rawUrl.includes(partToRemove)) { if(rawUrl.includes(partToRemove)) {
rawUrl = rawUrl.substring(partToRemove.length); rawUrl = rawUrl.substring(partToRemove.length);
rawUrl = decodeURIComponent(rawUrl); rawUrl = decodeURIComponent(rawUrl);
@ -34,7 +24,7 @@ function shareURL(donnees){
rawUrl = rawUrl.split("?")[0]; rawUrl = rawUrl.split("?")[0];
} }
let url = instance + "/bookmarks.php?action=add&address=" + encodeURIComponent(rawUrl) + "&title=" + encodeURIComponent(tabs[0].title) + "&description=" + encodeURIComponent(donnees); var url = instance + "/bookmarks.php?action=add&address=" + encodeURIComponent(rawUrl) + "&title=" + encodeURIComponent(currentTab.title) + "&description=" + encodeURIComponent(selectionContent);
widthInt = Number(windowWidth); widthInt = Number(windowWidth);
heightInt = Number(windowHeight); heightInt = Number(windowHeight);
@ -57,20 +47,24 @@ function shareURL(donnees){
}); });
}); });
}); });
});
} }
browser.contextMenus.create({ browser.contextMenus.create({
id: "semantic-scuttle", id: "semantic-scuttle",
title: "Add to (Semantic)Scuttle", title: "Add to (Semantic)Scuttle",
onclick: function(){ onclick: function(){
shareURL(); browser.tabs.query({ currentWindow: true, active: true }, function(tabs) {
tab = tabs[0];
browser.tabs.sendMessage(tab.id, {method: "getSelection"}).then(response => {
shareURL(response.response,tab);
}).catch(onError);
});
}, },
contexts: ["all"] contexts: ["all"]
}); });
browser.browserAction.onClicked.addListener((tab) => { browser.browserAction.onClicked.addListener((tab) => {
browser.tabs.sendMessage(tab.id, {method: "getSelection"}).then(response => { browser.tabs.sendMessage(tab.id, {method: "getSelection"}).then(response => {
shareURL(response.response); shareURL(response.response,tab);
}).catch(onError); }).catch(onError);
}); });

View File

@ -1,7 +1,7 @@
{ {
"manifest_version" : 2, "manifest_version" : 2,
"name": "Add to (Semantic)Scuttle", "name": "Add to (Semantic)Scuttle",
"version" : "0.7", "version" : "0.7.1",
"description" : "Add bookmarks to a (Semantic)Scuttle instance, a social bookmarking tool experimenting with tags and collaborative tag descriptions.", "description" : "Add bookmarks to a (Semantic)Scuttle instance, a social bookmarking tool experimenting with tags and collaborative tag descriptions.",
"homepage_url" : "https://addons.mozilla.org/fr/firefox/addon/add-to-semantic-scuttle/", "homepage_url" : "https://addons.mozilla.org/fr/firefox/addon/add-to-semantic-scuttle/",
"icons" : { "icons" : {