Skip to content

Instantly share code, notes, and snippets.

@hyuki
Created July 25, 2019 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyuki/c490bcd617a8bffcc6cdfac7c997197a to your computer and use it in GitHub Desktop.
Save hyuki/c490bcd617a8bffcc6cdfac7c997197a to your computer and use it in GitHub Desktop.
oneline-memo - Store any input text to your browser.
<!DOCTYPE html>
<html lang="ja">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>一行メモ</title>
<style>
input {
width: 50%;
height: 2em;
font-size: x-large;
}
</style>
</head>
<body>
<h1>一行メモ</h1>
<p>文字列を入力してEnterを打つとブラウザにその文字列が保存され、リロード後も再表示される。</p>
<input type="text" id="ONELINE-MEMO" placeholder="ONELINE-MEMO">
<script src="https://code.jquery.com/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"></script>
<script>
$(function() {
const key = 'ONELINE-MEMO'
const onelineMemo = localStorage.getItem(key);
if (!onelineMemo || onelineMemo.length == 0) {
$('#ONELINE-MEMO').attr('placeholder', 'ONELINE-MEMO');
} else {
$('#ONELINE-MEMO').val(onelineMemo);
}
$('#ONELINE-MEMO').keydown(function(e) {
if (e.keyCode == 13) {
const onelineMemo = $('#ONELINE-MEMO').val();
localStorage.setItem(key, onelineMemo);
}
return true;
});
$("#ONELINE-MEMO").focus();
});
</script>
</body>
</html>
@hyuki
Copy link
Author

hyuki commented Jul 25, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment