Only show when the full keyword is used.
Display a preview.
This commit is contained in:
parent
bb3cdb413f
commit
f5ed1d396e
27
src/index.js
27
src/index.js
|
@ -1,14 +1,14 @@
|
||||||
const React = require('react');
|
const React = require("react");
|
||||||
|
|
||||||
const icon = require('./icon.png');
|
const icon = require("./icon.png");
|
||||||
|
|
||||||
const KEYWORD = 'genpw';
|
const KEYWORD = "genpw";
|
||||||
const STRLEN = 16;
|
const STRLEN = 16;
|
||||||
|
|
||||||
const mkstr = length => {
|
const mkstr = length => {
|
||||||
var result = '';
|
var result = "";
|
||||||
var characters =
|
var characters =
|
||||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@/?#$%&*()[]{},.!~';
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@/?#$%&*()[]{},.!~";
|
||||||
var charactersLength = characters.length;
|
var charactersLength = characters.length;
|
||||||
for (var i = 0; i < length; i++) {
|
for (var i = 0; i < length; i++) {
|
||||||
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||||
|
@ -16,13 +16,11 @@ const mkstr = length => {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const order = 10;
|
|
||||||
|
|
||||||
const generate = ({ term, actions, display }) => {
|
const generate = ({ term, actions, display }) => {
|
||||||
let regex = new RegExp('^' + KEYWORD + '\\s+([0-9]+)', 'i');
|
if (term.startsWith(KEYWORD)) {
|
||||||
let match = term.match(regex);
|
let match = term.match(/^.+\s+([0-9]+)/i);
|
||||||
|
|
||||||
if (match) {
|
if (match && match[1]) {
|
||||||
var length = match[1];
|
var length = match[1];
|
||||||
} else {
|
} else {
|
||||||
var length = STRLEN;
|
var length = STRLEN;
|
||||||
|
@ -31,14 +29,15 @@ const generate = ({ term, actions, display }) => {
|
||||||
var newstr = mkstr(length);
|
var newstr = mkstr(length);
|
||||||
const result = {
|
const result = {
|
||||||
icon,
|
icon,
|
||||||
order,
|
|
||||||
term,
|
term,
|
||||||
title: 'Add the following ' + length + ' character random string to the clipboard',
|
title: "Generate a random string",
|
||||||
subtitle: newstr,
|
subtitle: "Add a " + length + " character random string to the clipboard",
|
||||||
onSelect: () => actions.copyToClipboard(newstr)
|
onSelect: () => actions.copyToClipboard(newstr),
|
||||||
|
getPreview: () => "<Preview>" + newstr + "</Preview>"
|
||||||
};
|
};
|
||||||
|
|
||||||
display(result);
|
display(result);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
Loading…
Reference in a new issue