Store data in pathname instead of hash

master
Boris Kubiak 2020-04-25 17:35:22 +02:00
parent fd019ce7c9
commit eb7f87d6aa
4 changed files with 12 additions and 16 deletions

View File

@ -1,4 +1,4 @@
lint: lint:
npx prettier --write --single-quote --tab-width=4 --print-width=120 index.js *.{html,css,md} npx prettier --write --single-quote --tab-width=4 --print-width=120 index.js *.{html,css,md}
dev: dev:
npx serve npx serve -s

View File

@ -12,9 +12,9 @@ As a result, there is no risk of data being lost, censored or deleted. The whole
When you click on "Generate Link", NoPaste compresses the whole text using the When you click on "Generate Link", NoPaste compresses the whole text using the
[LZMA algorithm](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Markov_chain_algorithm), encodes it in [LZMA algorithm](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Markov_chain_algorithm), encodes it in
[Base64](https://en.wikipedia.org/wiki/Base64), and puts it in the optional fragment, at the end of the URL: `nopaste.ml/#<your data goes here>` [Base64](https://en.wikipedia.org/wiki/Base64), and puts it just after the first `/`, in the URL: `nopaste.ml/<your data goes here>`
When you open a link which contains data, NoPaste decodes the fragment, decompresses it, and displays the result in the editor When you open a link, NoPaste reads, decodes, and decompresses whatever is after the `/`, and displays the result in the editor
## Embedded NoPaste snippets ## Embedded NoPaste snippets
@ -24,6 +24,6 @@ You can include NoPaste code snippets into your own website by clicking the _Emb
Feel free to edit the generated `height` and `width` attributes, so they suit your needs Feel free to edit the generated `height` and `width` attributes, so they suit your needs
[intro-img]: https://nopaste.ml/?lang=python#XQAAAQA6BAAAAAAAAAAFYH9Ev4Ly6wIDoAZQ25VXENWodOrWpmx8bfd8j6jeNeL/0fGICEpU6gh9GhXuFjqBBpJFOvefaxUXJquUWRQarmV+S0SHFOLUFyg/dw8OQI6RB6Y1yliOBWGL916HxAGqgwyLqjkH4w450OLk+q9oJYS6PrZfXU5uBC5DLe76OkG25ibvbsasKN51JuVyRedgoF/d7F9d6L7p02q0jHAM9pnPpKOKqlIVsNnXwYKXK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gldHO8txFQmZAYEH9oKJyGJLTAKsUuhuXVHxv/xxEyI [topaz-example]: https://topaz.github.io/paste/#XQAAAQDzAAAAAAAAAAAFFgvDUiqpf8dDPleMqfsqtbQYE28suCtDTB9iyFgGByXgSRMepMuokjoACV4UPgBzwM3p+V/N2rCi8m90FkQfsRuMJ4LrZVFgr81wKDc2okcywbJBz7OGNPpc8xu2lAkpSekqRO+I/OYMpqBE6w6JLw+cFocCptTbd+jBPuNfBVQrhYyQ3mN0BXmj+rejvVB8jG6J/HPP4u+m32pm0UBS0eb8rmaeDnanRkVI8/gs09nh8YK93sjVfIOAYOXoB2da//bUcos=

View File

@ -19,8 +19,8 @@ npm/codemirror@5.52.0/addon/scroll/simplescrollbars.css,
npm/codemirror@5.52.0/theme/dracula.min.css npm/codemirror@5.52.0/theme/dracula.min.css
" "
/> />
<link rel="stylesheet" href="style.css" /> <link rel="stylesheet" href="/style.css" />
<link href="favicon.ico" rel="icon" type="image/x-icon" /> <link href="/favicon.ico" rel="icon" type="image/x-icon" />
<meta <meta
name="description" name="description"
content="NoPaste is a client-side paste service which works with no database, and no back-end code. The whole data is stored in shareable links and nowhere else!" content="NoPaste is a client-side paste service which works with no database, and no back-end code. The whole data is stored in shareable links and nowhere else!"
@ -103,5 +103,5 @@ npm/codemirror@5.52.0/addon/mode/simple.min.js,
npm/codemirror@5.52.0/addon/scroll/simplescrollbars.js, npm/codemirror@5.52.0/addon/scroll/simplescrollbars.js,
npm/codemirror@5.52.0/mode/meta.min.js npm/codemirror@5.52.0/mode/meta.min.js
"></script> "></script>
<script src="index.js"></script> <script src="/index.js"></script>
</html> </html>

View File

@ -52,7 +52,7 @@ const initLangSelector = () => {
}; };
const initCode = () => { const initCode = () => {
const base64 = location.hash.substr(1); const base64 = location.pathname.substr(1) || location.hash.substr(1);
if (base64.length === 0) { if (base64.length === 0) {
return; return;
} }
@ -113,17 +113,13 @@ const hideCopyBar = (success) => {
// Build a shareable URL // Build a shareable URL
const buildUrl = (rawData, mode) => { const buildUrl = (rawData, mode) => {
const url = const url = `${location.protocol}//${location.host}/` + rawData + `?lang=${encodeURIComponent(select.selected())}`;
`${location.protocol}//${location.host}${location.pathname}` +
`?lang=${encodeURIComponent(select.selected())}` +
(mode === 'iframe' ? '&readonly' : '') +
`#${rawData}`;
if (mode === 'markdown') { if (mode === 'markdown') {
return `[NoPaste snippet](${url})`; return `[NoPaste snippet](${url})`;
} }
if (mode === 'iframe') { if (mode === 'iframe') {
const height = document.getElementsByClassName('CodeMirror-sizer')[0].clientHeight + 8; const height = document.getElementsByClassName('CodeMirror-sizer')[0].clientHeight + 8;
return `<iframe width="100%" height="${height}" frameborder="0" src="${url}"></iframe>`; return `<iframe width="100%" height="${height}" frameborder="0" src="${url}&readonly"></iframe>`;
} }
return url; return url;
}; };