URL exception list for remove querystrings feature

This commit is contained in:
Laurent Espitallier 2017-08-12 18:25:57 +02:00
parent 98decf9a49
commit af507b10b4
4 changed files with 17 additions and 7 deletions

View File

@ -4,12 +4,13 @@ function onError(error) {
function shareURL(selectionContent,currentTab){
browser.storage.local.get(["instance_url","window_width","window_height","remove_querystrings"],function(item){
browser.storage.local.get(["instance_url","window_width","window_height","remove_querystrings","exceptUrlList"],function(item){
instance = item["instance_url"];
windowWidth = item["window_width"];
windowHeight = item["window_height"];
noQueryStrings = item["remove_querystrings"];
exceptUrlList = item["exceptUrlList"];
// manages Mozilla Firefox reader mode
var rawUrl = currentTab.url;
@ -21,7 +22,14 @@ function shareURL(selectionContent,currentTab){
// manages URL query strings
if (noQueryStrings == true) {
rawUrl = rawUrl.split("?")[0];
var flagRemove = true;
var urlList = exceptUrlList.split(/,\s*/);
urlList.forEach(function(baseUrl) {
if (rawUrl.startsWith(baseUrl)) {
flagRemove = false
}
});
if (flagRemove) {rawUrl = rawUrl.split("?")[0];}
}
var url = instance + "/bookmarks.php?action=add&address=" + encodeURIComponent(rawUrl) + "&title=" + encodeURIComponent(currentTab.title) + "&description=" + encodeURIComponent(selectionContent);

View File

@ -39,9 +39,9 @@
"commands": {
"_execute_browser_action": {
"suggested_key": {
"default": "Alt+Shift+S"
"default": "Alt+Shift+S"
},
"description": "dd to (Semantic)Scuttle keyboard shortcut"
"description": "Add to (Semantic)Scuttle keyboard shortcut"
}
}
}

View File

@ -11,7 +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 />
<label>Remove querystrings from URL <input type="checkbox" id="remove_querystrings" ></label><label> Except for (separated by commas) <input type="text" id="exceptUrlList"></label><br />
<button type="submit">Save</button>
</form>

View File

@ -4,7 +4,8 @@ function saveOptions(e) {
instance_url: document.querySelector("#instance_url").value ,
window_width: document.querySelector("#window_width").value ,
window_height: document.querySelector("#window_height").value,
remove_querystrings: document.querySelector("#remove_querystrings").checked
remove_querystrings: document.querySelector("#remove_querystrings").checked,
exceptUrlList: document.querySelector("#exceptUrlList").value
});
}
@ -15,13 +16,14 @@ function restoreOptions() {
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;
document.querySelector("#exceptUrlList").value = result["exceptUrlList"] || "https://www.google.fr,https://www.youtube.com,http://lalist.inist.fr,https://www.qwant.com";
}
function onError(error) {
console.log(`Error: ${error}`);
}
var getting = browser.storage.local.get(["instance_url","window_width","window_height","remove_querystrings"]);
var getting = browser.storage.local.get(["instance_url","window_width","window_height","remove_querystrings","exceptUrlList"]);
getting.then(setCurrentChoices, onError);
}