First commit
This commit is contained in:
parent
c96dfb75e0
commit
cb94ae43eb
12
README
Normal file
12
README
Normal file
@ -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 :
|
75
background.js
Normal file
75
background.js
Normal file
@ -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();
|
||||||
|
});
|
BIN
data/icon48.png
Normal file
BIN
data/icon48.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
27
manifest.json
Normal file
27
manifest.json
Normal file
@ -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"]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
21
options.html
Normal file
21
options.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<form>
|
||||||
|
<label>(Semantic)Scuttle instance URL <input type="text" id="instance_url" ></label><br />
|
||||||
|
<label>Window Width <input type="text" id="window_width" ></label><br />
|
||||||
|
<label>Window Height <input type="text" id="window_height" ></label><br />
|
||||||
|
<button type="submit">Save</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<script src="options.js"></script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
44
options.js
Normal file
44
options.js
Normal file
@ -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);
|
Loading…
Reference in New Issue
Block a user