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 @@ -

Shorten URL with YOURLS

+

Shorten URL with YOURLS

@@ -37,7 +37,10 @@

Short
- + diff --git a/webextension/popup.js b/webextension/popup.js index 03aa3e8..42fbded 100644 --- a/webextension/popup.js +++ b/webextension/popup.js @@ -58,12 +58,19 @@ var _haveTab = function(tabs) { updateSource(tabs[0].url); - browser.runtime.sendMessage({method: "getSelection"}).then (function (response) - { - document.getElementById('keyword').value = response.selection; - }, function (error) {updateError ("Communication error within the extension!", communicationErrorMsg);}); + + document.getElementById('admin').addEventListener( + 'click', + function(se) { + window.open(settings.api + "admin/"); + } + ); if (settings.keyword) { + browser.runtime.sendMessage({method: "getSelection"}).then (function (response) { + document.getElementById('keyword').value = response.selection; + }, function (error) {updateError ("Communication error within the extension!", communicationErrorMsg);}); + updateResult("", "Waiting for keyword..."); document.getElementById('keyword_submit').addEventListener( 'click', @@ -110,6 +117,7 @@ + document.getElementById('settings').addEventListener( 'click', function(se) { diff --git a/webextension/yourls-48.png b/webextension/yourls-48.png deleted file mode 100644 index cd0adcd..0000000 Binary files a/webextension/yourls-48.png and /dev/null differ diff --git a/webextension/yourls-tight.svg b/webextension/yourls-tight.svg new file mode 100644 index 0000000..af30f71 --- /dev/null +++ b/webextension/yourls-tight.svg @@ -0,0 +1,108 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + diff --git a/webextension/yourls.svg b/webextension/yourls.svg new file mode 100644 index 0000000..b902a71 --- /dev/null +++ b/webextension/yourls.svg @@ -0,0 +1,104 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + +