[refactor] add random string adjectives count

This commit is contained in:
zombieFox 2020-04-06 15:37:42 +01:00
parent 33990b8aeb
commit 9aa6887e64
7 changed files with 70 additions and 25 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "nightTab",
"version": "5.5.4",
"version": "5.6.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "nightTab",
"version": "5.5.4",
"version": "5.6.0",
"description": "A neutral new tab page accented with a chosen colour. Customise the layout, style, background and bookmarks in nightTab.",
"main": "index.js",
"scripts": {

View File

@ -22,13 +22,13 @@ var helper = (function() {
var randomString = function(override) {
var options = {
mix: null,
letter: null
letter: null,
adjectivesCount: null
};
if (override) {
options = applyOptions(options, override);
};
var alphabet = "abcdefghijklmnopqrstuvwxyz";
var alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
var adjectives = {
a: ["Aback", "Abaft", "Abandoned", "Abashed", "Aberrant", "Abhorrent", "Abiding", "Abject", "Ablaze", "Able", "Abnormal", "Aboriginal", "Abortive", "Abounding", "Abrasive", "Abrupt", "Absent", "Absorbed", "Absorbing", "Abstracted", "Absurd", "Abundant", "Abusive", "Acceptable", "Accessible", "Accidental", "Accurate", "Acid", "Acidic", "Acoustic", "Acrid", "Adamant", "Adaptable", "Addicted", "Adhesive", "Adjoining", "Adorable", "Adventurous", "Afraid", "Aggressive", "Agonizing", "Agreeable", "Ahead", "Ajar", "Alert", "Alike", "Alive", "Alleged", "Alluring", "Aloof", "Amazing", "Ambiguous", "Ambitious", "Amuck", "Amused", "Amusing", "Ancient", "Angry", "Animated", "Annoyed", "Annoying", "Anxious", "Apathetic", "Aquatic", "Aromatic", "Arrogant", "Ashamed", "Aspiring", "Assorted", "Astonishing", "Attractive", "Auspicious", "Automatic", "Available", "Average", "Aware", "Awesome", "Axiomatic"],
b: ["Bad", "Barbarous", "Bashful", "Bawdy", "Beautiful", "Befitting", "Belligerent", "Beneficial", "Bent", "Berserk", "Bewildered", "Big", "Billowy", "Bitter", "Bizarre", "Black", "Bloody", "Blue", "Blushing", "Boiling", "Boorish", "Bored", "Boring", "Bouncy", "Boundless", "Brainy", "Brash", "Brave", "Brawny", "Breakable", "Breezy", "Brief", "Bright", "Broad", "Broken", "Brown", "Bumpy", "Burly", "Bustling", "Busy"],
@ -83,26 +83,71 @@ var helper = (function() {
w: ["Wallaby", "Walrus", "Wasp", "Weasel", "Whale", "Wolf", "Wolverine", "Wombat", "Woodcock", "Woodpecker", "Worm", "Wren"],
x: ["Xaviers Greenbul", "Xeme", "Xingu Corydoras", "Xolo"],
y: ["Yabby", "Yak", "Yellowhammer", "Yellowjacket"],
z: ["Zebra", "Zebu", "Zokor", "Zorilla"],
z: ["Zebra", "Zebu", "Zokor", "Zorilla"]
};
var seed;
var mix = function() {
var adjectivesSeed = alphabet[Math.floor(Math.random() * alphabet.length)];
var animalsSeed = alphabet[Math.floor(Math.random() * alphabet.length)];
return adjectives[adjectivesSeed][Math.floor(Math.random() * adjectives[adjectivesSeed].length)] + " " + animals[animalsSeed][Math.floor(Math.random() * animals[animalsSeed].length)];
var action = {
alliteration: {
short: function() {
var randomAdjective = adjectives[options.letter.toLowerCase()][Math.floor(Math.random() * adjectives[options.letter.toLowerCase()].length)];
var randomAnimal = animals[options.letter.toLowerCase()][Math.floor(Math.random() * animals[options.letter.toLowerCase()].length)];
return randomAdjective + " " + randomAnimal;
},
long: function() {
var randomAdjective = "";
for (var i = 1; i <= options.adjectivesCount; i++) {
if (adjectives[options.letter.toLowerCase()].length > 0) {
if (randomAdjective.length > 0) {
randomAdjective = randomAdjective + " ";
};
randomAdjective = randomAdjective + adjectives[options.letter.toLowerCase()].splice(Math.floor(Math.random() * adjectives[options.letter.toLowerCase()].length), 1);
};
};
var randomAnimal = animals[options.letter.toLowerCase()][Math.floor(Math.random() * animals[options.letter.toLowerCase()].length)];
return randomAdjective + " " + randomAnimal;
}
},
mix: {
short: function() {
var adjectivesSeed = alphabet[Math.floor(Math.random() * (alphabet.length - 1))];
var animalsSeed = alphabet[Math.floor(Math.random() * (alphabet.length - 1))];
var randomAdjective = adjectives[adjectivesSeed][Math.floor(Math.random() * adjectives[adjectivesSeed].length)];
var randomAnimal = animals[animalsSeed][Math.floor(Math.random() * animals[animalsSeed].length)];
return randomAdjective + " " + randomAnimal;
},
long: function() {
var randomAdjective = "";
for (var i = 1; i <= options.adjectivesCount; i++) {
var adjectiveLetter = alphabet[Math.floor(Math.random() * (alphabet.length - 1))];
if (adjectiveLetter in adjectives && adjectives[adjectiveLetter].length > 0) {
if (randomAdjective.length > 0) {
randomAdjective = randomAdjective + " ";
};
randomAdjective = randomAdjective + adjectives[adjectiveLetter].splice(Math.floor(Math.random() * adjectives[adjectiveLetter].length), 1);
if (adjectives[adjectiveLetter].length == 0) {
delete adjectives[adjectiveLetter];
};
};
};
var randomAnimalArray = animals[alphabet[Math.floor(Math.random() * (alphabet.length - 1))]]
var randomAnimal = randomAnimalArray[Math.floor(Math.random() * (randomAnimalArray.length - 1))];
return randomAdjective + " " + randomAnimal;
}
}
};
var alliteration = function() {
if (options.letter != null) {
return adjectives[options.letter.toLowerCase()][Math.floor(Math.random() * adjectives[options.letter.toLowerCase()].length)] + " " + animals[options.letter.toLowerCase()][Math.floor(Math.random() * animals[options.letter.toLowerCase()].length)];
if (options.letter != null && alphabet.includes(options.letter.toLowerCase())) {
if (options.adjectivesCount != null && options.adjectivesCount > 0) {
return action.alliteration.long();
} else {
var seed = alphabet[Math.floor(Math.random() * alphabet.length)];
return adjectives[seed][Math.floor(Math.random() * adjectives[seed].length)] + " " + animals[seed][Math.floor(Math.random() * animals[seed].length)];
return action.alliteration.short();
};
};
if (options.mix) {
return mix();
} else {
return alliteration();
if (options.adjectivesCount != null && options.adjectivesCount > 0) {
return action.mix.long();
} else {
return action.mix.short();
};
};
};

View File

@ -647,7 +647,7 @@ var link = (function() {
}, false);
groupFormRandomNameButton.addEventListener("click", function(event) {
var randomName = helper.randomString({
mix: true
adjectivesCount: 2
});
stagedGroup.group.name.text = randomName;
groupFormInputName.value = randomName;
@ -1187,7 +1187,7 @@ var link = (function() {
}, false);
groupNewRandomNameButton.addEventListener("click", function(event) {
var randomName = helper.randomString({
mix: true
adjectivesCount: 2
});
stagedLink.position.group.name.text = randomName;
groupNewInput.value = randomName;

View File

@ -2079,7 +2079,7 @@ var theme = (function() {
randomButton.addEventListener("click", function(event) {
var randomName = helper.randomString({
mix: true
adjectivesCount: 2
});
stagedThemeCustom.theme.name = randomName;
nameInput.value = randomName;

View File

@ -1,6 +1,6 @@
var version = (function() {
var current = "5.5.4";
var current = "5.6.0";
var name = "Zonked Tarsier";

View File

@ -2,7 +2,7 @@
"name": "nightTab",
"short_name": "nightTab",
"description": "A neutral new tab page accented with a chosen colour. Customise the layout, style, background and bookmarks in nightTab.",
"version": "5.5.4",
"version": "5.6.0",
"manifest_version": 2,
"chrome_url_overrides": {
"newtab": "index.html"