From cb94ae43eb60b979e22c2b2c75d34ae5af9095ef Mon Sep 17 00:00:00 2001 From: FrenchHope Date: Fri, 14 Jul 2017 07:11:06 +0200 Subject: [PATCH] First commit --- README | 12 ++++++++ background.js | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ data/icon48.png | Bin 0 -> 2973 bytes manifest.json | 27 +++++++++++++++++ options.html | 21 ++++++++++++++ options.js | 44 ++++++++++++++++++++++++++++ 6 files changed, 179 insertions(+) create mode 100644 README create mode 100644 background.js create mode 100644 data/icon48.png create mode 100644 manifest.json create mode 100644 options.html create mode 100644 options.js 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 0000000000000000000000000000000000000000..4afe5653f548b4b74ea0ecdb727ea2d7ac12a091 GIT binary patch literal 2973 zcmV;O3u5$%P)goj-97KwhiC2V3PP2ldJ3g;d6n8G9?K;-nbmfpSUq#CUJ0lX6J}IALW+ z#Th(ACNE@i0;bjV0463;7)ztZW8mlBgC+9Iz`bue0pMf6t(mbYh&+b&=h{{e+Q5S@ z3CA%E3_94^5i;X9Vho=vmt^EkBTz2MO~B`!!X)BkDUN4xoM?m9yI1wWwBm%uCwuT# z?DW8xQU3K!ApxIPq0%pnVk!u-o5l)~?iOta|t> zFVk9l9*tTp;CsLifM;-ObsaLgFy0Ajv84w|C%o9{+i5d$SzY5?3r+}x3i^2b$Ij#In&SAZjiX zx{HLhIiltgKm+(8@Lk~HspDGh5_suzY z0Qr$T1ET|E3t7aHt*x81azFiR2rtCOL_*6AX}JM@BP0w##0C^^{uJKADFxm>bzGlw zfDd$l7sd;WUOP%|IEQ6zH9f3EC%O+Q_$Q1`b zEW!X<^?>?Sm(0Gm;VqmJ;C;Yz4sZpy4j^01k{``)9Z4I+fEpl707!ts+ND0)tS70D z4d6I7)}T#ov4y`n4ZvcRrK$KyPIO=`UtFfK(%1!oUa#~nTHCJ&8}w#(`jwe01a1Xy z{#jZ9i@*CIGa@o>0pDnaoCHAO@(Y*on_JFUyCBjo9lBuK1)W(hDK_bQ!FHcr*H^AA z<6d2(dHEz7x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8xSWA6^TA zY<%g&dfd5JX;5FO;ZbbIjZ^rMDf~SG&F7*WN;P z7CSqN@rUs$b!~vlvJ-)qfm%?RF50;<>WvCfb2&bUZ7!p#y4v8>vln^v z(~t1OHMhT|?thfi_dm+%V{c>sz3=9OMe%LK_dqsg| zU`|!Lp(G+1;{Q%uL(lAT>k$S&@(yl3JkDFZ0QZ3>dEzJMskCoDuc{UL$gT*8$c+%6 z8EqpW@iFCP)&4IhL_~lIV3HoM^pTU>^|zZ^2w;)^1lE9gU`bW`d8I4u;%pIE6p;e4 zSN8Y8vbG&~*rf*mL}U^;1f+mEacnPawM%-fA|e(rM(mkE;+ba^cvW@Vqd)#11OE3^ T8>YXG00000NkvXXu0mjfBm9@% literal 0 HcmV?d00001 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);