Bug correction & new feature : selection is copied to description field
This commit is contained in:
parent
5edda2b0d6
commit
5f1e39f123
1
TODO
1
TODO
@ -1,2 +1 @@
|
|||||||
-Add keyboard shortcut if possible
|
-Add keyboard shortcut if possible
|
||||||
-Bug corrections & optimizations
|
|
||||||
|
@ -1,18 +1,28 @@
|
|||||||
var instance
|
var instance;
|
||||||
var windowWidth
|
var windowWidth;
|
||||||
var windowHeight
|
var windowHeight;
|
||||||
var noQueryStrings
|
var noQueryStrings;
|
||||||
|
|
||||||
// prefs are not loaded once before shareURL it won't work on first click.
|
function onError(error) {
|
||||||
var gettingPrefs = browser.storage.local.get(["instance_url","window_width","window_height","remove_querystrings"]);
|
console.log(`Error: ${error}`);
|
||||||
gettingPrefs.then(onGot,onError);
|
}
|
||||||
|
|
||||||
function shareURL(){
|
function onGot(item) {
|
||||||
|
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.tabs.query({active: true},function(tabs){
|
||||||
|
|
||||||
// prefs are loaded again when the function is called to manage changes in the options page.
|
browser.storage.local.get(["instance_url","window_width","window_height","remove_querystrings"],function(item){
|
||||||
let gettingPrefs = browser.storage.local.get(["instance_url","window_width","window_height","remove_querystrings"]);
|
|
||||||
gettingPrefs.then(onGot,onError);
|
instance = item["instance_url"];
|
||||||
|
windowWidth = item["window_width"];
|
||||||
|
windowHeight = item["window_height"];
|
||||||
|
noQueryStrings = item["remove_querystrings"];
|
||||||
|
|
||||||
var tab = tabs[0];
|
var tab = tabs[0];
|
||||||
|
|
||||||
@ -29,7 +39,7 @@ function shareURL(){
|
|||||||
rawUrl = rawUrl.split("?")[0];
|
rawUrl = rawUrl.split("?")[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
var url = instance + "/bookmarks.php?action=add&address=" + encodeURIComponent(rawUrl) + "&title=" + encodeURIComponent(tabs[0].title);
|
var url = instance + "/bookmarks.php?action=add&address=" + encodeURIComponent(rawUrl) + "&title=" + encodeURIComponent(tabs[0].title) + "&description=" + encodeURIComponent(donnees);
|
||||||
widthInt = Number(windowWidth);
|
widthInt = Number(windowWidth);
|
||||||
heightInt = Number(windowHeight);
|
heightInt = Number(windowHeight);
|
||||||
|
|
||||||
@ -52,17 +62,7 @@ function shareURL(){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
function onError(error) {
|
|
||||||
console.log(`Error: ${error}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onGot(item) {
|
|
||||||
instance = item["instance_url"];
|
|
||||||
windowWidth = item["window_width"];
|
|
||||||
windowHeight = item["window_height"];
|
|
||||||
noQueryStrings = item["remove_querystrings"];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
browser.contextMenus.create({
|
browser.contextMenus.create({
|
||||||
@ -74,6 +74,8 @@ browser.contextMenus.create({
|
|||||||
contexts: ["all"]
|
contexts: ["all"]
|
||||||
});
|
});
|
||||||
|
|
||||||
browser.browserAction.onClicked.addListener(() => {
|
browser.browserAction.onClicked.addListener((tab) => {
|
||||||
shareURL();
|
browser.tabs.sendMessage(tab.id, {method: "getSelection"}).then(response => {
|
||||||
|
shareURL(response.response);
|
||||||
|
}).catch(onError);
|
||||||
});
|
});
|
||||||
|
7
content-script.js
Normal file
7
content-script.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
browser.runtime.onMessage.addListener(request => {
|
||||||
|
if (request.method == "getSelection") {
|
||||||
|
return Promise.resolve({response: window.getSelection().toString()});
|
||||||
|
} else {
|
||||||
|
return Promise.resolve({});
|
||||||
|
}
|
||||||
|
});
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"manifest_version" : 2,
|
"manifest_version" : 2,
|
||||||
"name": "Add to (Semantic)Scuttle",
|
"name": "Add to (Semantic)Scuttle",
|
||||||
"version" : "0.6",
|
"version" : "0.7",
|
||||||
"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" : {
|
||||||
@ -27,8 +27,13 @@
|
|||||||
"default_title" : "Add to (Semantic)Scuttle",
|
"default_title" : "Add to (Semantic)Scuttle",
|
||||||
"default_icon" : "data/icon48.png"
|
"default_icon" : "data/icon48.png"
|
||||||
},
|
},
|
||||||
|
"content_scripts": [
|
||||||
|
{
|
||||||
|
"matches": ["<all_urls>"],
|
||||||
|
"js": ["content-script.js"]
|
||||||
|
}
|
||||||
|
],
|
||||||
"background" : {
|
"background" : {
|
||||||
"scripts" : ["background.js"]
|
"scripts" : ["background.js"]
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user