Skip to content

Commit

Permalink
make up
Browse files Browse the repository at this point in the history
including:
* new icon
* links to settings and admin interface
  • Loading branch information
binfalse committed Nov 24, 2017
1 parent 2562584 commit 2c813f9
Show file tree
Hide file tree
Showing 10 changed files with 267 additions and 25 deletions.
18 changes: 2 additions & 16 deletions webextension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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';


Expand Down
24 changes: 24 additions & 0 deletions webextension/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
5 changes: 3 additions & 2 deletions webextension/manifest.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -11,7 +11,8 @@
}
},
"icons": {
"48": "yourls-48.png"
"48": "yourls.svg",
"96": "yourls.svg"
},
"permissions": [
"activeTab",
Expand Down
3 changes: 3 additions & 0 deletions webextension/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion webextension/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ body {
}
#message {
color: red;
margin-top: 10px;
}
#headlineicon {
height: 1em;
height: .8em;
}
button {
margin-right: 5px;
margin-top: 10px;
}
7 changes: 5 additions & 2 deletions webextension/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="stylesheet" href="popup.css" />
</head>
<body>
<h3><img id='headlineicon' src='yourls-48.png' alt='' title='YOURLS icon'> Shorten URL with YOURLS</h3>
<h3><img id='headlineicon' src='yourls-tight.svg' alt='' title='YOURLS icon'> Shorten URL with YOURLS</h3>
<table class="display_table">
<tr>
<td>
Expand Down Expand Up @@ -37,7 +37,10 @@ <h3><img id='headlineicon' src='yourls-48.png' alt='' title='YOURLS icon'> Short
<strong id="message_title"></strong>
<div id="message_supp"></div>
</div>
<button id="settings">Go to the configuration page</button>
<div id="links">
<button id="settings">Settings</button>
<button id="admin">YOURLS admin interface</button>
</div>
<script src="lib.js"></script>
<script src="popup.js"></script>
</body>
Expand Down
16 changes: 12 additions & 4 deletions webextension/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -110,6 +117,7 @@




document.getElementById('settings').addEventListener(
'click',
function(se) {
Expand Down
Binary file removed webextension/yourls-48.png
Binary file not shown.
108 changes: 108 additions & 0 deletions webextension/yourls-tight.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
104 changes: 104 additions & 0 deletions webextension/yourls.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2c813f9

Please sign in to comment.