├── .gitignore ├── LICENSE ├── README.md ├── package.json ├── simplereddit.js └── wrangler.toml /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /dist 3 | **/*.rs.bk 4 | Cargo.lock 5 | bin/ 6 | pkg/ 7 | wasm-pack.log 8 | worker/ 9 | node_modules/ 10 | .cargo-ok 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. 122 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [SimpleReddit](https://simplereddit.ethan.link) 2 | 3 | No distractions. No comments sections. No stylesheets. No JavaScript. 4 | 5 | Just an HTML-only Reddit client to stop you entering an internet time vortex. 6 | ## FAQs 7 | 8 | ### Why did you make this? 9 | 10 | I wanted a quick way to check Reddit, stay up-to-date and read interesting things without getting distracted. 11 | 12 | If I intentionally want to go down a Reddit rabbithole, I'll browse it via [Libreddit](https://github.com/spikecodes/libreddit) (which is still a lot better than the normal Reddit UI!) 13 | 14 | ### Why is there no CSS or JavaScript? 15 | 16 | Why should there be CSS or JavaScript? I think the site works just fine, and it's a bit of a proof to myself and others that you can make a perfectly functional and usable site using the powers of plain HTML alone. 17 | 18 | ### Are you sure there's no CSS or JS? Not even a sneaky little `style=""`? 19 | 20 | There's none! For proof, here's the site's [Content-Security-Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP): 21 | 22 | ``` 23 | default-src 'none'; img-src https://simplereddit.ethan.link/favicon.ico 24 | ``` 25 | 26 | This means the allowed sources for scripts and styles is `'none'`, so even if there was any CSS or JS on the page (including via attributes), the browser would refuse to run it! 27 | 28 | ### How/where does this run? 29 | 30 | It's a single no-dependency JavaScript file intended to be deployed via [Cloudflare Workers](https://workers.cloudflare.com). It should be pretty easy port to any hosting/infrastructure though, as it's a single JS file that can be easily adapted. 31 | 32 | ### Can I self-host this? 33 | 34 | Sure! To host on your own Cloudflare account, just clone the repo, update the details in `wrangler.toml`, then run `wrangler publish` in your terminal. 35 | 36 | If you want to self-host elsewhere, it shouldn't be too hard to adapt the JS file, the only things that will need changing is where `handleRequest` is called from, and possibly the method used to return HTTP responses. 37 | 38 | ### Can I contribute? 39 | 40 | Since it's a fairly small-scale project, I'm not sure how many things there are that need doing! But if you have any ideas or find any bugs, feel free to leave an issue or pull request. 41 | 42 | If you enjoy SimpleReddit and want to leave a small tip, you can [☕ buy me a coffee](https://www.buymeacoffee.com/Booligoosh). -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "name": "simplereddit", 4 | "version": "1.0.0", 5 | "description": "A simple, HTML-only Reddit client", 6 | "license": "CC0-1.0", 7 | "main": "simplereddit.js", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/Booligoosh/SimpleReddit.git" 11 | }, 12 | "scripts": { 13 | "test": "echo \"Error: no test specified\" && exit 1", 14 | "format": "prettier --write '**/*.{js,css,json,md}'" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /simplereddit.js: -------------------------------------------------------------------------------- 1 | const CSP = 2 | "default-src 'none'; img-src https://simplereddit.ethan.link/favicon.ico"; 3 | const ITEMS_LIMIT = 20; 4 | 5 | addEventListener("fetch", (event) => { 6 | event.respondWith( 7 | handleRequest(event.request).catch( 8 | (err) => 9 | new Response(err.stack, { 10 | status: 500, 11 | headers: { 12 | "Content-Security-Policy": CSP, 13 | }, 14 | }) 15 | ) 16 | ); 17 | }); 18 | 19 | async function handleRequest(request) { 20 | const url = new URL(request.url); 21 | const pathname = url.pathname; 22 | // Favicon 23 | if (pathname === "/favicon.ico") 24 | return fetch("https://files.ethan.link/simplereddit.ico"); 25 | // Robots.txt 26 | if (pathname === "/robots.txt") 27 | return new Response("User-agent: *\nDisallow: /"); 28 | // Subreddit pages 29 | if (pathname.startsWith("/r/")) return subredditPage(request, url); 30 | // Home page 31 | if (pathname === "/") return homePage(); 32 | // Home page form submissions 33 | if (pathname === "/form") { 34 | return Response.redirect( 35 | `${url.origin}/r/${url.searchParams.get("subreddit")}`, 36 | 301 37 | ); 38 | } 39 | // 404 catch-all 40 | return notFoundPage(); 41 | } 42 | 43 | function homePage() { 44 | const html = ` 45 | 46 | 47 | 48 | 49 | SimpleReddit 50 | 51 | 52 |
53 |


54 |

SimpleReddit

55 |

No distractions. No comments sections. No stylesheets. No JavaScript.

56 |

