Option to remove query strings from URL

This commit is contained in:
Laurent Espitallier 2017-07-26 10:06:36 +02:00
parent b127e1e9f9
commit 5edda2b0d6
5 changed files with 16 additions and 7 deletions

1
TODO
View File

@ -1,3 +1,2 @@
-Option to clean URLs (after the ?)
-Add keyboard shortcut if possible
-Bug corrections & optimizations

View File

@ -1,16 +1,17 @@
var instance
var windowWidth
var windowHeight
var noQueryStrings
// prefs are not loaded once before shareURL it won't work on first click.
var gettingPrefs = browser.storage.local.get(["instance_url","window_width","window_height"]);
var gettingPrefs = browser.storage.local.get(["instance_url","window_width","window_height","remove_querystrings"]);
gettingPrefs.then(onGot,onError);
function shareURL(){
browser.tabs.query({active: true},function(tabs){
// prefs are loaded again when the function is called to manage changes in the options page.
let gettingPrefs = browser.storage.local.get(["instance_url","window_width","window_height"]);
let gettingPrefs = browser.storage.local.get(["instance_url","window_width","window_height","remove_querystrings"]);
gettingPrefs.then(onGot,onError);
var tab = tabs[0];
@ -23,6 +24,11 @@ function shareURL(){
rawUrl = decodeURIComponent(rawUrl);
}
// manages URL query strings
if (noQueryStrings == true) {
rawUrl = rawUrl.split("?")[0];
}
var url = instance + "/bookmarks.php?action=add&address=" + encodeURIComponent(rawUrl) + "&title=" + encodeURIComponent(tabs[0].title);
widthInt = Number(windowWidth);
heightInt = Number(windowHeight);
@ -56,6 +62,7 @@ function onGot(item) {
instance = item["instance_url"];
windowWidth = item["window_width"];
windowHeight = item["window_height"];
noQueryStrings = item["remove_querystrings"];
}
browser.contextMenus.create({

View File

@ -1,9 +1,9 @@
{
"manifest_version" : 2,
"name": "Add to (Semantic)Scuttle",
"version" : "0.5",
"version" : "0.6",
"description" : "Add bookmarks to a (Semantic)Scuttle instance, a social bookmarking tool experimenting with tags and collaborative tag descriptions.",
"homepage_url" : "https://github.com/FrenchHope/Add-to-Semantic-Scuttle-WebExt",
"homepage_url" : "https://addons.mozilla.org/fr/firefox/addon/add-to-semantic-scuttle/",
"icons" : {
"48" : "data/icon48.png"
},

View File

@ -11,6 +11,7 @@
<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 />
<label>Remove querystrings from URL<input type="checkbox" id="remove_querystrings" ></label><br />
<button type="submit">Save</button>
</form>

View File

@ -3,7 +3,8 @@ function saveOptions(e) {
browser.storage.local.set({
instance_url: document.querySelector("#instance_url").value ,
window_width: document.querySelector("#window_width").value ,
window_height: document.querySelector("#window_height").value
window_height: document.querySelector("#window_height").value,
remove_querystrings: document.querySelector("#remove_querystrings").checked
});
}
@ -13,13 +14,14 @@ function restoreOptions() {
document.querySelector("#instance_url").value = result["instance_url"] || "http://semanticscuttle.sourceforge.net/";
document.querySelector("#window_width").value = result["window_width"] || "640";
document.querySelector("#window_height").value = result["window_height"] || "480";
document.querySelector("#remove_querystrings").checked = result["remove_querystrings"] || false;
}
function onError(error) {
console.log(`Error: ${error}`);
}
var getting = browser.storage.local.get(["instance_url","window_width","window_height"]);
var getting = browser.storage.local.get(["instance_url","window_width","window_height","remove_querystrings"]);
getting.then(setCurrentChoices, onError);
}