Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Degrees_Of_Pedity
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pedy
Degrees_Of_Pedity
Commits
22739795
Commit
22739795
authored
6 years ago
by
Pedy
Browse files
Options
Downloads
Patches
Plain Diff
Prepare the speech modifiers, todo macro
parent
651a55e5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/init/js_mod.tw
+136
-4
136 additions, 4 deletions
src/init/js_mod.tw
with
136 additions
and
4 deletions
src/init/js_mod.tw
+
136
−
4
View file @
22739795
...
...
@@ -51,6 +51,11 @@ window.jsEither = function(choices) {
return choices[index];
};
//find an occurrence within given string, supports regex
window.jsStrcount = function(str, search) {
return (str.match(new RegExp(search, "g")) || []).length;
}
//unlike the previous function, this doesn't require strict formatting, accepting a simple string-type var
//splitter can be specified, by default it's :
window.jsSplitr = function(choices, splitter) {
...
...
@@ -66,6 +71,12 @@ window.jsSplitcheck = function() {
}
return n
};
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
//capitalize first letter of a given string
window.jsCapitalize = function(lower) {
return lower.replace(/^\w/, c => c.toUpperCase());
...
...
@@ -103,6 +114,9 @@ return output
//second var is capitalization - 1 will give full caps, 2 will give lowercase, 3 will give random capitalization
//todo - gender division? I mean boys probably moan differently
window.jsMoan = function(mode, capitalization) {
/*check if there are splitters, choose one*/
mode = jsSplitr(mode)
switch(mode) {
case 'rand': case 'r':
...
...
@@ -203,10 +217,7 @@ window.jsCount = function(n) {
default: return n + "th";
}
};
//find an occurrence within given string, supports regex
window.jsStrcount = function(str, search) {
return (str.match(new RegExp(search, "g")) || []).length;
}
//puts an appropriate article to the given string
window.jsArticle = function(str) {
/* exceptions, add on demand */
...
...
@@ -823,4 +834,125 @@ while (true) {
default:
return intToString;
}
};
window.jsintToTally = function(integer) {
var numeralSB = "";
for(var i=0; i<Math.floor(integer/5); i++) {
numeralSB += "<strike>IIII</strike> ";
}
for(var i=0; i<integer%5; i++) {
numeralSB += "I";
}
return numeralSB.toString();
};
window.jsaddStutter = function(sentence, frequency) {
var splitSentence = sentence.split(" ");
var builder = "";
// 1 in "frequency" words are stutters, with a minimum of 1.
var wordsToStutter = Math.floor(splitSentence.length / frequency) + 1;
var offset = 0;
for (var i = 0; i < wordsToStutter; i++) {
offset = jsRandom(frequency);
offset = (i * frequency + offset) >= splitSentence.length ? splitSentence.length - 1 : (i * frequency + offset);
// In case of an accidental comma position? also avoid apostrophe
if (splitSentence[offset].charAt(0) != ',' && splitSentence[offset].charAt(0) != '\'')
splitSentence[offset] = splitSentence[offset].charAt(0) + "-" + splitSentence[offset];
else
if (splitSentence[offset].charAt(0) == ',')
splitSentence[offset] = "," + splitSentence[offset].charAt(1); //+ "-" + splitSentence[offset].substring(1, splitSentence[offset].length + 1)
else
splitSentence[offset] = "'" + splitSentence[offset].charAt(1) + "-" + splitSentence[offset].substring(1, splitSentence[offset].length + 1);
for (var j = 0; j < frequency && ((i * frequency + j) < splitSentence.length); j++)
builder += splitSentence[i * frequency + j] + " "
}
//remove the trailing space
return builder.substring(0, builder.length-1).toString()
};
const endOfSentence = new RegExp('[,.!?]', 'g');
/*
* Determine whether a given string contains sentence-ending punctuation.
* @param text text to check whether
* @return boolean whether the text contains a period, exclamation or question mark
*/
window.jsisEndOfSentence = function(text) {
if(!text.length) {
return false;
}
return Boolean((text.substring(text.length-1).match(endOfSentence) || []).length);
};
window.jsinsertIntoSentences = function(sentence, frequency, inserts, middle) {
var splitSentence = sentence.split(" ");
//utilitiesStringBuilder.setLength(0);
var builder = "";
// 1 in "frequency" words have an insert, with a minimum of 1.
var wordsToInsert = Math.floor(splitSentence.length / frequency + 1)
var offset = 0;
for (var i = 0; i < wordsToInsert; i++) {
var offset = Math.min(i * frequency + jsRandom(frequency), splitSentence.length - 1);
var insert = inserts[jsRandom(inserts.length-1)];
// If wanted, ensure not inserting to the start or end of a sentence
if (offset >= splitSentence.length -1 || jsisEndOfSentence(splitSentence[offset])) {
if (middle) {
// Skip if at end of string or sentence
continue;
}
// Add a full stop to the insert, creating its own sentence
insert += ".";
}
var len = splitSentence[offset].length;
// Remove duplicate commas if selected position ends with one and insert has one
if (insert.trim().charAt(0) == ',' && splitSentence[offset].charAt(len -1) == ',') {
splitSentence[offset] = splitSentence[offset].substring(0, len-1);
}
// Append the insert to this word:
splitSentence[offset] = splitSentence[offset] + insert;
}
//for (var word : splitSentence)
for (var i = 0; i < splitSentence.length; i++){
builder += splitSentence[i] + " ";
}
return builder.substring(0, builder.length-1).toString()
};
var sexSounds = [ " ~"+jsMoan("l")+"!~", " ~"+jsMoan("l")+"!~"," ~"+jsMoan("l")+"!~"," ~"+jsMoan("l")+"!~", " ~"+jsMoan("m")+"!~", " ~"+jsMoan("m")+"!~"," ~"+jsMoan("m")+"!~"," ~"+jsMoan("m")+"!~"];
window.jsaddSexSounds = function(sentence, frequency) {
return jsinsertIntoSentences(sentence, frequency, sexSounds, true);
};
var muffledSounds = [ " ~Mrph~", " ~Mmm~", " ~Mrmm~" ];
window.jsaddMuffle = function(sentence, frequency) {
return jsinsertIntoSentences(sentence, frequency, muffledSounds, true);
};
var drunkSounds = [ " ~Hic!~" ];
window.jsaddDrunkSlur = function(sentence, frequency) {
/* diploma man style here, maybe there's a better method?*/
var sentence = sentence.replaceAll("Hi", "Heeey")
var sentence = sentence.replaceAll("yes", "yesh")
var sentence = sentence.replaceAll("is", "ish")
var sentence = sentence.replaceAll("ss", "ssh")
var sentence = sentence.replaceAll("So", "Sho")
var sentence = sentence.replaceAll("so", "sho");
return jsinsertIntoSentences(sentence, frequency, drunkSounds, false)
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment