clearIncognito/Private mode detected - saving text to browser's local storage is not available! Please open Notepad in regular window!
'); childWindow.document.write(document.getElementById('area').value.replace(/\n/gi,'
')); childWindow.document.write(' '); childWindow.print(); childWindow.document.close(); childWindow.close(); } function Help() { window.location.href = 'notepad_help.html'; } // works with chrome, not in FF function Exit() { window.open('','_self',''); window.close(); } function New() { cancelSaveFile(); Snapshot(); if( area.value != "" ) { var r=confirm("Are you sure?"); if (r==true) { area.value = ""; localStorage.notepad_filename = ''; SetDocTitle(); //Snapshot(); } } area.focus(); } function Open() { cancelSaveFile(); var fileElem = document.getElementById("fileElem"); fileElem.focus(); fileElem.click(); } function LocalSave() { localStorage.notepad_text = area.value; area.focus(); } function Save_As() { if( area.value=='' ) return; document.getElementById("getFilename").style.display = ""; //return false; } function Save() { if( area.value=='' ) return; if( localStorage.notepad_filename=='' ) document.getElementById("getFilename").style.display = ""; else saveFile(); return false; } function SelectAll() { area.select(); } function Del() { s = getSelect(area); if( s.text.length!=0 ) { Snapshot(); var text = area.value; fillString(text,"", s.start, s.end); } pos = s.start; setCaret(pos); area.focus(); } function Del2() { s = getSelect(area); if( s.text.length!=0 ) { Snapshot(); var text = area.value; fillString(text,"", s.start, s.end-1); } pos = s.start; setCaret(pos); area.focus(); } function Cut() { s = getSelect(area); if( s.text.length!=0 ) { Snapshot(); selectedText = s.text; fillString(area.value,"", s.start, s.end); } else selectedText = ''; pos = s.start; setCaret(pos); area.focus(); } function Copy() { //document.execCommand('copy'); s = getSelect(area); if( s.text.length!=0 ) selectedText = s.text; else selectedText = ''; setSelect(area,s.start,s.end); area.focus(); } function Paste() { s = getSelect(area); Snapshot(); if( selectedText.length!=0 ) { //Snapshot(); var text = area.value; fillString(text, selectedText, s.start, s.end); pos = s.start+selectedText.length; setCaret(pos); } area.focus(); } function cancelSaveFile() { document.getElementById("getFilename").style.display = "none"; } function saveFile() { document.getElementById("getFilename").style.display = "none"; var name = document.getElementById("filename").value; if( name=='' ) name='filename.html'; localStorage.notepad_filename = name; SetDocTitle(); LocalSave(); s = area.value; OSName = GetOS(); if( OSName=="Windows" ) s = s.replace(/\n/g,'\r\n'); var blob = new Blob([s], {type: "text/plain;charset=utf-8"}); saveAs(blob, localStorage.notepad_filename); } function loadFile() { var fileElem = document.getElementById("fileElem").files[0]; var name = fileElem.name; var reader = new FileReader(); reader.onloadend = function(evt) { if( evt.target.readyState==FileReader.DONE ) { localStorage.notepad_filename = name; SetDocTitle(); //area.value = evt.target.result; s = evt.target.result; OSName = GetOS(); if( OSName=="Windows" ) s = s.replace(/\r\n/g,'\n'); area.value = s; area.focus(); } }; reader.readAsText(fileElem); } function getSelect(obj) { var s = obj.selectionStart; var e = obj.selectionEnd; var txt = obj.value.substring(s,e); return { start: s, end: e, text: txt }; } function setSelect(obj, start, end) { obj.focus(); obj.selectionStart = start; obj.selectionEnd = end; } function fillString(text, selectText, start, end) { // split textarea value into three pieces: before startPosition, // startPosition until endPosition, and after endPosition var str1 = text.substring(0,start); var str2 = text.substring(start,end); var str3 = text.substring(end,text.length); // replace str2 with formatted substring (selectedText) str2 = selectText; area.value = str1+str2+str3; } // !!! check with IE function getCaret() { return area.selectionStart; } function setCaret(pos) { area.selectionStart = pos; area.selectionEnd = pos; } function Snapshot() { pos = getCaret(); txt = area.value; if( txt_hist[ihist-1]==area.value ) return; if( ihist==nhist ) { pos_hist.push(pos); txt_hist.push(txt); ihist++; if( pos_hist.length > Nhist ) { pos_hist.shift(); txt_hist.shift(); ihist--; } } else { pos_hist[ihist] = pos; txt_hist[ihist] = txt; ihist++; if( (ihist+1)<=nhist ) for(i=ihist+1; i<=nhist; i++) { pos_hist.pop(); txt_hist.pop(); } } nhist = ihist; } function Undo() { //if( browser=='Chrome' ) if(0) { document.execCommand('undo',false,null); return; } if( nhist==0 ) return; if( ihist<2 ) return; if( txt_hist[ihist-1]!=area.value ) Snapshot(); ihist--; i = ihist-1 pos = pos_hist[i]; txt = txt_hist[i]; setCaret(pos); area.value = txt; } function Redo() { //if( browser=='Chrome' ) if(0) { document.execCommand('redo',false,null); return; } if( nhist==0 ) return; if( ihist==nhist ) return; pos = pos_hist[ihist]; txt = txt_hist[ihist]; ihist++; setCaret(pos); area.value = txt; } function DecSize() { if( localStorage.notepad_fontSize > 8 ) { localStorage.notepad_fontSize--; if( localStorage.notepad_fontSize >= 13 ) localStorage.notepad_fontSize--; SetFontSize(); } area.focus(); } function IncSize() { if( localStorage.notepad_fontSize < 50 ) { localStorage.notepad_fontSize++; if( localStorage.notepad_fontSize >= 13 ) localStorage.notepad_fontSize++; SetFontSize(); } area.focus(); } function TextLines() { var visibility=$("#tlines").css('visibility'); $("#tlines").css('visibility', (visibility == 'visible') ? 'hidden' : 'visible'); if( visibility == 'visible' ) $("#area").removeClass("notes"); else $("#area").addClass("notes"); } function SetFontSize() { area.style.fontSize = localStorage.notepad_fontSize+'px'; } function SetDocTitle() { var name = localStorage.notepad_filename; if( name=='' ) document.title = 'Notepad | Online Notes free, no login required'; else document.title = 'Notepad - '+localStorage.notepad_filename; } function SetBar() { //var pos=$("#area").prop("selectionStart"); var pos=$("#area").prop("selectionEnd"); var txt=$("#area").val(); txt = txt.substring(0,pos); var line = txt.split('\n').length; var col = txt.split('\n')[line-1].length+1; $("#bar").html("Line "+line+", Column "+col); }