Commit 1fbe055e authored by Irina's avatar Irina

V2.3

parents
<!-- The extension generates the string of given amount of symbols or calculates the length of a given string
Author: Irina Ivanova, iriiiina@gmail.com
1.05.2013
Tartu, Estonia -->
<!doctype html>
<html>
<head>
<title>String Generator</title>
<link rel = 'stylesheet' type = 'text/css' href = 'style.css' />
<script src = 'js/generateString.js' type = 'text/javascript' charset="utf-8"></script>
<script src = 'js/calculateLength.js' type = 'text/javascript' charset="utf-8"></script>
</head>
<body>
<div id = 'error'><br /><br /></div>
<div id = 'generateString'>
Number of characters: <input type = 'text' name = 'length' id = 'inputLength' maxlength = '10' tabindex = '1' autofocus/><br />
<center>
<table>
<tr>
<td><input type = 'radio' name = 'inputType' id = 'inputTypeNumber' value = 'number' />Number <sup>[LeftArr]</sup>
<input type = 'radio' name = 'inputType' id = 'inputTypeText' value = 'text' checked/>Text <sup>[RightArr]</sup></td>
</tr>
<tr>
<td><input type = 'checkbox' name = 'inputSpace' id = 'inputSpace' value = 'space' />every 10th character is a space <sup>[UpArr]</sup></td>
</tr>
<tr>
<td><input type = 'checkbox' name = 'inputUmlaut' id = 'inputUmlaut' value = 'umlaut' />insert umlauts <sup>[DownArr]</sup></td>
</tr>
</table>
</center>
<br />
Copy the generated string:<br />
<textarea rows = '4' cols = '30' id = 'generatedString' disabled></textarea>
</div>
<br />
<center>&mdash; OR &mdash;</center><br />
<div id = 'calculateString'>
Or insert the string to calculate the length:</br >
<textarea rows = '4' cols = '30' id = 'inputString' tabindex = '2'></textarea>
</div>
<div id = 'calculatedLength'><br /></div>
<div id = 'info'><br />iriiiina@gmail.com</div>
</body>
</html>
\ No newline at end of file
function listenForInputString() {
var inputString = document.getElementById('inputString');
if(inputString.addEventListener){
inputString.addEventListener('keydown', calculateLength, false);
} else if(inputString.attachEvent){
inputString.attachEvent('keydown', calculateLength);
}
}
// Handler
if(window.addEventListener){
window.addEventListener('load', listenForInputString, false);
} else if(window.attachEvent){
window.attachEvent('onload', listenForInputString);
} else{
document.addEventListener('load', listenForInputString, false);
}
// Constant variables
var inputString;
function setVariablesForCalculateLength() {
inputString = document.getElementById('inputString').value;
}
function calculateLength(e) {
if (e.keyCode == 13) {
setVariablesForCalculateLength();
var calculatedLength = inputString.length;
returnCalculatedLength(calculatedLength);
}
}
function returnCalculatedLength(calculatedLength) {
var divCalculatedLength = document.getElementById('calculatedLength');
divCalculatedLength.innerHTML = 'Length: ' + calculatedLength + '<br />';
}
function setFocusOnInputString() {
var inputString = document.getElementById('inputString');
inputString.focus();
}
\ No newline at end of file
// Handler
if (window.addEventListener) {
window.addEventListener('load', listenInputLength, false);
window.addEventListener('load', listenRadioButtons, false);
window.addEventListener('load', listenSpaceCheckbox, false);
window.addEventListener('load', listenUmlautCheckbox, false);
} else if (window.attachEvent) {
window.attachEvent('onload', listenInputLength);
window.attachEvent('onload', listenRadioButtons);
window.attachEvent('onload', listenSpaceCheckbox);
window.attachEvent('onload', listenUmlautCheckbox);
} else {
document.addEventListener('load', listenInputLength, false);
document.addEventListener('load', listenRadioButtons, false);
document.addEventListener('load', listenSpaceCheckbox, false);
document.addEventListener('load', listenUmlautCheckbox, false);
}
function listenInputLength() {
var inputLength = document.getElementById('inputLength');
if (inputLength.addEventListener) {
inputLength.addEventListener('keydown', inputLengthListener, false);
} else if (inputLength.attachEvent) {
inputLength.attachEvent('keydown', inputLengthListener);
}
}
function listenRadioButtons() {
var inputTypeNumber = document.getElementById('inputTypeNumber');
var inputTypeText = document.getElementById('inputTypeText');
if (inputTypeNumber.addEventListener) {
inputTypeNumber.addEventListener('change', setFocusAfterRadioButton, false);
inputTypeText.addEventListener('change', setFocusAfterRadioButton, false);
} else if (inputTypeNumber.attachEvent) {
inputTypeNumber.attachEvent('change', setFocusAfterRadioButton);
}
}
function listenSpaceCheckbox() {
var inputSpace = document.getElementById('inputSpace');
if (inputSpace.addEventListener) {
inputSpace.addEventListener('change', setFocusAfterSpaceCheckbox, false);
} else if (inputSpace.attachEvent) {
inputSpace.attachEvent('change', setFocusAfterSpaceCheckbox);
}
}
function listenUmlautCheckbox() {
var inputUmlaut = document.getElementById('inputUmlaut');
if (inputUmlaut.addEventListener) {
inputUmlaut.addEventListener('change', setFocusAfterUmlautCheckbox, false);
} else if (inputUmlaut.attachEvent) {
inputUmlaut.attachEvent('change', setFocusAfterUmlautCheckbox);
}
}
function setFocusAfterRadioButton(event) {
var radioButton = event.target;
if (radioButton.checked) {
if (document.getElementById('inputTypeNumber').checked) {
disableUmlautCheckbox();
} else {
enableUmlautCheckbox();
}
setFocusOnInputLength();
selectInputLength();
} else {
setFocusOnInputLength();
selectInputLength();
}
}
function setFocusAfterSpaceCheckbox(event) {
var spaceCheckbox = event.target;
if (spaceCheckbox.checked) {
setFocusOnInputLength();
selectInputLength();
} else {
setFocusOnInputLength();
selectInputLength();
}
}
function setFocusAfterUmlautCheckbox(event) {
var umlautCheckbox = event.target;
if (umlautCheckbox.checked) {
setFocusOnInputLength();
selectInputLength();
} else {
setFocusOnInputLength();
selectInputLength();
}
}
function inputLengthListener(e) {
if (e.keyCode == 13) { // 13 = Enter
generateString();
} else if (e.keyCode == 39) { // 39 = right arrow = text
checkTextRadiobutton();
selectInputLength();
} else if (e.keyCode == 37) { // 37 = left arrow = number
checkNumberRadiobutton();
selectInputLength();
} else if (e.keyCode == 38) { // 38 = up arrow = space
if (document.getElementById('inputSpace').checked == true) {
uncheckSpaceCheckbox();
} else {
checkSpaceCheckbox();
}
} else if (e.keyCode == 40) { // 40 = down arrow = umlaut
if (document.getElementById('inputUmlaut').checked && document.getElementById('inputTypeText').checked) {
uncheckUmlautCheckbox();
} else if (document.getElementById('inputTypeText').checked) {
checkUmlautCheckbox();
}
}
}
function checkTextRadiobutton() {
var textRadiobutton = document.getElementById('inputTypeText');
textRadiobutton.checked = true;
setFocusOnInputLength();
enableUmlautCheckbox();
}
function checkNumberRadiobutton() {
var numberRadiobutton = document.getElementById('inputTypeNumber');
numberRadiobutton.checked = true;
setFocusOnInputLength();
disableUmlautCheckbox();
}
function checkSpaceCheckbox() {
var spaceCheckbox = document.getElementById('inputSpace');
spaceCheckbox.checked = true;
}
function uncheckSpaceCheckbox() {
var spaceCheckbox = document.getElementById('inputSpace');
spaceCheckbox.checked = false;
}
function checkUmlautCheckbox() {
var umlautCheckbox = document.getElementById('inputUmlaut');
umlautCheckbox.checked = true;
}
function uncheckUmlautCheckbox() {
var umlautCheckbox = document.getElementById('inputUmlaut');
umlautCheckbox.checked = false;
}
// Constant variables
var type;
var length;
var string;
var space;
var umlaut;
function setVariablesForStringGenerator() {
// get type
var inputType;
if (document.getElementById('inputTypeNumber').checked) {
inputType = 'number';
} else if (document.getElementById('inputTypeText').checked) {
inputType = 'text';
}
// set type
if (inputType == 'number' || inputType == 'text') {
type = inputType;
} else {
returnError('Inserted type is incorrect');
}
// get length
var inputLength = document.getElementById('inputLength').value;
// set length
if (inputLength.indexOf('.') == -1 && inputLength.indexOf(',') == -1 && inputLength > 0) {
length = inputLength;
} else {
returnError('Inserted number is incorrect');
}
// get Space
if (document.getElementById('inputSpace').checked) {
space = 'true';
} else {
space = 'false';
}
//get Umlaut
if (document.getElementById('inputUmlaut').checked) {
umlaut = 'true';
} else {
umlaut = 'false';
}
}
function generateString() {
clearGeneratedString();
clearError();
setVariablesForStringGenerator();
// Generate number string
if (type == 'number') {
if (length > 2) {
string = '1';
for (var i = 1; i < length-1; i++) {
if (i % 10 == 0) {
if (space == 'true') {
string += ' ';
} else {
string += '0';
}
} else {
string += '0';
}
}
string += '9';
} else if (length == 2) {
string = '19';
} else {
string = '1';
}
// Generate text string
} else if (type == 'text') {
if (umlaut == 'false') {
if (length > 2) {
string = 'A';
for (var i = 1; i < length-1; i++) {
if (i % 10 == 0) {
if (space == 'true') {
string += ' ';
} else {
string += 'x';
}
} else {
string += 'x';
}
}
string += 'Z';
} else if (length == 2) {
string = 'AZ';
} else {
string = 'A';
}
} else if (umlaut == 'true') {
if (length == 1) {
string = 'Ä';
} else if (length == 2) {
string = 'ÄÖ';
} else if (length == 3) {
string = 'ÄöÜ';
} else if (length == 4) {
string = 'ÄöüÕ';
} else if (length == 5) {
string = 'ÄöüõZ';
} else if (length > 5) {
string = 'Äöüõ';
for (var i = 1; i < length-4; i++) {
if (i % 10 == 0) {
if (space == 'true') {
string += ' ';
} else {
string += 'x';
}
} else {
string += 'x';
}
}
string += 'Z';
}
} else {
clearGeneratedString();
returnError('Can not generate the string');
}
}
returnGeneratedString(string);
}
function returnGeneratedString(generatedString) {
var textarea = document.getElementById('generatedString');
textarea.value = textarea.value + generatedString;
selectGeneratedString();
}
function setFocusOnInputLength() {
document.getElementById('inputLength').focus();
}
function selectGeneratedString() {
document.getElementById('generatedString').select();
}
function selectInputLength() {
document.getElementById('inputLength').select();
}
function disableUmlautCheckbox() {
document.getElementById('inputUmlaut').disabled = true;
document.getElementById('inputUmlaut').checked = false;
}
function enableUmlautCheckbox() {
document.getElementById('inputUmlaut').disabled = false;
}
function returnError(errorText) {
var divError = document.getElementById('error');
divError.innerHTML = errorText + '<br /><br />';
var inputLength = document.getElementById('inputLength');
inputLength.style.borderColor = '#FF0000';
selectInputLength();
throw '';
}
function clearGeneratedString() {
var clearTextarea = document.getElementById('generatedString');
clearTextarea.value = '';
}
function clearError() {
var clearError = document.getElementById('error');
clearError.innerHTML = '<br /><br />';
var inputLength = document.getElementById('inputLength');
inputLength.style.border = '';
}
function clearInputLength() {
var inputLength = document.getElementById('inputLength');
inputLength.value = '';
}
\ No newline at end of file
{
"name": "String Generator",
"version": "2.3",
"manifest_version": 2,
"description": "Extension generates the string of specified length or calculates the length of specified string.",
"homepage_url": "https://chrome.google.com/webstore/detail/string-generator/mklinoolelpkognneckhecljdfhehfbc",
"icons": { "16": "icons/icon16.gif",
"48": "icons/icon48.gif",
"128": "icons/icon128.gif" },
"browser_action": {
"default_icon": "icons/icon16.gif",
"default_popup": "index.html"
}
}
\ No newline at end of file
body {
min-width: 250px;
overflow-x: hidden;
background-color: #FFFFCC;
font-family: "Times New Roman",Georgia,Serif;
font-size: 11px;
color: #333333;
}
input {
font-size: 11px;
color: #000000;
}
#inputLength {
width: 80px;
}
#generateString {
margin-right: 5px;
vertical-align: middle;
}
#calculateString {
margin-right: 5px;
vertical-align: middle;
}
#calculatedLength {
margin-right: 5px;
vertical-align: middle;
font-size: 13px;
font-weight: bold;
}
#error {
font-size: 14px;
color: #CC0000;
font-weight: bold;
}
#info {
float: right;
color: gray;
font-size: 10px;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment