TypeScript
Compiler: tsc greeter.js
Index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE = edge">
<meta name="viewport" content="width = device-width, initial-scale = 1">
</head>
<body>
<script type="text/javascript" src="file:///D:/Prj/AngularCLI/Prj01/greeter.js"></script>
</body>
</html>
Greeter.js
class Student {
fullName: string;
constructor(public firstName, public midleName, public lastName){
this.fullName = firstName + " " + midleName + " " + lastName;
}
}
interface Person {
name: string;
age: number;
}
function birthday(someone : Person) : Person {
return {name: someone.name, age: someone.age};
}
function greeter(person : Person) {
return "Hello, " + person.name + " " + person.number;
}
var user = new Student("Manh", "Viet", "Nguyen");
document.body.innerHTML = greeter(user);
document.addEventListener("DOMContentLoaded", function (event) {
console.log(JSON.stringify(birthday({ name: "Judy", age: 39 })));
console.log(JSON.stringify(user));
console.log(JSON.parse("{'Name':'Manh','Age':34}"));
});
How to put Javascript code into the Address bar
The following is a snippet of code that everyone should probably have in their back pocket these days. Especially if you do a lot of online money transactions. The following javascript injection will reveal a true server name if the website you are looking at is being spoofed (hosted by someone other than the real site who probably wants to steal your money and/or identity) Just go to the page you need to check (e.g.-when you go to you bank's site or feel questionable) and post this script in the address bar:
javascript:alert("The actual URL is:\t\t" + location.protocol + "//" + location.hostname + "/" + "\nThe address URL is:\t\t" + location.href + "\n" + "\nIf the server names do not match, this may be a spoof.");
How to put Javascript code into the URL in a Bookmark
javascript:(function() {alert("The actual url is:\n" + location.protocol + "//" + location.hostname + "/" + "\n\nThe address URL is:\n" + location.href + "\n" + "\nIf the server names do not match, this may be a spoof.")})()
Select or Deselect Text Inside an Element Using JavaScript
https://www.thewebflash.com/select-or-deselect-text-inside-an-element-using-js/
Source Code
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
function selectText(element) {
if (/INPUT|TEXTAREA/i.test(element.tagName)) {
element.focus(); if (element.setSelectionRange) { element.setSelectionRange(0, element.value.length); } else { element.select(); }
return;
}
var rangeObj, selection; if (document.createRange) { rangeObj = document.createRange(); rangeObj.selectNodeContents(element); selection = window.getSelection(); selection.removeAllRanges(); selection.addRange(rangeObj); } else if (document.body.createTextRange) { rangeObj = document.body.createTextRange(); rangeObj.moveToElementText(element); rangeObj.select(); }
}
function deselect(element) {
if (element && /INPUT|TEXTAREA/i.test(element.tagName)) {
if ('selectionStart' in element) { element.selectionEnd = element.selectionStart; }
element.blur();
}
if (window.getSelection) { window.getSelection().removeAllRanges(); } else if (document.selection) { document.selection.empty(); }
}
$(function ($) { $('#btnSelect1').click(function () { selectText($('#exampleDiv')[0]); window.setTimeout(deselect, 3000); }); $('#btnSelect2').click(function () { selectText($('#exampleTextarea')[0]); window.setTimeout(function () { deselect($('#exampleTextarea')[0]); }, 3000); }); });
</script>
</head>
<body>
<h3>Demo</h3>
<style>
#exampleDiv {
padding: 8px;
background-color: white;
white-space: pre;
overflow-x: auto;
margin-bottom: 1em;
}
#exampleTextarea {
display: block;
width: 99%;
margin-bottom: 1em;
}
</style>
<p>Click the 'Run Demo' button below to select text inside a <div> element and deselect automatically in 3 seconds.</p>
<div class="post-format">
<div class="format-container pad">
<div id="exampleDiv">
Lorem ipsum dolor sit amet, autem assentior signiferumque sea ei, ad zril choro epicurei pri.
Qui an assum mazim adversarium. His ex illum noluisse atomorum, at tation laoreet quo,
qui movet petentium laboramus at. Usu ei dicam laoreet efficiendi. Dolorem sententiae ea vix,
illum vitae no eos. Eu eam prima pertinax dissentiet, laboramus disputando ullamcorper mei ex.
</div>
<p><button id="btnSelect1">Run Demo</button></p>
</div>
</div>
<p>Click the 'Run Demo' button below to select text inside a <textarea> and deselect it automatically in 3 seconds.</p>
<div class="post-format">
<div class="format-container pad">
<textarea id="exampleTextarea" rows="4" spellcheck="false">Lorem ipsum dolor sit amet, et sint inermis oportere cum, ut sea dolore aeterno euripidis, blandit appareat consequat nec te. Te natum lucilius mel. Ea sed numquam nominavi instructior, tollit utroque senserit ea eam. Eam putant partiendo ei.</textarea>
<p><button id="btnSelect2">Run Demo</button></p>
</div>
</div>
</body>
</html>