Skip to content

Instantly share code, notes, and snippets.

@Kelsin33
Created May 4, 2018 17:00
Show Gist options
  • Save Kelsin33/a54223adb720299b5fde6abcd75b17a7 to your computer and use it in GitHub Desktop.
Save Kelsin33/a54223adb720299b5fde6abcd75b17a7 to your computer and use it in GitHub Desktop.
$(document).ready(function(){
$("#player").hide();
$('#questionForm').submit(function(ev) {
ev.preventDefault(); // to stop the form from submitting
// Patterns defined using the RegEx syntax JS uses (a subset of PCRE)
var patterns = [
[/.*personal information.*/, 'personal info'],
[/.*data.*/, 'data'],
[/.*(risk)|(threat).*security.*/, 'security threat'],
[/test/, 'test']
]
var vid = document.getElementById("myVideo");
var userInput = ev.target['userInput']
console.log("Input3:", userInput.value);
// For every pattern we have defined
for (var i = patterns.length - 1; i >= 0; i--) {
// Test it against the string to see if it matches
var res = userInput.value.search(patterns[i][0])
if ( res != -1 ){
console.log("Pattern matched:", patterns[i][1])
// Trigger a video playback here using patterns[i][1] as the key
$("#player").show();
vid.onplaying = function() {
alert("The video is now playing");
};
break
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment