Last active
November 9, 2019 06:16
-
-
Save hyuki/6bc3ab320b22d8869062df7819a795dd to your computer and use it in GitHub Desktop.
Create a new page in Scrapbox (scrapbox.io)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> | |
<meta charset="utf-8"> | |
<title>Scrapbox</title> | |
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> | |
</head> | |
<body> | |
<div class="container-fluid"> | |
<div class="row"> | |
<div class="col-xs-3"> | |
<div class="panel panel-primary"> | |
<div class="panel-heading">Create a new page</div> | |
<div class="panel-body"> | |
<textarea id="SCRAPBOX-NEW" style="border:none; box-shadow:none; width:100%; outline:none;" class="list-group-item form-control" placeholder=""></textarea> | |
</div> | |
<div class="panel-footer"> | |
<a id="SCRAPBOX-CREATE" class="btn btn-primary">Create</a> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div><!-- /container-fluid --> | |
<script> | |
$(function() { | |
const project = 'https://scrapbox.io/PROJECT-NAME/'; | |
function create() { | |
if (!navigator.onLine) { | |
alert("Network is offline."); | |
} else if (confirm('Create a new page in Scrapbox')) { | |
const val = $('#SCRAPBOX-NEW').val(); | |
const ar = val.split('\n'); | |
const title = ar.shift(); | |
const body = ar.join("\n"); | |
window.open(project + encodeURIComponent(title) + '?body=' + encodeURIComponent(body)); | |
$('#SCRAPBOX-NEW').val(''); | |
} | |
} | |
$('#SCRAPBOX-NEW').attr('placeholder', 'Title'+"\n"+'Body'); | |
$('#SCRAPBOX-NEW').keydown(function(e) { | |
if (e.metaKey && e.keyCode == 13) { | |
create(); | |
return false; | |
} | |
return true; | |
}); | |
$('#SCRAPBOX-CREATE').click(function(e) { | |
create(); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://twitter.com/hyuki/status/1193049581296082945