Extract helpers.js (#130)
* Extract helpers.js * Rebuild background.dist.js and popup.dist.js when helpers change * Cleanup require definitions
This commit is contained in:
1
Makefile
1
Makefile
@@ -14,7 +14,6 @@ extension:
|
|||||||
$(MAKE) -C src
|
$(MAKE) -C src
|
||||||
|
|
||||||
EXTENSION_FILES := \
|
EXTENSION_FILES := \
|
||||||
src/*.css \
|
|
||||||
src/*.png \
|
src/*.png \
|
||||||
src/*.svg \
|
src/*.svg \
|
||||||
src/fonts/* \
|
src/fonts/* \
|
||||||
|
@@ -2,7 +2,7 @@ BROWSERIFY := node_modules/.bin/browserify
|
|||||||
PRETTIER := node_modules/.bin/prettier
|
PRETTIER := node_modules/.bin/prettier
|
||||||
LESSC := node_modules/.bin/lessc
|
LESSC := node_modules/.bin/lessc
|
||||||
|
|
||||||
CLEAN_FILES := js
|
CLEAN_FILES := css js
|
||||||
PRETTIER_FILES := $(wildcard *.json *.js popup/*.js options/*.js *.less popup/*.less options/*.less *.html popup/*.html options/*.html)
|
PRETTIER_FILES := $(wildcard *.json *.js popup/*.js options/*.js *.less popup/*.less options/*.less *.html popup/*.html options/*.html)
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
@@ -24,11 +24,11 @@ css/options.dist.css: $(LESSC) options/options.less
|
|||||||
[ -d css ] || mkdir -p css
|
[ -d css ] || mkdir -p css
|
||||||
$(LESSC) options/options.less css/options.dist.css
|
$(LESSC) options/options.less css/options.dist.css
|
||||||
|
|
||||||
js/background.dist.js: $(BROWSERIFY) background.js
|
js/background.dist.js: $(BROWSERIFY) background.js helpers.js
|
||||||
[ -d js ] || mkdir -p js
|
[ -d js ] || mkdir -p js
|
||||||
$(BROWSERIFY) -o js/background.dist.js background.js
|
$(BROWSERIFY) -o js/background.dist.js background.js
|
||||||
|
|
||||||
js/popup.dist.js: $(BROWSERIFY) popup/*.js
|
js/popup.dist.js: $(BROWSERIFY) popup/*.js helpers.js
|
||||||
[ -d js ] || mkdir -p js
|
[ -d js ] || mkdir -p js
|
||||||
$(BROWSERIFY) -o js/popup.dist.js popup/popup.js
|
$(BROWSERIFY) -o js/popup.dist.js popup/popup.js
|
||||||
|
|
||||||
|
@@ -2,9 +2,9 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
require("chrome-extension-async");
|
require("chrome-extension-async");
|
||||||
var TldJS = require("tldjs");
|
const sha1 = require("sha1");
|
||||||
var sha1 = require("sha1");
|
const idb = require("idb");
|
||||||
var idb = require("idb");
|
const helpers = require("./helpers");
|
||||||
|
|
||||||
// native application id
|
// native application id
|
||||||
var appID = "com.github.browserpass.native";
|
var appID = "com.github.browserpass.native";
|
||||||
@@ -61,35 +61,6 @@ chrome.runtime.onInstalled.addListener(onExtensionInstalled);
|
|||||||
|
|
||||||
//----------------------------------- Function definitions ----------------------------------//
|
//----------------------------------- Function definitions ----------------------------------//
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the deepest available domain component of a path
|
|
||||||
*
|
|
||||||
* @since 3.0.0
|
|
||||||
*
|
|
||||||
* @param string path Path to parse
|
|
||||||
* @param string currentHost Current hostname for the active tab
|
|
||||||
* @return string|null Extracted domain
|
|
||||||
*/
|
|
||||||
function pathToDomain(path, currentHost) {
|
|
||||||
var parts = path.split(/\//).reverse();
|
|
||||||
for (var key in parts) {
|
|
||||||
if (parts[key].indexOf("@") >= 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
var t = TldJS.parse(parts[key]);
|
|
||||||
if (
|
|
||||||
t.isValid &&
|
|
||||||
((t.tldExists && t.domain !== null) ||
|
|
||||||
t.hostname === currentHost ||
|
|
||||||
currentHost.endsWith(`.${t.hostname}`))
|
|
||||||
) {
|
|
||||||
return t.hostname;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set badge text with the number of matching password entries
|
* Set badge text with the number of matching password entries
|
||||||
*
|
*
|
||||||
@@ -119,7 +90,7 @@ async function updateMatchingPasswordsCount(tabId) {
|
|||||||
for (var storeId in response.data.files) {
|
for (var storeId in response.data.files) {
|
||||||
for (var key in response.data.files[storeId]) {
|
for (var key in response.data.files[storeId]) {
|
||||||
const login = response.data.files[storeId][key].replace(/\.gpg$/i, "");
|
const login = response.data.files[storeId][key].replace(/\.gpg$/i, "");
|
||||||
const domain = pathToDomain(storeId + "/" + login, currentDomain);
|
const domain = helpers.pathToDomain(storeId + "/" + login, currentDomain);
|
||||||
const inCurrentDomain =
|
const inCurrentDomain =
|
||||||
currentDomain === domain || currentDomain.endsWith("." + domain);
|
currentDomain === domain || currentDomain.endsWith("." + domain);
|
||||||
const recent = settings.recent[sha1(currentDomain + sha1(storeId + sha1(login)))];
|
const recent = settings.recent[sha1(currentDomain + sha1(storeId + sha1(login)))];
|
||||||
|
39
src/helpers.js
Normal file
39
src/helpers.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
//------------------------------------- Initialisation --------------------------------------//
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const TldJS = require("tldjs");
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
pathToDomain
|
||||||
|
};
|
||||||
|
|
||||||
|
//----------------------------------- Function definitions ----------------------------------//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the deepest available domain component of a path
|
||||||
|
*
|
||||||
|
* @since 3.0.0
|
||||||
|
*
|
||||||
|
* @param string path Path to parse
|
||||||
|
* @param string currentHost Current hostname for the active tab
|
||||||
|
* @return string|null Extracted domain
|
||||||
|
*/
|
||||||
|
function pathToDomain(path, currentHost) {
|
||||||
|
var parts = path.split(/\//).reverse();
|
||||||
|
for (var key in parts) {
|
||||||
|
if (parts[key].indexOf("@") >= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var t = TldJS.parse(parts[key]);
|
||||||
|
if (
|
||||||
|
t.isValid &&
|
||||||
|
((t.tldExists && t.domain !== null) ||
|
||||||
|
t.hostname === currentHost ||
|
||||||
|
currentHost.endsWith(`.${t.hostname}`))
|
||||||
|
) {
|
||||||
|
return t.hostname;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
@@ -1,6 +1,6 @@
|
|||||||
module.exports = Interface;
|
module.exports = Interface;
|
||||||
|
|
||||||
var m = require("mithril");
|
const m = require("mithril");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Options main interface
|
* Options main interface
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
require("chrome-extension-async");
|
require("chrome-extension-async");
|
||||||
var Interface = require("./interface");
|
const Interface = require("./interface");
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
module.exports = Interface;
|
module.exports = Interface;
|
||||||
|
|
||||||
var m = require("mithril");
|
const m = require("mithril");
|
||||||
var FuzzySort = require("fuzzysort");
|
const FuzzySort = require("fuzzysort");
|
||||||
var Moment = require("moment");
|
const Moment = require("moment");
|
||||||
var SearchInterface = require("./searchinterface");
|
const SearchInterface = require("./searchinterface");
|
||||||
|
|
||||||
const LATEST_NATIVE_APP_VERSION = 3000003;
|
const LATEST_NATIVE_APP_VERSION = 3000003;
|
||||||
|
|
||||||
|
@@ -2,9 +2,9 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
require("chrome-extension-async");
|
require("chrome-extension-async");
|
||||||
var TldJS = require("tldjs");
|
const sha1 = require("sha1");
|
||||||
var sha1 = require("sha1");
|
const Interface = require("./interface");
|
||||||
var Interface = require("./interface");
|
const helpers = require("../helpers");
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|
||||||
@@ -29,35 +29,6 @@ function handleError(error, type = "error") {
|
|||||||
document.body.appendChild(errorNode);
|
document.body.appendChild(errorNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the deepest available domain component of a path
|
|
||||||
*
|
|
||||||
* @since 3.0.0
|
|
||||||
*
|
|
||||||
* @param string path Path to parse
|
|
||||||
* @param string currentHost Current hostname for the active tab
|
|
||||||
* @return string|null Extracted domain
|
|
||||||
*/
|
|
||||||
function pathToDomain(path, currentHost) {
|
|
||||||
var parts = path.split(/\//).reverse();
|
|
||||||
for (var key in parts) {
|
|
||||||
if (parts[key].indexOf("@") >= 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
var t = TldJS.parse(parts[key]);
|
|
||||||
if (
|
|
||||||
t.isValid &&
|
|
||||||
((t.tldExists && t.domain !== null) ||
|
|
||||||
t.hostname === currentHost ||
|
|
||||||
currentHost.endsWith(`.${t.hostname}`))
|
|
||||||
) {
|
|
||||||
return t.hostname;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the main popup logic
|
* Run the main popup logic
|
||||||
*
|
*
|
||||||
@@ -98,7 +69,7 @@ async function run() {
|
|||||||
login: response.files[storeId][key].replace(/\.gpg$/i, ""),
|
login: response.files[storeId][key].replace(/\.gpg$/i, ""),
|
||||||
allowFill: true
|
allowFill: true
|
||||||
};
|
};
|
||||||
login.domain = pathToDomain(storeId + "/" + login.login, settings.host);
|
login.domain = helpers.pathToDomain(storeId + "/" + login.login, settings.host);
|
||||||
login.inCurrentDomain =
|
login.inCurrentDomain =
|
||||||
settings.host == login.domain || settings.host.endsWith("." + login.domain);
|
settings.host == login.domain || settings.host.endsWith("." + login.domain);
|
||||||
login.recent =
|
login.recent =
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
module.exports = SearchInterface;
|
module.exports = SearchInterface;
|
||||||
|
|
||||||
var m = require("mithril");
|
const m = require("mithril");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search interface
|
* Search interface
|
||||||
|
Reference in New Issue
Block a user