diff --git a/README b/README new file mode 100644 index 0000000..817c8fc --- /dev/null +++ b/README @@ -0,0 +1,12 @@ + +Add to (Semantic)Scuttle WebExt + +Add to (Semantic)Scuttle WebExt is a simple extension that allow to add bookmarks to a (Semantic)Scuttle instance. +(Semantic)Scuttle is a social bookmarking tool experimenting with tags and collaborative tag descriptions. + +It needs 3 parameters to work properly: +- (Semantic)Scuttle instance URL +- popup window width +- popup window height + +Source : diff --git a/background.js b/background.js new file mode 100644 index 0000000..8fb8bce --- /dev/null +++ b/background.js @@ -0,0 +1,75 @@ +var instance +var windowWidth +var windowHeight + +function shareURL(){ + browser.tabs.query({active: true},function(tabs){ + + var gettingUrl = browser.storage.local.get("instance_url"); + gettingUrl.then(onGotUrl, onError); + var gettingWidth = browser.storage.local.get("window_width"); + gettingWidth.then(onGotWidth, onError); + var gettingHeight = browser.storage.local.get("window_height"); + gettingHeight.then(onGotHeight, onError); + + var tab = tabs[0]; + + var url = instance + "bookmarks.php?action=add&address=" + encodeURIComponent(tab.url) + "&title=" + tabs[0].title; + 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 + if(new_url.includes("action=add") == false){ + browser.windows.remove(win.id); + } + } + } + }); + }); + }); +} + +function onError(error) { + console.log(`Error: ${error}`); +} + +function onGotUrl(item) { + if (item.instance_url) { + instance = item.instance_url; + } +} + +function onGotWidth(item) { + if (item.window_width) { + windowWidth = item.window_width; + } +} + +function onGotHeight(item) { + if (item.window_height) { + windowHeight = item.window_height; + } +} + +browser.contextMenus.create({ + id: "semantic-scuttle", + title: "Add to (Semantic)Scuttle", + onclick: function(){ + shareURL(); + }, + contexts: ["all"] +}); + +browser.browserAction.onClicked.addListener(() => { + shareURL(); +}); diff --git a/data/icon48.png b/data/icon48.png new file mode 100644 index 0000000..4afe565 Binary files /dev/null and b/data/icon48.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..012b7fa --- /dev/null +++ b/manifest.json @@ -0,0 +1,27 @@ +{ + "manifest_version" : 2, + "name": "Add to (Semantic)Scuttle", + "version" : "0.1", + "description" : "Allow to add bookmarks to (Semantic)Scuttle, a social bookmarking tool experimenting with tags and collaborative tag descriptions.", + "homepage_url" : "http://semanticscuttle.sourceforge.net/", + "icons" : { + "48" : "data/icon48.png" + }, + "options_ui" : { + "page": "options.html" + }, + "permissions" : [ + "storage", + "notifications", + "contextMenus", + "activeTab", + "tabs"], + "browser_action" : { + "default_title" : "Add to (Semantic)Scuttle", + "default_icon" : "data/icon48.png" + }, + "background" : { + "scripts" : ["background.js"] + } + +} diff --git a/options.html b/options.html new file mode 100644 index 0000000..b166a39 --- /dev/null +++ b/options.html @@ -0,0 +1,21 @@ + + + + + + + + + +
+
+
+
+ +
+ + + + + + diff --git a/options.js b/options.js new file mode 100644 index 0000000..a60f11a --- /dev/null +++ b/options.js @@ -0,0 +1,44 @@ +function saveOptions(e) { + e.preventDefault(); + browser.storage.local.set({ + instance_url: document.querySelector("#instance_url").value + }); + browser.storage.local.set({ + window_width: document.querySelector("#window_width").value + }); + browser.storage.local.set({ + window_height: document.querySelector("#window_height").value + }); +} + +function restoreOptions() { + + function setCurrentChoiceUrl(result) { + document.querySelector("#instance_url").value = result.instance_url || "http://semanticscuttle.sourceforge.net/"; + } + + function setCurrentChoiceWidth(result) { + document.querySelector("#window_width").value = result.window_width || "640"; + } + + function setCurrentChoiceHeight(result) { + document.querySelector("#window_height").value = result.window_height || "480"; + } + + function onError(error) { + console.log(`Error: ${error}`); + } + + var gettingUrl = browser.storage.local.get("instance_url"); + gettingUrl.then(setCurrentChoiceUrl, onError); + + var gettingWidth = browser.storage.local.get("window_width"); + gettingWidth.then(setCurrentChoiceWidth, onError); + + var gettingHeight = browser.storage.local.get("window_height"); + gettingHeight.then(setCurrentChoiceHeight, onError); + +} + +document.addEventListener("DOMContentLoaded", restoreOptions); +document.querySelector("form").addEventListener("submit", saveOptions);