Skip to content

Instantly share code, notes, and snippets.

@hyuki
Last active November 9, 2019 06:16
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/6bc3ab320b22d8869062df7819a795dd to your computer and use it in GitHub Desktop.
Save hyuki/6bc3ab320b22d8869062df7819a795dd to your computer and use it in GitHub Desktop.
Create a new page in Scrapbox (scrapbox.io)
<!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>
@hyuki
Copy link
Author

hyuki commented Nov 9, 2019

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