├── .gitattributes
├── .htaccess
├── README.md
├── _notes
└── .htaccess
├── index.php
├── script.js
└── styles.css
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.htaccess:
--------------------------------------------------------------------------------
1 | Options -Indexes
2 | RewriteEngine On
3 | RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?note=$1
4 |
5 |
6 | Header set X-Robots-Tag: "noindex, nofollow"
7 |
8 |
9 |
10 | Order Allow,Deny
11 | Deny from all
12 |
13 |
14 | # Uncomment the lines below to enable basic authentication.
15 | # See https://httpd.apache.org/docs/current/programs/htpasswd.html for generating your .htpasswd
16 |
17 | # AuthType basic
18 | # AuthName "website.name"
19 | # AuthUserFile "/home/user/update-path-to.htpasswd"
20 | # Require valid-user
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Minimalist-Web-Notepad-API
2 | Minimalist Web Notepad API:一款带API的开源轻量级简洁在线笔记本
3 |
4 | 相信大家都会试过寻找地方来进行临时记录,或者是传输一个文本给其它设备或者他人。
5 |
6 | 最近我在github发现了一个非常不错的项目[Minimalist Web Notepad][1]。
7 |
8 | 十分的轻量简洁代码仅5KB,用于临时记录与传输文本非常方便,简直是极简主义者必备品!
9 |
10 | 我在原项目的基础上加入了API接口,日常使用更加方便。
11 |
12 |
13 | 安装教程
14 | --
15 | 在index.php文件顶部,更改$base_url变量以指向您的站点。
16 | 确保允许Web服务器写入_notes目录。
17 |
18 | **在Apache上**
19 |
20 | 您可能需要启用mod_rewrite并.htaccess在站点配置中设置文件。
21 |
22 | **在Nginx上**
23 |
24 | 要启用URL重写,请将以下内容放入配置文件中:
25 | 如果记事本在根目录中:
26 |
27 | location / {
28 | rewrite ^/([a-zA-Z0-9_-]+)$ /index.php?note=$1;
29 | }
30 |
31 | 如果记事本在子目录中:
32 |
33 | location ~* ^/notes/([a-zA-Z0-9_-]+)$ {
34 | try_files $uri /notes/index.php?note=$1;
35 | }
36 |
37 | API文档
38 | -----
39 | **获取指定笔记文本**
40 |
41 | 接口地址:/{note}
42 |
43 | 请求方式:get
44 |
45 | 请求参数:raw
46 |
47 | 返回数据:指定笔记的内容(string)
48 |
49 | 示例参数:/demo?raw
50 |
51 | **新建指定地址笔记并写入文本**
52 | **或修改指定地址笔记文本**
53 |
54 | 接口地址:/{note}
55 |
56 | 请求方式:get post
57 |
58 | 请求参数:text
59 |
60 | 返回数据:saved(string)
61 |
62 | 示例参数:/demo?text=test
63 |
64 |
65 | **新建随机地址笔记并添加文本**
66 |
67 | 接口地址:/?new
68 |
69 | 请求方式:get post
70 |
71 | 请求参数:text
72 |
73 | 返回数据:新建的网址url(string)
74 |
75 | 示例参数:/?new&text=test
76 |
77 |
78 | Demo
79 | ----
80 | **通过网站进行文本传输**
81 |
82 | ![5.png][7]
83 |
84 | https://note.166167.xyz
85 |
86 |
87 | **通过IOS快捷指令进行剪切板同步**
88 | ![1.jpg][3]
89 | ![2.jpg][4]
90 |
91 | **通过Python应用进行Win剪切板同步**
92 |
93 | import win32clipboard as w
94 | import win32con
95 | import requests
96 |
97 | def copy():
98 | w.OpenClipboard()
99 | data = w.GetClipboardData(win32con.CF_UNICODETEXT)
100 | w.CloseClipboard()
101 | body = {
102 | "text": data,
103 | }
104 | r = requests.post('https://note.166167.xyz/demo', data = body)
105 | print(r.status_code,data)
106 |
107 | def paste():
108 | r = requests.get('https://note.166167.xyz/demo?raw')
109 | data = r.text
110 | w.OpenClipboard()
111 | w.SetClipboardData(win32con.CF_UNICODETEXT,data)
112 | w.CloseClipboard()
113 | print(r.status_code,data)
114 |
115 | def new():
116 | w.OpenClipboard()
117 | data = w.GetClipboardData(win32con.CF_UNICODETEXT)
118 | w.CloseClipboard()
119 | body = {
120 | "text": data,
121 | }
122 | r = requests.post('https://note.166167.xyz/?new', data = body)
123 | print(r.status_code,data)
124 |
125 |
126 | [1]: https://github.com/pereorga/minimalist-web-notepad
127 | [3]: https://search.pstatic.net/common?type=origin&src=https://www.mrchung.cn/usr/uploads/2020/04/1156753274.jpg
128 | [4]: https://search.pstatic.net/common?type=origin&src=https://www.mrchung.cn/usr/uploads/2020/04/2992297654.jpg
129 | [5]: https://search.pstatic.net/common?type=origin&src=https://www.mrchung.cn/usr/uploads/2020/04/3170686476.png
130 | [6]: https://search.pstatic.net/common?type=origin&src=https://www.mrchung.cn/usr/uploads/2020/04/1102607478.png
131 | [7]: https://search.pstatic.net/common?type=origin&src=https://www.mrchung.cn/usr/uploads/2020/04/3535009824.png
132 |
--------------------------------------------------------------------------------
/_notes/.htaccess:
--------------------------------------------------------------------------------
1 |
2 | Require all denied
3 |
4 |
5 | Order allow,deny
6 |
7 |
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 | 64) {
35 | header("Location: $base_url/" . substr(str_shuffle('234579abcdefghjkmnpqrstwxyz'), -5));
36 | die;
37 | }
38 | $path = $save_path . '/' . $_GET['note'];
39 | if (isset($_POST['text'])) {
40 | $text = $_POST['text'];
41 | if (save($path, $text)) {
42 | echo("saved");
43 | }
44 | die;
45 | }
46 | if (isset($_GET['text'])) {
47 | $text = $_GET['text'];
48 | if (save($path, $text)) {
49 | echo("saved");
50 | }
51 | die;
52 | }
53 | if (isset($_GET['raw'])) {
54 | if (is_file($path)) {
55 | echo(file_get_contents($path));
56 | } else {
57 | header('HTTP/1.0 404 Not Found');
58 | }
59 | die;
60 | }
61 | ?>
62 |
63 |
64 |
65 |
66 |
67 |
69 |
70 |
71 |
72 |
73 |
74 |
79 |
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/script.js:
--------------------------------------------------------------------------------
1 | /*! Minimalist Web Notepad | https://github.com/pereorga/minimalist-web-notepad */
2 |
3 | function uploadContent() {
4 |
5 | // If textarea value changes.
6 | if (content !== textarea.value) {
7 | var temp = textarea.value;
8 | var request = new XMLHttpRequest();
9 |
10 | request.open('POST', window.location.href, true);
11 | request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
12 | request.onload = function() {
13 | if (request.readyState === 4) {
14 |
15 | // Request has ended, check again after 1 second.
16 | content = temp;
17 | setTimeout(uploadContent, 1000);
18 | }
19 | }
20 | request.onerror = function() {
21 |
22 | // Try again after 1 second.
23 | setTimeout(uploadContent, 1000);
24 | }
25 | request.send('text=' + encodeURIComponent(temp));
26 |
27 | // Make the content available to print.
28 | printable.removeChild(printable.firstChild);
29 | printable.appendChild(document.createTextNode(temp));
30 | }
31 | else {
32 |
33 | // Content has not changed, check again after 1 second.
34 | setTimeout(uploadContent, 1000);
35 | }
36 | }
37 |
38 | var textarea = document.getElementById('content');
39 | var printable = document.getElementById('printable');
40 | var content = textarea.value;
41 |
42 | // Make the content available to print.
43 | printable.appendChild(document.createTextNode(content));
44 |
45 | textarea.focus();
46 | uploadContent();
47 |
--------------------------------------------------------------------------------
/styles.css:
--------------------------------------------------------------------------------
1 | /*! Minimalist Web Notepad | https://github.com/pereorga/minimalist-web-notepad */
2 |
3 | body {
4 | margin: 0;
5 | background: #ebeef1;
6 | }
7 | .container {
8 | position: absolute;
9 | top: 20px;
10 | right: 20px;
11 | bottom: 20px;
12 | left: 20px;
13 | }
14 | #content {
15 | font-size: 100%;
16 | margin: 0;
17 | padding: 20px;
18 | overflow-y: auto;
19 | resize: none;
20 | width: 100%;
21 | height: 100%;
22 | min-height: 100%;
23 | -webkit-box-sizing: border-box;
24 | -moz-box-sizing: border-box;
25 | box-sizing: border-box;
26 | border: 1px #ddd solid;
27 | outline: none;
28 | }
29 | #printable {
30 | display: none;
31 | }
32 |
33 | @media (prefers-color-scheme: dark) {
34 | body {
35 | background: #383934;
36 | }
37 | #content {
38 | background: #282923;
39 | color: #f8f8f2;
40 | border: 0;
41 | }
42 | }
43 |
44 | @media print {
45 | .container {
46 | display: none;
47 | }
48 | #printable {
49 | display: block;
50 | white-space: pre-wrap;
51 | word-break: break-word;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------