Just an HTML-only Reddit client to stop you entering an internet time vortex.

57 |

58 |
59 | r/ 60 | 61 |
62 |

63 |

Made by Ethan, source code on GitHub

64 |

Buy Me A Coffee (tip jar)

65 |
66 | `; 67 | return new Response(html, { 68 | headers: { 69 | "Content-Type": "text/html; charset=utf-8", 70 | "Cache-Control": "no-cache", 71 | "Content-Security-Policy": CSP, 72 | }, 73 | }); 74 | } 75 | 76 | async function subredditPage(request, url) { 77 | const subreddit = url.pathname.split("/")[2]; 78 | const { data } = await fetch( 79 | `https://www.reddit.com/r/${subreddit}.json` 80 | ).then((r) => r.json()); 81 | 82 | if (!data) return notFoundPage(); 83 | 84 | const name = data.children[0].data.subreddit_name_prefixed; 85 | // Redirect to nicely capitalised version, without any trailing bits 86 | if (url.pathname !== `/${name}`) { 87 | return Response.redirect(`${url.origin}/${name}`, 302); 88 | } 89 | const html = ` 90 | 91 | 92 | 93 | 94 | ${name} • SimpleReddit 95 | 96 | 97 | ← Homepage 98 |
99 |
100 | 101 | ${name} 102 | 103 |
104 | ${formatCount(data.children[0].data.subreddit_subscribers)} members 105 |

106 |
107 | ${data.children 108 | .filter(({ data }) => !data.title?.trim()?.endsWith("?")) 109 | .slice(0, ITEMS_LIMIT) 110 | .map( 111 | ({ data }) => ` 112 | 113 | ${ 114 | !data.is_self && !data.crosspost_parent_list?.[0]?.is_self 115 | ? `` 118 | : "" 119 | } 120 | ${getTag(data)} ${data.title} 121 | ${ 122 | !data.is_self && !data.crosspost_parent_list?.[0]?.is_self 123 | ? "" 124 | : "" 125 | } 126 | 127 |
128 | ${new Date(data.created_utc * 1000).toLocaleString([], { 129 | month: "short", 130 | weekday: "short", 131 | day: "numeric", 132 | hour: "numeric", 133 | minute: "numeric", 134 | timeZone: request.cf?.timezone, 135 | })} 136 | ${data.stickied ? "(pinned)" : ""} • 137 | ${data.ups} upvote${data.ups !== 1 ? "s" : ""} 138 | ${ 139 | data.crosspost_parent 140 | ? `
Crossposted from ${data.crosspost_parent_list?.[0]?.subreddit_name_prefixed}` 141 | : "" 142 | } 143 | ${ 144 | data.is_self || data.crosspost_parent_list?.[0]?.is_self 145 | ? ` 146 |
147 | Self text 148 | ${ 149 | ( 150 | data.selftext_html || 151 | data.crosspost_parent_list?.[0]?.selftext_html 152 | ) 153 | ?.replaceAll("<", "<") 154 | .replaceAll(">", ">") 155 | .replaceAll("&", "&") || "" 156 | } 157 |
158 | ` 159 | : "" 160 | } 161 |
` 162 | ) 163 | .join("")} 164 | Ok, stop reading reddit now and go for a walk :) 165 | `; 166 | return new Response(html, { 167 | headers: { 168 | "Content-Type": "text/html; charset=utf-8", 169 | "Cache-Control": "no-cache", 170 | "Content-Security-Policy": CSP, 171 | }, 172 | }); 173 | } 174 | 175 | function notFoundPage() { 176 | return new Response("Not found", { 177 | status: 404, 178 | headers: { 179 | "Content-Security-Policy": CSP, 180 | }, 181 | }); 182 | } 183 | 184 | function getTag(data) { 185 | if (data.is_self || data.crosspost_parent_list?.[0]?.is_self) return "📝"; 186 | if (data.is_video) return "📽"; 187 | if (["i.redd.it", "i.imgur.com"].includes(data.domain)) return "📸"; 188 | return "🔗"; 189 | // if (data.is_self) return "[self]" 190 | // if (data.is_video) return "[video]" 191 | // if (data.domain === "i.redd.it") return "[image]" 192 | // return "[link]" 193 | } 194 | 195 | function formatCount(count) { 196 | if (count >= 1000000) return Math.floor(count / 1000000) + "m"; 197 | if (count >= 1000) return Math.floor(count / 1000) + "k"; 198 | else return count.toString(); 199 | } 200 | -------------------------------------------------------------------------------- /wrangler.toml: -------------------------------------------------------------------------------- 1 | name = "simplereddit" 2 | type = "javascript" 3 | 4 | account_id = "48df40c1aa92584981c77c02cdf375ac" 5 | workers_dev = false 6 | route = "https://simplereddit.ethan.link/*" 7 | zone_id = "68a394814d6cd79d15f00063a6381c23" 8 | --------------------------------------------------------------------------------