开源一个无后端也无前端彻底无服务的网页版记事本

2023-06-01 01:12:48 +08:00
 meeop

data:text/html;base64,PGh0bWwgY29udGVudGVkaXRhYmxlPmVkaXQgbWU8L2h0bWw+

复制到浏览器即可使用,可加书签,可分享,不需要网络,全平台可用

有时候需要有个地方临时复制粘贴一些东西,这时候可以用记事本,但是记事本或者其他文本编辑软件关闭时一般需要确认是否保存,且这些临时内容会和工作内容混合

还有个问题是记事本页面不够大,ui 也略复杂一点

这个网页版记事本就能支持这种场景,原则上不支持保存,随用随关,铺满全屏

而且我觉得最有意思的点是,这其实是一个彻底开源极端易于分享的软件形式,软件所有内容都塞到 url 数据里,所见即所得,无需安装,适配全平台,用户还能随时修改逻辑,无需网络,没有服务器成本

缺点是软件大小有限制 以及软件作者可能不太好赚钱

17312 次点击
所在节点    分享创造
150 条回复
azui999
2023-06-02 14:10:10 +08:00
挺有趣,收藏了
googlefans
2023-06-02 15:02:30 +08:00
太牛了..
太有创艺了
zhw2590582
2023-06-02 17:04:21 +08:00
有点意思
Leung818
2023-06-02 17:34:28 +08:00
我没啥文化,先来一句卧槽
kobezone
2023-06-02 18:43:50 +08:00
真是 NB 这都能想到 妙啊 楼主🐂🍺plus
dode
2023-06-02 21:32:19 +08:00
@codehz 不能用
mghio
2023-06-02 21:38:49 +08:00
以下是来自 Google Bard 对其工作原理的解释:

The code data:text/html;base64,PGh0bWwgY29udGVudGVkaXRhYmxlPmVkaXQgbWU8L2h0bWw+ in a browser URL is a data URI scheme. It is a way of embedding a small amount of data, such as text, images, or CSS, directly into a web page. This can be useful for things like embedding a small logo or tracking pixel into a page, or for providing fallback content for users who cannot load external resources.

The data URI scheme is defined by the following syntax:

Code snippet
data:[<media type>][;base64],<data>
Use code with caution. Learn more
The <media type> is a string that identifies the type of data being embedded. The <data> is the actual data, encoded in base64.

In the example you provided, the <media type> is text/html and the <data> is the HTML code for a simple page. This page contains a heading and a paragraph of text.

When a browser encounters a data URI, it will decode the base64 data and then treat it as if it had been loaded from an external resource. In this case, the browser will load the HTML code and display it as a web page.

Data URIs can be a useful way to embed small amounts of data into web pages. However, they should be used sparingly, as they can increase the size of the page and make it slower to load.

Here are some additional things to keep in mind when using data URIs:

The maximum size of a data URI is 32KB.
Data URIs are not supported by all browsers.
Data URIs can be used to embed malicious code.
If you are considering using data URIs, it is important to weigh the benefits and drawbacks carefully.
fox233
2023-06-03 14:18:58 +08:00
这种链接可以生产二维码吗?还有就是手机端访问字很小,可以适配手机端吗
Llesue
2023-06-03 16:33:25 +08:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>小小记事本</title>
<style>
* {
margin: 0 auto;
box-sizing: border-box;
color: #777777;
outline: none;
}
body {
background: #f5f5f5;
}
.main {
display: flex;
flex-direction: column;
max-width: 960px;
}
.container {
display: flex;
width: 100%;
margin: 5vh 0 1.5vh;
}
.title {
flex: 1;
font-size: 2em;
font-weight: 600;
padding-left: 16px;
white-space: nowrap;
}
.edit {
width: 100%;
min-height: 50vh;
padding: 16px;
font-size: 1.2em;
border: 1px dashed #ccc;
border-radius: 2px;
background: #fff;
}
button {
border: 1px solid #ccc;
padding: 0 20px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="main">
<div class="container">
<div class="title" contenteditable>编辑标题✏️</div>
<button id="btn">复制当前页 dataUrl</button>
</div>
<div class="edit" contenteditable>编辑这里开始.✏️</div>
</div>
<script>
function utf8_to_b64(str) {
return window.btoa(unescape(encodeURIComponent(str)));
}

// function b64_to_utf8(str) {
// return decodeURIComponent(escape(window.atob(str)));
// }

const btn = document.querySelector("#btn");
btn.addEventListener("click", () => {
const htmlContent = document.querySelector("html");
console.log(htmlContent.innerHTML);
const dataUrl = "<html>" + htmlContent.innerHTML + "</html>";
const base64 = utf8_to_b64(dataUrl);
// console.log(base64);

const inputValue = `data:text/html;base64,${base64}`
const input = document.createElement("input");
input.setAttribute("readonly", "readonly");
input.setAttribute("value", inputValue);
document.body.appendChild(input);
input.setSelectionRange(0, 9999);
input.select();
document.execCommand("copy");
document.body.removeChild(input);
alert('地址已复制。')
});
</script>
</body>
</html>
Llesue
2023-06-03 16:34:08 +08:00
@Llesue 不会做那个 dataurl 😂
Llesue
2023-06-03 17:55:13 +08:00
data:text/html;charset=utf-8,<title>小小记事本</title><style>* {margin: 0 auto;box-sizing: border-box;color: gray;outline: none;border-radius: 5px;}</style><script> function copyToClipboard() { var htmlContent = document.documentElement.outerHTML; var tempInput = document.createElement("textarea"); tempInput.style.opacity = 0; tempInput.value = 'data:text/html;charset=utf-8,' +htmlContent; document.body.appendChild(tempInput); tempInput.select(); document.execCommand("copy"); document.body.removeChild(tempInput); alert("已复制"); } </script><body style="background: gainsboro;"><div style="display: flex; flex-direction: column; max-width: 960px;"><div style="display: flex; width: 100%; margin: 5vh 0 1.5vh;"><div style="flex: 1; font-size: 2em; font-weight: 600; padding-left: 16px; white-space: nowrap;" contenteditable>编辑标题✏️</div><button onclick="copyToClipboard()" style="border: 1px solid lightgray; padding: 0 20px; cursor: pointer; font-size: 1em;">复制当前页 dataUrl</button></div><div style="width: 100%; min-height: 50vh; padding: 16px; font-size: 1.2em; border: 1px dashed lightgray; background: whitesmoke; text-align: justify;" contenteditable>编辑这里开始.✏️

会了
lizhenda
2023-06-03 21:20:51 +08:00
厉害了啊,还可以这么玩
Llesue
2023-06-04 01:36:36 +08:00
@meeop #106 试过了,内容加不到 localstorage 里……
meeop
2023-06-04 02:05:38 +08:00
@fox233 网上搜索个二维码生成器就能做二维码了,但我试了下微信扫不会帮你打开链接,只能复制扫出来的内容手动贴浏览器执行。适配手机端的话肯定可以,这就是个标准网页,但需要额外开发下
fox233
2023-06-04 10:41:28 +08:00
@fox233 我试了也是这样,想知道怎么直接打开这个二维码
xxl123456
2023-06-05 17:19:08 +08:00
有无大佬解释原理是什么
lunhub
2023-06-05 17:27:31 +08:00
@Llesue 牛逼啊是
zeep
2023-06-06 00:24:49 +08:00
@zhaol 如果分享时可以缩短链接就好了
jixule
2023-06-06 15:07:51 +08:00
@Llesue 试了一下,界面好看多了,有俩问题:1. 如果复制 vscode 内容,编辑区带有格式生成 url ,打开是空白; 2.编辑区如果复制纯文本,遇到 16 进制颜色的#后面就不显示了,标题中有#后面页面全都不显示了
ixoy
2023-06-06 17:08:43 +08:00

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/944717

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX