diff --git a/webextension/background.js b/webextension/background.js index a4dc205..c7f778c 100644 --- a/webextension/background.js +++ b/webextension/background.js @@ -41,6 +41,7 @@ browser.runtime.onMessage.addListener (function(request, sender, sendResponse) if (request.keyword) options.keyword = request.keyword; + YOURLS (settings, options).then(function(result) { sendResponse (result); }, function(error) { @@ -102,22 +103,7 @@ function YOURLS(settings, options, expected) { var expMatchString = expected || '^\\s*(\\S+)\\s*$'; - var apiURLwSlash = settings.api; - // strip common postfixes from the server url - var endStripper = [ - 'yourls-api.php', - 'admin/tools.php', - 'admin/index.php', - 'admin/plugins.php', - 'admin/', - 'admin', - 'readme.html', - ]; - for (var i = 0; i < endStripper.length; i++) - if (apiURLwSlash.endsWith (endStripper[i])) - apiURLwSlash = apiURLwSlash.substr (0, apiURLwSlash.length - endStripper[i].length); - if (apiURLwSlash.substr(-1) != '/') - apiURLwSlash += '/'; + apiURLwSlash = settings.api; var apiURL = apiURLwSlash + 'yourls-api.php'; diff --git a/webextension/lib.js b/webextension/lib.js index 2245efa..40c9b17 100644 --- a/webextension/lib.js +++ b/webextension/lib.js @@ -61,6 +61,30 @@ function injectSupplemental (node, supp) { } +// returns server url including tailing slash +function sanitiseApiUrl (url) { + + // strip common postfixes from the server url + var endStripper = [ + 'yourls-api.php', + 'admin/tools.php', + 'admin/index.php', + 'admin/plugins.php', + 'admin/', + 'admin', + 'readme.html', + ]; + + for (var i = 0; i < endStripper.length; i++) + if (url.endsWith (endStripper[i])) + url = url.substr (0, url.length - endStripper[i].length); + + if (url.substr(-1) != '/') + url += '/'; + + return url; +} + var communicationErrorMsg = { text: "This seems like a serious bug!? Could you please file a bug report at https://github.com/binfalse/YOURLS-FirefoxExtension/issues/new and explain what you did? This would help improving the add-on.", diff --git a/webextension/manifest.json b/webextension/manifest.json index 5d38036..1778782 100644 --- a/webextension/manifest.json +++ b/webextension/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "YOURLS WebExtension", - "version": "2.3.3", + "version": "2.4.0", "description": "Shorten URLs with your own YOURLS instance", "homepage_url": "https://s.binfalse.de/2f", "applications": { @@ -11,7 +11,8 @@ } }, "icons": { - "48": "yourls-48.png" + "48": "yourls.svg", + "96": "yourls.svg" }, "permissions": [ "activeTab", diff --git a/webextension/options.js b/webextension/options.js index 2f0bdbb..b3c1558 100644 --- a/webextension/options.js +++ b/webextension/options.js @@ -38,6 +38,9 @@ } document.querySelector('#maxwait').value = settings['maxwait']; + settings['api'] = sanitiseApiUrl (settings['api']); + document.querySelector('#api').value = settings['api']; + browser.runtime.sendMessage({method: "version", settings: settings}, function (response) { if (!response.error) { diff --git a/webextension/popup.css b/webextension/popup.css index b5b1835..1bcb5e0 100644 --- a/webextension/popup.css +++ b/webextension/popup.css @@ -10,7 +10,12 @@ body { } #message { color: red; + margin-top: 10px; } #headlineicon { - height: 1em; + height: .8em; +} +button { + margin-right: 5px; + margin-top: 10px; } diff --git a/webextension/popup.html b/webextension/popup.html index 6f9b6cf..63adb26 100644 --- a/webextension/popup.html +++ b/webextension/popup.html @@ -5,7 +5,7 @@
-
@@ -37,7 +37,10 @@ Short
-
+ |