Skip to content

Commit

Permalink
Add option to disable dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
ochorocho committed Jan 27, 2020
1 parent adc1564 commit 8d4c2f3
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 61 deletions.
6 changes: 6 additions & 0 deletions addon/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
</label>
</section>

<section class="clear-options">
<label class="title">Disable Dropdown
<input type="checkbox" name="dropdown" id="dropdown"><br>
</label>
</section>

<section class="clear-options">
<input class="save" type="button" value="Save preferences" id="save-button"/>
</section>
Expand Down
16 changes: 13 additions & 3 deletions javascript/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,18 @@ function storeSettings() {
return password.value;
}

function getDropdown() {
const dropdown = document.querySelector("#dropdown");
return dropdown.checked;
}

const url = getUrl();
const token = getToken();
const password = getPassword();
const dropdown = getDropdown();

if (isURL(url) && token !== '' && token !== '') {
checkApi(url, token, password);
checkApi(url, token, password, dropdown);
} else {
message('Oops, could not save preferences', 'error');
}
Expand All @@ -66,13 +72,16 @@ function updateUI(restoredSettings) {

const password = document.querySelector('#password');
password.value = restoredSettings.password || '';

const dropdown = document.querySelector('#dropdown');
dropdown.checked = restoredSettings.dropdown === true ? true : '';
}

function onError(e) {
console.error(e);
}

