Only show when the full keyword is used.
Display a preview.
This commit is contained in:
parent
bb3cdb413f
commit
f5ed1d396e
49
src/index.js
49
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,29 +16,28 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
var newstr = mkstr(length);
|
||||||
|
const result = {
|
||||||
|
icon,
|
||||||
|
term,
|
||||||
|
title: "Generate a random string",
|
||||||
|
subtitle: "Add a " + length + " character random string to the clipboard",
|
||||||
|
onSelect: () => actions.copyToClipboard(newstr),
|
||||||
|
getPreview: () => "<Preview>" + newstr + "</Preview>"
|
||||||
|
};
|
||||||
|
|
||||||
|
display(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
var newstr = mkstr(length);
|
|
||||||
const result = {
|
|
||||||
icon,
|
|
||||||
order,
|
|
||||||
term,
|
|
||||||
title: 'Add the following ' + length + ' character random string to the clipboard',
|
|
||||||
subtitle: newstr,
|
|
||||||
onSelect: () => actions.copyToClipboard(newstr)
|
|
||||||
};
|
|
||||||
|
|
||||||
display(result);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
Loading…
Reference in a new issue