function checkApi(url, token, password) {
function checkApi(url, token, password, dropdown) {
return fetch(url + '/api.php', {
method: 'POST',
headers: {
Expand All @@ -93,7 +102,8 @@ function checkApi(url, token, password) {
browser.storage.local.set({
url,
token,
password
password,
dropdown
});

message("Preferences saved.\n SysPass connection established", 'success');
Expand Down
55 changes: 31 additions & 24 deletions javascript/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ const currentTab = browser.tabs.query({currentWindow: true, active: true})
* Get addon settings
*/
gettingStoredSettings.then(function (data) {
let settingsSearch = Object.assign({ "method": 'account/search' }, data);
settings = data;
let settingsSearch = Object.assign({"method": 'account/search'}, data);
settings = data;

currentTab.then((tabs) => {
currentTab.then((tabs) => {
let url = new URL(tabs[0].url);
chrome.runtime.sendMessage({contentScriptQuery: "accountSearch", text: url.hostname, settings: settingsSearch}, data => createList(data));
});
});

chrome.runtime.sendMessage({
contentScriptQuery: "accountSearch",
text: url.hostname,
settings: settingsSearch
}, data => createList(data));
});
});


/**
Expand All @@ -26,24 +30,27 @@ gettingStoredSettings.then(function (data) {
* @returns {[]}
*/
function createList(data) {
let popUpList = document.querySelector("#popup-list");
popUpList.innerHTML = '';

data.result.result.forEach(function (item) {
let link = document.createElement('div');
link.setAttribute('data-login', item.login);
link.innerText = item.name;
link.className = "popup-list__item";
link.addEventListener('click', function (e) {
currentTab.then((tabs) => {
browser.tabs.sendMessage(tabs[0].id, {
command: "fillOutForm",
login: item.login,
id: item.id,
let popUpList = document.querySelector("#popup-list");
popUpList.innerHTML = '';

data.result.result.forEach(function (item) {
let link = document.createElement('div');
let login = item.login === '' ? '' : ` ( ${item.login} )`;

link.setAttribute('data-login', item.login);
link.innerText = item.name + login;
link.className = "popup-list__item";
link.addEventListener('click', function (e) {
currentTab.then((tabs) => {
browser.tabs.sendMessage(tabs[0].id, {
command: "fillOutForm",
login: item.login,
id: item.id,
});
});
});
});
})

popUpList.appendChild(link);
});
popUpList.appendChild(link);
});
}

51 changes: 25 additions & 26 deletions javascript/syspass.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,26 @@ let settings, usernameField = '', passwordField = '';
* Get addon settings
*/
gettingStoredSettings.then(function (data) {
let settingsSearch = Object.assign({ "method": 'account/search' }, data);
let settingsSearch = Object.assign({"method": 'account/search'}, data);
settings = data;
chrome.runtime.sendMessage({contentScriptQuery: "accountSearch", text: window.location.host, settings: settingsSearch}, data => selectLogin(data));
chrome.runtime.sendMessage({
contentScriptQuery: "accountSearch",
text: window.location.host,
settings: settingsSearch
}, data => selectLogin(data));
});

browser.runtime.onMessage.addListener(request => {
if(request.command === 'fillOutForm') {
let form = passwordField.closest('form');
let password = document.querySelector('input[type=password]');
let username = form.querySelectorAll('input[type="text"]')[0];
username.value = request.login;
if (request.command === 'fillOutForm') {
usernameField.value = `${request.login}`;

spinner();
let settingsPassword = Object.assign({ "method": 'account/viewPass', id: request.id }, settings);
let settingsPassword = Object.assign({"method": 'account/viewPass', id: request.id}, settings);
chrome.runtime.sendMessage({contentScriptQuery: "getPassword", settings: settingsPassword}, data => {
password.value = data.result.result.password;
passwordField.value = data.result.result.password;
document.getElementById('syspass-spinner').remove();
});



}
return Promise.resolve({response: "Login set ..."});
});

/**
Expand All @@ -53,7 +50,7 @@ function autocompleteField(field, data) {
onSelect: function (item) {
usernameField.value = item.value;
spinner();
let settingsPassword = Object.assign({ "method": 'account/viewPass', id: item.id }, settings);
let settingsPassword = Object.assign({"method": 'account/viewPass', id: item.id}, settings);
chrome.runtime.sendMessage({contentScriptQuery: "getPassword", settings: settingsPassword}, data => {
passwordField.value = data.result.result.password
document.getElementById('syspass-spinner').remove();
Expand All @@ -76,14 +73,16 @@ function selectLogin(data) {
passwordField = document.querySelector('input[type=password]');
usernameField = passwordField.closest('form').querySelectorAll('input[type="text"]')[0];

if (usernameField !== undefined) {
usernameField.setAttribute('autocomplete', 'off');
autocompleteField(usernameField, list);
}
if (settings.dropdown === false) {
if (usernameField !== undefined) {
usernameField.setAttribute('autocomplete', 'off');
autocompleteField(usernameField, list);
}

if (passwordField !== undefined) {
passwordField.setAttribute('autocomplete', 'off');
autocompleteField(passwordField, list);
if (passwordField !== undefined) {
passwordField.setAttribute('autocomplete', 'off');
autocompleteField(passwordField, list);
}
}
}, 100);
}
Expand All @@ -110,14 +109,14 @@ function processList(data) {
function spinner() {
let spinnerHtml = document.createElement('div');
let pw = passwordField.getBoundingClientRect();
let top = pw.height - ( pw.height * 0.9 );
let top = pw.height - (pw.height * 0.9);

spinnerHtml.innerHTML = '<div id="syspass-spinner" class="syspass-spinner"></div>';
spinnerHtml.style.cssText = "position: absolute; z-index: 1000";
spinnerHtml.style.top = ( pw.top + top / 2 ) + "px";
spinnerHtml.style.left = ( pw.left - pw.height + pw.width ) + "px";
spinnerHtml.style.height = ( pw.height * 0.9 ) + "px";
spinnerHtml.style.width = ( pw.height * 0.9 ) + "px";
spinnerHtml.style.top = (pw.top + top / 2) + "px";
spinnerHtml.style.left = (pw.left - pw.height + pw.width) + "px";
spinnerHtml.style.height = (pw.height * 0.9) + "px";
spinnerHtml.style.width = (pw.height * 0.9) + "px";

document.body.appendChild(spinnerHtml);
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"extract-loader": "^3.1.0",
"file-loader": "^5.0.2",
"node-sass": "^4.13.1",
"postcss-inline-svg": "^4.1.0",
"postcss-loader": "^3.0.0",
"postcss-svgo": "^4.0.2",
"sass-loader": "^8.0.2",
"web-ext": "^4.0.0",
"webextension-polyfill": "^0.6.0",
Expand Down
14 changes: 14 additions & 0 deletions scss/popup.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ body {



.link__login {
background-color: #ff0000;
display: block !important;
width: 20px !important;
height: 20px !important;
}

.link__password {
background: #9b231d;
display: block !important;
width: 20px !important;
height: 20px !important;
}



%box {
Expand Down
8 changes: 4 additions & 4 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ module.exports = {
outputPath: './'
}
},
{ loader: 'extract-loader' },
{ loader: 'css-loader' },
{ loader: 'postcss-loader' },
{ loader: 'sass-loader' }
{loader: 'extract-loader'},
{loader: 'css-loader'},
{loader: 'postcss-loader'},
{loader: 'sass-loader'}
]
}
]
Expand Down
19 changes: 15 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1697,7 +1697,7 @@ css-select-base-adapter@^0.1.1:
resolved "https://registry.yarnpkg.com/css-select-base-adapter/-/css-select-base-adapter-0.1.1.tgz#3b2ff4972cc362ab88561507a95408a1432135d7"
integrity sha512-jQVeeRG70QI08vSTwf1jHxp74JoZsr2XSgETae8/xC8ovSnL2WF87GTLO86Sbwdt2lK4Umg4HnnwMO4YF3Ce7w==

css-select@^2.0.0:
css-select@^2.0.0, css-select@^2.0.2:
version "2.1.0"
resolved "https://registry.yarnpkg.com/css-select/-/css-select-2.1.0.tgz#6a34653356635934a81baca68d0255432105dbef"
integrity sha512-Dqk7LQKpwLoH3VovzZnkzegqNSuAziQyNZUcrdDM401iY+R5NkGBXGmtO05/yaXQziALuPogeG0b7UAgjnTJTQ==
Expand Down Expand Up @@ -2052,7 +2052,7 @@ dom-serializer@0:
domelementtype "^2.0.1"
entities "^2.0.0"

dom-serializer@~0.1.1:
dom-serializer@^0.1.1, dom-serializer@~0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-0.1.1.tgz#1ec4059e284babed36eec2941d4a970a189ce7c0"
integrity sha512-l0IU0pPzLWSHBcieZbpOKgkIn3ts3vAh7ZuFyXNwJxJXk/c4Gwj9xaTJwIDVQCXawWD0qb3IzMGH5rglQaO0XA==
Expand Down Expand Up @@ -3385,7 +3385,7 @@ html-comment-regex@^1.1.0:
resolved "https://registry.yarnpkg.com/html-comment-regex/-/html-comment-regex-1.1.2.tgz#97d4688aeb5c81886a364faa0cad1dda14d433a7"
integrity sha512-P+M65QY2JQ5Y0G9KKdlDpo0zK+/OHptU5AaBwUfAIDJZk1MYf32Frm84EcOytfJE0t5JvkAnKlmjsXDnWzCJmQ==

htmlparser2@^3.9.1:
htmlparser2@^3.10.1, htmlparser2@^3.9.1:
version "3.10.1"
resolved "https://registry.yarnpkg.com/htmlparser2/-/htmlparser2-3.10.1.tgz#bd679dc3f59897b6a34bb10749c855bb53a9392f"
integrity sha512-IgieNijUMbkDovyoKObU1DUhm1iwNYE/fuifEoEHfd1oZKZDaONBSkal7Y01shxsM49R4XaMdGez3WnF9UfiCQ==
Expand Down Expand Up @@ -5363,6 +5363,17 @@ postcss-discard-overridden@^4.0.1:
dependencies:
postcss "^7.0.0"

postcss-inline-svg@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/postcss-inline-svg/-/postcss-inline-svg-4.1.0.tgz#54e9199632242cc181af5b55f0f0691ad1020f95"
integrity sha512-0pYBJyoQ9/sJViYRc1cNOOTM7DYh0/rmASB0TBeRmWkG8YFK2tmgdkfjHkbRma1iFtBFKFHZFsHwRTDZTMKzSQ==
dependencies:
css-select "^2.0.2"
dom-serializer "^0.1.1"
htmlparser2 "^3.10.1"
postcss "^7.0.17"
postcss-value-parser "^4.0.0"

postcss-load-config@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/postcss-load-config/-/postcss-load-config-2.1.0.tgz#c84d692b7bb7b41ddced94ee62e8ab31b417b003"
Expand Down Expand Up @@ -5651,7 +5662,7 @@ [email protected]:
source-map "^0.6.1"
supports-color "^6.1.0"

postcss@^7.0.0, postcss@^7.0.1, postcss@^7.0.14, postcss@^7.0.16, postcss@^7.0.23, postcss@^7.0.26, postcss@^7.0.5, postcss@^7.0.6:
postcss@^7.0.0, postcss@^7.0.1, postcss@^7.0.14, postcss@^7.0.16, postcss@^7.0.17, postcss@^7.0.23, postcss@^7.0.26, postcss@^7.0.5, postcss@^7.0.6:
version "7.0.26"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.26.tgz#5ed615cfcab35ba9bbb82414a4fa88ea10429587"
integrity sha512-IY4oRjpXWYshuTDFxMVkJDtWIk2LhsTlu8bZnbEJA4+bYT16Lvpo8Qv6EvDumhYRgzjZl489pmsY3qVgJQ08nA==
Expand Down

0 comments on commit 8d4c2f3

Please sign in to comment.