Spaces:
Configuration error
Configuration error
Upload 12 files
Browse files- Account.js +32 -0
- Attachment.js +55 -0
- Card.js +34 -0
- Host.js +13 -0
- HtmlDate.js +33 -0
- LICENSE +203 -0
- README.md +21 -10
- Status.js +146 -0
- index.css +45 -0
- index.html +113 -19
- index.js +132 -0
- server.js +205 -0
Account.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import Host from './Host.js'
|
| 2 |
+
import { a, em, img } from 'https://unpkg.com/ez-html-elements'
|
| 3 |
+
|
| 4 |
+
/** Create an account object from the JSON returned from the server. */
|
| 5 |
+
export default (account) => {
|
| 6 |
+
// Account PUBLIC:
|
| 7 |
+
return Object.freeze({
|
| 8 |
+
/** Is the given id the same as this account's id? */
|
| 9 |
+
sameId: (id) => id === account.id,
|
| 10 |
+
|
| 11 |
+
/** Generate HTML text */
|
| 12 |
+
html: () => {
|
| 13 |
+
const accountServer = account.url.match(/https:\/\/([^/]+)\//)[1]
|
| 14 |
+
|
| 15 |
+
return a(
|
| 16 |
+
{ href: `#accounts/${account.id}` },
|
| 17 |
+
img(['inline'], {
|
| 18 |
+
src: account.avatar,
|
| 19 |
+
width: 48,
|
| 20 |
+
height: 48,
|
| 21 |
+
alt: `@${account.username}`
|
| 22 |
+
}) +
|
| 23 |
+
Host(accountServer).faviconHtml() +
|
| 24 |
+
'@' +
|
| 25 |
+
account.username +
|
| 26 |
+
'@' +
|
| 27 |
+
accountServer,
|
| 28 |
+
em('(' + account.display_name + ')')
|
| 29 |
+
)
|
| 30 |
+
}
|
| 31 |
+
})
|
| 32 |
+
}
|
Attachment.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {
|
| 2 |
+
a,
|
| 3 |
+
details,
|
| 4 |
+
figure,
|
| 5 |
+
figcaption,
|
| 6 |
+
img,
|
| 7 |
+
summary
|
| 8 |
+
} from 'https://unpkg.com/ez-html-elements'
|
| 9 |
+
|
| 10 |
+
/** Create an attachment object from the JSON returned from the server. */
|
| 11 |
+
export default (attachment, isSensitive) => {
|
| 12 |
+
// Attachment PRIVATE:
|
| 13 |
+
/** Generate HTML for the media item */
|
| 14 |
+
function mediaHtml () {
|
| 15 |
+
if (!attachment.meta || !attachment.meta.small) {
|
| 16 |
+
return ''
|
| 17 |
+
}
|
| 18 |
+
const { width, height } = attachment.meta.small
|
| 19 |
+
switch (attachment.type) {
|
| 20 |
+
case 'image':
|
| 21 |
+
case 'video':
|
| 22 |
+
case 'gifv':
|
| 23 |
+
return figure(
|
| 24 |
+
a(
|
| 25 |
+
{ href: attachment.url },
|
| 26 |
+
img({
|
| 27 |
+
alt: attachment.description || 'attachment',
|
| 28 |
+
src: attachment.preview_url,
|
| 29 |
+
width,
|
| 30 |
+
height
|
| 31 |
+
})
|
| 32 |
+
) + figcaption(attachment.description)
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
default:
|
| 36 |
+
console.warn(`Unrecognized media attachment type "${attachment.type}"`)
|
| 37 |
+
return ''
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
// Attachment PUBLIC:
|
| 42 |
+
return Object.freeze({
|
| 43 |
+
/** Generate HTML text */
|
| 44 |
+
html: () => {
|
| 45 |
+
const media = mediaHtml()
|
| 46 |
+
if (media === '') {
|
| 47 |
+
return ''
|
| 48 |
+
}
|
| 49 |
+
if (!isSensitive) {
|
| 50 |
+
return media
|
| 51 |
+
}
|
| 52 |
+
return details(summary('⚠️🫣 ' + attachment.description), media)
|
| 53 |
+
}
|
| 54 |
+
})
|
| 55 |
+
}
|
Card.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { a, aside, img, p, strong } from 'https://unpkg.com/ez-html-elements'
|
| 2 |
+
|
| 3 |
+
/** Create a card object from the JSON returned from the server. */
|
| 4 |
+
export default (card) => {
|
| 5 |
+
// Card PRIVATE:
|
| 6 |
+
const caption =
|
| 7 |
+
a({ href: card.url }, strong(card.title)) +
|
| 8 |
+
(card.description ? p(card.description) : '')
|
| 9 |
+
|
| 10 |
+
// Card PUBLIC:
|
| 11 |
+
return Object.freeze({
|
| 12 |
+
/** Generate HTML text */
|
| 13 |
+
html: () => {
|
| 14 |
+
switch (card.type) {
|
| 15 |
+
case 'link':
|
| 16 |
+
case 'video':
|
| 17 |
+
return aside(
|
| 18 |
+
a(
|
| 19 |
+
{ href: card.url, alt: card.title },
|
| 20 |
+
img({
|
| 21 |
+
width: card.width,
|
| 22 |
+
height: card.height,
|
| 23 |
+
src: card.image,
|
| 24 |
+
alt: card.title
|
| 25 |
+
}),
|
| 26 |
+
caption
|
| 27 |
+
)
|
| 28 |
+
)
|
| 29 |
+
default:
|
| 30 |
+
return ''
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
})
|
| 34 |
+
}
|
Host.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { img } from 'https://unpkg.com/ez-html-elements'
|
| 2 |
+
|
| 3 |
+
export default (host) => {
|
| 4 |
+
return Object.freeze({
|
| 5 |
+
faviconHtml: () =>
|
| 6 |
+
img(['inline'], {
|
| 7 |
+
src: `https://${host}/favicon.ico`,
|
| 8 |
+
width: 48,
|
| 9 |
+
height: 48,
|
| 10 |
+
alt: host
|
| 11 |
+
})
|
| 12 |
+
})
|
| 13 |
+
}
|
HtmlDate.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { time } from 'https://unpkg.com/ez-html-elements'
|
| 2 |
+
|
| 3 |
+
/** Create a date object from a standard string representation */
|
| 4 |
+
export default (dateString) => {
|
| 5 |
+
// HtmlDate PRIVATE:
|
| 6 |
+
|
| 7 |
+
function dateView () {
|
| 8 |
+
const ms = Date.now() - Date.parse(dateString)
|
| 9 |
+
if (ms < 1500) {
|
| 10 |
+
return `${ms} ms`
|
| 11 |
+
}
|
| 12 |
+
const seconds = Math.round(ms / 1000)
|
| 13 |
+
if (seconds < 90) {
|
| 14 |
+
return `${seconds}s`
|
| 15 |
+
}
|
| 16 |
+
const minutes = Math.round(seconds / 60)
|
| 17 |
+
if (minutes < 90) {
|
| 18 |
+
return `${minutes}min`
|
| 19 |
+
}
|
| 20 |
+
const hours = Math.round(minutes / 60)
|
| 21 |
+
if (hours < 90) {
|
| 22 |
+
return `${hours}h`
|
| 23 |
+
}
|
| 24 |
+
const days = Math.round(hours / 24)
|
| 25 |
+
return `${days}d`
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
// HtmlDate PUBLIC:
|
| 29 |
+
return Object.freeze({
|
| 30 |
+
/** Generate HTML text */
|
| 31 |
+
html: () => time({ datetime: dateString }, dateView())
|
| 32 |
+
})
|
| 33 |
+
}
|
LICENSE
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Eclipse Public License - v 1.0
|
| 2 |
+
|
| 3 |
+
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
|
| 4 |
+
LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
|
| 5 |
+
CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
|
| 6 |
+
|
| 7 |
+
1. DEFINITIONS
|
| 8 |
+
|
| 9 |
+
"Contribution" means:
|
| 10 |
+
|
| 11 |
+
a) in the case of the initial Contributor, the initial code and documentation
|
| 12 |
+
distributed under this Agreement, and
|
| 13 |
+
b) in the case of each subsequent Contributor:
|
| 14 |
+
i) changes to the Program, and
|
| 15 |
+
ii) additions to the Program;
|
| 16 |
+
|
| 17 |
+
where such changes and/or additions to the Program originate from and are
|
| 18 |
+
distributed by that particular Contributor. A Contribution 'originates'
|
| 19 |
+
from a Contributor if it was added to the Program by such Contributor
|
| 20 |
+
itself or anyone acting on such Contributor's behalf. Contributions do not
|
| 21 |
+
include additions to the Program which: (i) are separate modules of
|
| 22 |
+
software distributed in conjunction with the Program under their own
|
| 23 |
+
license agreement, and (ii) are not derivative works of the Program.
|
| 24 |
+
|
| 25 |
+
"Contributor" means any person or entity that distributes the Program.
|
| 26 |
+
|
| 27 |
+
"Licensed Patents" mean patent claims licensable by a Contributor which are
|
| 28 |
+
necessarily infringed by the use or sale of its Contribution alone or when
|
| 29 |
+
combined with the Program.
|
| 30 |
+
|
| 31 |
+
"Program" means the Contributions distributed in accordance with this
|
| 32 |
+
Agreement.
|
| 33 |
+
|
| 34 |
+
"Recipient" means anyone who receives the Program under this Agreement,
|
| 35 |
+
including all Contributors.
|
| 36 |
+
|
| 37 |
+
2. GRANT OF RIGHTS
|
| 38 |
+
a) Subject to the terms of this Agreement, each Contributor hereby grants
|
| 39 |
+
Recipient a non-exclusive, worldwide, royalty-free copyright license to
|
| 40 |
+
reproduce, prepare derivative works of, publicly display, publicly
|
| 41 |
+
perform, distribute and sublicense the Contribution of such Contributor,
|
| 42 |
+
if any, and such derivative works, in source code and object code form.
|
| 43 |
+
b) Subject to the terms of this Agreement, each Contributor hereby grants
|
| 44 |
+
Recipient a non-exclusive, worldwide, royalty-free patent license under
|
| 45 |
+
Licensed Patents to make, use, sell, offer to sell, import and otherwise
|
| 46 |
+
transfer the Contribution of such Contributor, if any, in source code and
|
| 47 |
+
object code form. This patent license shall apply to the combination of
|
| 48 |
+
the Contribution and the Program if, at the time the Contribution is
|
| 49 |
+
added by the Contributor, such addition of the Contribution causes such
|
| 50 |
+
combination to be covered by the Licensed Patents. The patent license
|
| 51 |
+
shall not apply to any other combinations which include the Contribution.
|
| 52 |
+
No hardware per se is licensed hereunder.
|
| 53 |
+
c) Recipient understands that although each Contributor grants the licenses
|
| 54 |
+
to its Contributions set forth herein, no assurances are provided by any
|
| 55 |
+
Contributor that the Program does not infringe the patent or other
|
| 56 |
+
intellectual property rights of any other entity. Each Contributor
|
| 57 |
+
disclaims any liability to Recipient for claims brought by any other
|
| 58 |
+
entity based on infringement of intellectual property rights or
|
| 59 |
+
otherwise. As a condition to exercising the rights and licenses granted
|
| 60 |
+
hereunder, each Recipient hereby assumes sole responsibility to secure
|
| 61 |
+
any other intellectual property rights needed, if any. For example, if a
|
| 62 |
+
third party patent license is required to allow Recipient to distribute
|
| 63 |
+
the Program, it is Recipient's responsibility to acquire that license
|
| 64 |
+
before distributing the Program.
|
| 65 |
+
d) Each Contributor represents that to its knowledge it has sufficient
|
| 66 |
+
copyright rights in its Contribution, if any, to grant the copyright
|
| 67 |
+
license set forth in this Agreement.
|
| 68 |
+
|
| 69 |
+
3. REQUIREMENTS
|
| 70 |
+
|
| 71 |
+
A Contributor may choose to distribute the Program in object code form under
|
| 72 |
+
its own license agreement, provided that:
|
| 73 |
+
|
| 74 |
+
a) it complies with the terms and conditions of this Agreement; and
|
| 75 |
+
b) its license agreement:
|
| 76 |
+
i) effectively disclaims on behalf of all Contributors all warranties
|
| 77 |
+
and conditions, express and implied, including warranties or
|
| 78 |
+
conditions of title and non-infringement, and implied warranties or
|
| 79 |
+
conditions of merchantability and fitness for a particular purpose;
|
| 80 |
+
ii) effectively excludes on behalf of all Contributors all liability for
|
| 81 |
+
damages, including direct, indirect, special, incidental and
|
| 82 |
+
consequential damages, such as lost profits;
|
| 83 |
+
iii) states that any provisions which differ from this Agreement are
|
| 84 |
+
offered by that Contributor alone and not by any other party; and
|
| 85 |
+
iv) states that source code for the Program is available from such
|
| 86 |
+
Contributor, and informs licensees how to obtain it in a reasonable
|
| 87 |
+
manner on or through a medium customarily used for software exchange.
|
| 88 |
+
|
| 89 |
+
When the Program is made available in source code form:
|
| 90 |
+
|
| 91 |
+
a) it must be made available under this Agreement; and
|
| 92 |
+
b) a copy of this Agreement must be included with each copy of the Program.
|
| 93 |
+
Contributors may not remove or alter any copyright notices contained
|
| 94 |
+
within the Program.
|
| 95 |
+
|
| 96 |
+
Each Contributor must identify itself as the originator of its Contribution,
|
| 97 |
+
if
|
| 98 |
+
any, in a manner that reasonably allows subsequent Recipients to identify the
|
| 99 |
+
originator of the Contribution.
|
| 100 |
+
|
| 101 |
+
4. COMMERCIAL DISTRIBUTION
|
| 102 |
+
|
| 103 |
+
Commercial distributors of software may accept certain responsibilities with
|
| 104 |
+
respect to end users, business partners and the like. While this license is
|
| 105 |
+
intended to facilitate the commercial use of the Program, the Contributor who
|
| 106 |
+
includes the Program in a commercial product offering should do so in a manner
|
| 107 |
+
which does not create potential liability for other Contributors. Therefore,
|
| 108 |
+
if a Contributor includes the Program in a commercial product offering, such
|
| 109 |
+
Contributor ("Commercial Contributor") hereby agrees to defend and indemnify
|
| 110 |
+
every other Contributor ("Indemnified Contributor") against any losses,
|
| 111 |
+
damages and costs (collectively "Losses") arising from claims, lawsuits and
|
| 112 |
+
other legal actions brought by a third party against the Indemnified
|
| 113 |
+
Contributor to the extent caused by the acts or omissions of such Commercial
|
| 114 |
+
Contributor in connection with its distribution of the Program in a commercial
|
| 115 |
+
product offering. The obligations in this section do not apply to any claims
|
| 116 |
+
or Losses relating to any actual or alleged intellectual property
|
| 117 |
+
infringement. In order to qualify, an Indemnified Contributor must:
|
| 118 |
+
a) promptly notify the Commercial Contributor in writing of such claim, and
|
| 119 |
+
b) allow the Commercial Contributor to control, and cooperate with the
|
| 120 |
+
Commercial Contributor in, the defense and any related settlement
|
| 121 |
+
negotiations. The Indemnified Contributor may participate in any such claim at
|
| 122 |
+
its own expense.
|
| 123 |
+
|
| 124 |
+
For example, a Contributor might include the Program in a commercial product
|
| 125 |
+
offering, Product X. That Contributor is then a Commercial Contributor. If
|
| 126 |
+
that Commercial Contributor then makes performance claims, or offers
|
| 127 |
+
warranties related to Product X, those performance claims and warranties are
|
| 128 |
+
such Commercial Contributor's responsibility alone. Under this section, the
|
| 129 |
+
Commercial Contributor would have to defend claims against the other
|
| 130 |
+
Contributors related to those performance claims and warranties, and if a
|
| 131 |
+
court requires any other Contributor to pay any damages as a result, the
|
| 132 |
+
Commercial Contributor must pay those damages.
|
| 133 |
+
|
| 134 |
+
5. NO WARRANTY
|
| 135 |
+
|
| 136 |
+
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN
|
| 137 |
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
|
| 138 |
+
IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE,
|
| 139 |
+
NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each
|
| 140 |
+
Recipient is solely responsible for determining the appropriateness of using
|
| 141 |
+
and distributing the Program and assumes all risks associated with its
|
| 142 |
+
exercise of rights under this Agreement , including but not limited to the
|
| 143 |
+
risks and costs of program errors, compliance with applicable laws, damage to
|
| 144 |
+
or loss of data, programs or equipment, and unavailability or interruption of
|
| 145 |
+
operations.
|
| 146 |
+
|
| 147 |
+
6. DISCLAIMER OF LIABILITY
|
| 148 |
+
|
| 149 |
+
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
|
| 150 |
+
CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 151 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
|
| 152 |
+
LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
| 153 |
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
| 154 |
+
ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
|
| 155 |
+
EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY
|
| 156 |
+
OF SUCH DAMAGES.
|
| 157 |
+
|
| 158 |
+
7. GENERAL
|
| 159 |
+
|
| 160 |
+
If any provision of this Agreement is invalid or unenforceable under
|
| 161 |
+
applicable law, it shall not affect the validity or enforceability of the
|
| 162 |
+
remainder of the terms of this Agreement, and without further action by the
|
| 163 |
+
parties hereto, such provision shall be reformed to the minimum extent
|
| 164 |
+
necessary to make such provision valid and enforceable.
|
| 165 |
+
|
| 166 |
+
If Recipient institutes patent litigation against any entity (including a
|
| 167 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Program itself
|
| 168 |
+
(excluding combinations of the Program with other software or hardware)
|
| 169 |
+
infringes such Recipient's patent(s), then such Recipient's rights granted
|
| 170 |
+
under Section 2(b) shall terminate as of the date such litigation is filed.
|
| 171 |
+
|
| 172 |
+
All Recipient's rights under this Agreement shall terminate if it fails to
|
| 173 |
+
comply with any of the material terms or conditions of this Agreement and does
|
| 174 |
+
not cure such failure in a reasonable period of time after becoming aware of
|
| 175 |
+
such noncompliance. If all Recipient's rights under this Agreement terminate,
|
| 176 |
+
Recipient agrees to cease use and distribution of the Program as soon as
|
| 177 |
+
reasonably practicable. However, Recipient's obligations under this Agreement
|
| 178 |
+
and any licenses granted by Recipient relating to the Program shall continue
|
| 179 |
+
and survive.
|
| 180 |
+
|
| 181 |
+
Everyone is permitted to copy and distribute copies of this Agreement, but in
|
| 182 |
+
order to avoid inconsistency the Agreement is copyrighted and may only be
|
| 183 |
+
modified in the following manner. The Agreement Steward reserves the right to
|
| 184 |
+
publish new versions (including revisions) of this Agreement from time to
|
| 185 |
+
time. No one other than the Agreement Steward has the right to modify this
|
| 186 |
+
Agreement. The Eclipse Foundation is the initial Agreement Steward. The
|
| 187 |
+
Eclipse Foundation may assign the responsibility to serve as the Agreement
|
| 188 |
+
Steward to a suitable separate entity. Each new version of the Agreement will
|
| 189 |
+
be given a distinguishing version number. The Program (including
|
| 190 |
+
Contributions) may always be distributed subject to the version of the
|
| 191 |
+
Agreement under which it was received. In addition, after a new version of the
|
| 192 |
+
Agreement is published, Contributor may elect to distribute the Program
|
| 193 |
+
(including its Contributions) under the new version. Except as expressly
|
| 194 |
+
stated in Sections 2(a) and 2(b) above, Recipient receives no rights or
|
| 195 |
+
licenses to the intellectual property of any Contributor under this Agreement,
|
| 196 |
+
whether expressly, by implication, estoppel or otherwise. All rights in the
|
| 197 |
+
Program not expressly granted under this Agreement are reserved.
|
| 198 |
+
|
| 199 |
+
This Agreement is governed by the laws of the State of New York and the
|
| 200 |
+
intellectual property laws of the United States of America. No party to this
|
| 201 |
+
Agreement will bring a legal action under this Agreement more than one year
|
| 202 |
+
after the cause of action arose. Each party waives its rights to a jury trial in
|
| 203 |
+
any resulting litigation.
|
README.md
CHANGED
|
@@ -1,10 +1,21 @@
|
|
| 1 |
-
--
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Simpledon -- Simple Mastodon Web Client
|
| 2 |
+
|
| 3 |
+
Code is running [here][1] (Enter a Mastodon server name to start.)
|
| 4 |
+
|
| 5 |
+
Creating a Mastodon client with the simplest possible amount of code.
|
| 6 |
+
|
| 7 |
+
1. Just three files (HTML, CSS, and JavaScript)
|
| 8 |
+
2. Semantic HTML
|
| 9 |
+
3. Any dependencies loaded in remotely
|
| 10 |
+
|
| 11 |
+
## Legal
|
| 12 |
+
|
| 13 |
+
Copyright (c) 2023 Eamonn O'Brien-Strain All rights reserved. This
|
| 14 |
+
program and the accompanying materials are made available under the
|
| 15 |
+
terms of the Eclipse Public License v1.0 which accompanies this
|
| 16 |
+
distribution, and is available at
|
| 17 |
+
http://www.eclipse.org/legal/epl-v10.html
|
| 18 |
+
|
| 19 |
+
> This is a purely personal project, not a project of my employer.
|
| 20 |
+
|
| 21 |
+
[1]: https://allmastodon.com/simplodon
|
Status.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import server from './server.js'
|
| 2 |
+
import Account from './Account.js'
|
| 3 |
+
import Attachment from './Attachment.js'
|
| 4 |
+
import Card from './Card.js'
|
| 5 |
+
import Host from './Host.js'
|
| 6 |
+
import HtmlDate from './HtmlDate.js'
|
| 7 |
+
import {
|
| 8 |
+
details,
|
| 9 |
+
div,
|
| 10 |
+
input,
|
| 11 |
+
p,
|
| 12 |
+
summary
|
| 13 |
+
} from 'https://unpkg.com/ez-html-elements'
|
| 14 |
+
|
| 15 |
+
/** Creates a Status object from the JSON returned from the server. */
|
| 16 |
+
function Status (status) {
|
| 17 |
+
// Status PRIVATE:
|
| 18 |
+
const account = Account(status.account)
|
| 19 |
+
const createdAt = HtmlDate(status.created_at)
|
| 20 |
+
|
| 21 |
+
const attachmentListHtml = (as, isSensitive) =>
|
| 22 |
+
as.map((a) => Attachment(a, isSensitive).html()).join('')
|
| 23 |
+
|
| 24 |
+
function html () {
|
| 25 |
+
const mediaSection =
|
| 26 |
+
status.media_attachments && status.media_attachments.length > 0
|
| 27 |
+
? attachmentListHtml(status.media_attachments, status.sensitive)
|
| 28 |
+
: ''
|
| 29 |
+
const cardHtml = status.card ? Card(status.card).html() : ''
|
| 30 |
+
const contentSection = cardHtml + status.content
|
| 31 |
+
return status.spoiler_text
|
| 32 |
+
? details(summary(status.spoiler_text), contentSection + mediaSection)
|
| 33 |
+
: div(contentSection + mediaSection)
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
function filterStatus ($status) {
|
| 37 |
+
$status.querySelectorAll('a.hashtag').forEach((a) => {
|
| 38 |
+
a.href = a.href.replace(/^.*\/tags\/(.+)$/, '#tags/$1')
|
| 39 |
+
a.removeAttribute('target') // stay in current window
|
| 40 |
+
})
|
| 41 |
+
$status.querySelectorAll('a.u-url').forEach((a) => {
|
| 42 |
+
const parsed = a.href.match(/^https:\/\/(.+)\/@(.+)$/)
|
| 43 |
+
if (parsed) {
|
| 44 |
+
const [, mentionedServer, mentionedPerson] = parsed
|
| 45 |
+
a.innerHTML =
|
| 46 |
+
Host(mentionedServer).faviconHtml() +
|
| 47 |
+
'@' +
|
| 48 |
+
mentionedPerson +
|
| 49 |
+
'@' +
|
| 50 |
+
mentionedServer
|
| 51 |
+
}
|
| 52 |
+
})
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
async function fetchAndAddAfter ($summary) {
|
| 56 |
+
const inReplyTo = Status(await server.status(status.in_reply_to_id))
|
| 57 |
+
inReplyTo.addAfter($summary)
|
| 58 |
+
}
|
| 59 |
+
const favId = `fav-${status.id}`
|
| 60 |
+
const boostId = `boost-${status.id}`
|
| 61 |
+
const bookmarkId = `bookmark-${status.id}`
|
| 62 |
+
|
| 63 |
+
const favHtml = input(['fav'], {
|
| 64 |
+
id: favId,
|
| 65 |
+
type: 'checkbox',
|
| 66 |
+
checked: status.favourited
|
| 67 |
+
})
|
| 68 |
+
const boostHtml = input(['boost'], {
|
| 69 |
+
id: boostId,
|
| 70 |
+
type: 'checkbox',
|
| 71 |
+
checked: status.reblogged
|
| 72 |
+
})
|
| 73 |
+
const bookmarkHtml = input(['bookmark'], {
|
| 74 |
+
id: bookmarkId,
|
| 75 |
+
type: 'checkbox',
|
| 76 |
+
checked: status.bookmarked
|
| 77 |
+
})
|
| 78 |
+
const header = p(
|
| 79 |
+
account.html(),
|
| 80 |
+
createdAt.html(),
|
| 81 |
+
favHtml,
|
| 82 |
+
boostHtml,
|
| 83 |
+
bookmarkHtml
|
| 84 |
+
)
|
| 85 |
+
function nextTick (callback) {
|
| 86 |
+
setTimeout(callback, 0)
|
| 87 |
+
}
|
| 88 |
+
function addListeners () {
|
| 89 |
+
nextTick(() => {
|
| 90 |
+
const $fav = document.querySelector('#' + favId)
|
| 91 |
+
const $boost = document.querySelector('#' + boostId)
|
| 92 |
+
const $bookmark = document.querySelector('#' + bookmarkId)
|
| 93 |
+
$fav.addEventListener('change', () => {
|
| 94 |
+
server.fav(status.id, $fav.checked)
|
| 95 |
+
})
|
| 96 |
+
$boost.addEventListener('change', () => {
|
| 97 |
+
server.boost(status.id, $boost.checked)
|
| 98 |
+
})
|
| 99 |
+
$bookmark.addEventListener('change', () => {
|
| 100 |
+
server.bookmark(status.id, $bookmark.checked)
|
| 101 |
+
})
|
| 102 |
+
})
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
// Status PUBLIC:
|
| 106 |
+
return Object.freeze({
|
| 107 |
+
/** Insert into the given parent element the HTML text for this post and any preceding posts in the thread. */
|
| 108 |
+
thread: async ($parent) => {
|
| 109 |
+
if (status.reblog) {
|
| 110 |
+
$parent.insertAdjacentHTML('beforeend', header + '♻️')
|
| 111 |
+
addListeners()
|
| 112 |
+
const $subArticle = document.createElement('article')
|
| 113 |
+
Status(status.reblog).thread($subArticle)
|
| 114 |
+
$parent.append($subArticle)
|
| 115 |
+
return
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
$parent.insertAdjacentHTML('beforeend', header + html())
|
| 119 |
+
addListeners()
|
| 120 |
+
filterStatus($parent.lastElementChild)
|
| 121 |
+
if (status.in_reply_to_id) {
|
| 122 |
+
const $details = document.createElement('details')
|
| 123 |
+
const $summary = document.createElement('summary')
|
| 124 |
+
$summary.innerText = '🧵'
|
| 125 |
+
$details.append($summary)
|
| 126 |
+
$parent.insertAdjacentElement('afterbegin', $details)
|
| 127 |
+
fetchAndAddAfter($summary, status.in_reply_to_id) // no await, so happens asynchronously
|
| 128 |
+
}
|
| 129 |
+
},
|
| 130 |
+
|
| 131 |
+
/** Insert after the given sibling element the HTML for this post. */
|
| 132 |
+
addAfter: ($sibling) => {
|
| 133 |
+
$sibling.insertAdjacentHTML('afterend', html())
|
| 134 |
+
filterStatus($sibling.nextElementSibling)
|
| 135 |
+
if (!account.sameId(status.in_reply_to_account_id)) {
|
| 136 |
+
$sibling.insertAdjacentHTML('afterend', header)
|
| 137 |
+
addListeners()
|
| 138 |
+
}
|
| 139 |
+
if (status.in_reply_to_id) {
|
| 140 |
+
fetchAndAddAfter($sibling, status.in_reply_to_id) // no await, so happens asynchronously
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
})
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
export default Status
|
index.css
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.hidden,
|
| 2 |
+
.invisible {
|
| 3 |
+
display: none;
|
| 4 |
+
}
|
| 5 |
+
|
| 6 |
+
img.inline {
|
| 7 |
+
height: 1.5em;
|
| 8 |
+
width: 1.5em;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
.ellipsis::after {
|
| 12 |
+
content: "…";
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
aside > p {
|
| 16 |
+
overflow: hidden;
|
| 17 |
+
text-overflow: ellipsis;
|
| 18 |
+
display: -webkit-box;
|
| 19 |
+
-webkit-line-clamp: 5;
|
| 20 |
+
line-clamp: 5;
|
| 21 |
+
-webkit-box-orient: vertical;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
article {
|
| 25 |
+
clear: right;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
.fav::before {
|
| 29 |
+
content: "🤍"
|
| 30 |
+
}
|
| 31 |
+
.fav:checked::before {
|
| 32 |
+
content: "❤️"
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
.boost::before {
|
| 36 |
+
content: "♺"
|
| 37 |
+
}
|
| 38 |
+
.boost:checked::before {
|
| 39 |
+
content: "♻️"
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
.bookmark::before {
|
| 43 |
+
content: "🔖";
|
| 44 |
+
}
|
| 45 |
+
|
index.html
CHANGED
|
@@ -1,19 +1,113 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
|
| 4 |
+
<head>
|
| 5 |
+
<meta charset="UTF-8" />
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
+
<meta name="description" content="Mastodon Client">
|
| 8 |
+
<title>Simplodon</title>
|
| 9 |
+
<link id="$cssLink" rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css" />
|
| 10 |
+
<link href="index.css" rel="stylesheet" />
|
| 11 |
+
<script src="index.js" type="module"></script>
|
| 12 |
+
</head>
|
| 13 |
+
|
| 14 |
+
<body>
|
| 15 |
+
<header>
|
| 16 |
+
<nav>
|
| 17 |
+
<span id="$header">(no server)</span>
|
| 18 |
+
<a href="#settings">⚙️</a>
|
| 19 |
+
<a href="#public">🌐</a>
|
| 20 |
+
<a href="#public/local">🧑🏽🤝🧑🏽</a>
|
| 21 |
+
<a class="hidden" id="$home" href="#home">🏠</a>
|
| 22 |
+
<a class="hidden" id="$login" href="#">🔑</a>
|
| 23 |
+
</nav>
|
| 24 |
+
</header>
|
| 25 |
+
|
| 26 |
+
<main id="$timeline"></main>
|
| 27 |
+
<main id="$settings" class="hidden">
|
| 28 |
+
<section>
|
| 29 |
+
<label>🖧<input name="server" id="$server" /></label>
|
| 30 |
+
</section>
|
| 31 |
+
<section>
|
| 32 |
+
<form>
|
| 33 |
+
<select id="$cssSelect">
|
| 34 |
+
<option value="https://cdn.simplecss.org/simple.min.css">
|
| 35 |
+
Simple
|
| 36 |
+
</option>
|
| 37 |
+
<!--option value="https://unpkg.com/axist@latest/dist/axist.min.css">
|
| 38 |
+
axist
|
| 39 |
+
</option-->
|
| 40 |
+
<!--option value="https://unpkg.com/awsm.css/dist/awsm.min.css">
|
| 41 |
+
awsm.css
|
| 42 |
+
</option-->
|
| 43 |
+
<!--option
|
| 44 |
+
value="https://cdn.jsdelivr.net/gh/kimeiga/bahunya/dist/bahunya.min.css"
|
| 45 |
+
>
|
| 46 |
+
Bahunya
|
| 47 |
+
</option-->
|
| 48 |
+
<!--option value="https://unpkg.com/bamboo.css">Bamboo CSS</option-->
|
| 49 |
+
<!--option
|
| 50 |
+
value="https://cdn.jsdelivr.net/gh/longsien/BareCSS/css/bare.min.css"
|
| 51 |
+
>
|
| 52 |
+
BareCSS
|
| 53 |
+
</option-->
|
| 54 |
+
<option value="https://cdn.jsdelivr.net/gh/vladocar/Basic.css/css/basic.min.css">
|
| 55 |
+
Basic
|
| 56 |
+
</option>
|
| 57 |
+
<option value="https://cdn.jsdelivr.net/gh/waldyrious/downstyler/downstyler.css">
|
| 58 |
+
Downstyler
|
| 59 |
+
</option>
|
| 60 |
+
<option value="https://cdn.jsdelivr.net/npm/holiday.css@0.9.8">
|
| 61 |
+
holiday
|
| 62 |
+
</option>
|
| 63 |
+
<!--option value="https://cdn.jsdelivr.net/gh/davidrzs/latexcss/latex.css">LatexCSS</option-->
|
| 64 |
+
<!--option value="https://unpkg.com/marx-css/css/marx.min.css">Marx</option-->
|
| 65 |
+
<!--option value="https://cdn.jsdelivr.net/gh/wmeredith/MercuryCSS/dist/mercury.css">MercuryCSS</option-->
|
| 66 |
+
<!--option value="https://unpkg.com/mvp.css@1.12/mvp.css">MVP.css</option-->
|
| 67 |
+
<option value="https://cdn.jsdelivr.net/npm/@exampledev/new.css@1/new.min.css">
|
| 68 |
+
new
|
| 69 |
+
</option>
|
| 70 |
+
<!--option
|
| 71 |
+
value="https://cdn.jsdelivr.net/gh/davidpaulsson/no-class/releases/download/1.0.1/no-class.min.css"
|
| 72 |
+
>
|
| 73 |
+
MercuryCSS
|
| 74 |
+
</option-->
|
| 75 |
+
<!--option
|
| 76 |
+
value="https://unpkg.com/@picocss/pico@latest/css/pico.min.css"
|
| 77 |
+
>
|
| 78 |
+
Pico
|
| 79 |
+
</option-->
|
| 80 |
+
<!--option value="https://cdn.jsdelivr.net/gh/oxalorg/sakura/css/sakura.css">sakura</option-->
|
| 81 |
+
<option value="https://cdn.jsdelivr.net/npm/spcss">SPCSS</option>
|
| 82 |
+
<!--option value="https://unpkg.com/style.css">style.css</option-->
|
| 83 |
+
<!--option value="https://cdn.jsdelivr.net/gh/vasanthv/stylize.css/blob/master/stylize.min.css">Stylize.css</option-->
|
| 84 |
+
<option value="https://cdn.jsdelivr.net/gh/yegor256/tacit@gh-pages/tacit-css.min.css">
|
| 85 |
+
tacit
|
| 86 |
+
</option>
|
| 87 |
+
<option value="https://cdn.jsdelivr.net/gh/edwardtufte/tufte-css/tufte.min.css">
|
| 88 |
+
Tufte
|
| 89 |
+
</option>
|
| 90 |
+
<!--option value="https://www.w3.org/StyleSheets/Core/Modernist">W3C Core Styles</option-->
|
| 91 |
+
<option value="https://cdn.jsdelivr.net/npm/water.css@2/out/water.min.css">
|
| 92 |
+
water
|
| 93 |
+
</option>
|
| 94 |
+
<option value="https://writ.cmcenroe.me/1.0.4/writ.min.css">
|
| 95 |
+
Writ
|
| 96 |
+
</option>
|
| 97 |
+
<!--option value="https://cdn.jsdelivr.net/gh/metakirby5/yorha/dist/yorha.min.css">YoRHa</option-->
|
| 98 |
+
<option value="https://classless.de/classless.css">
|
| 99 |
+
Classless
|
| 100 |
+
</option>
|
| 101 |
+
<!--option value="https://cdn.jsdelivr.net/npm/bullframe.css">
|
| 102 |
+
bullframe
|
| 103 |
+
</option-->
|
| 104 |
+
</select>
|
| 105 |
+
</form>
|
| 106 |
+
</section>
|
| 107 |
+
</main>
|
| 108 |
+
<footer>
|
| 109 |
+
<p>Simplodon</p>
|
| 110 |
+
</footer>
|
| 111 |
+
</body>
|
| 112 |
+
|
| 113 |
+
</html>
|
index.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import server from './server.js'
|
| 2 |
+
import Status from './Status.js'
|
| 3 |
+
|
| 4 |
+
/* global alert $settings $cssSelect $timeline $login $header $server */
|
| 5 |
+
|
| 6 |
+
function settings (shown) {
|
| 7 |
+
if (shown) {
|
| 8 |
+
$timeline.classList.add('hidden')
|
| 9 |
+
$settings.classList.remove('hidden')
|
| 10 |
+
} else {
|
| 11 |
+
$timeline.classList.remove('hidden')
|
| 12 |
+
$settings.classList.add('hidden')
|
| 13 |
+
}
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
// const accountFromUsername = username => server.
|
| 17 |
+
|
| 18 |
+
async function showStatusList (header, statuses) {
|
| 19 |
+
if (statuses.error) {
|
| 20 |
+
alert(statuses.error)
|
| 21 |
+
return
|
| 22 |
+
}
|
| 23 |
+
$header.innerHTML = header
|
| 24 |
+
$timeline.replaceChildren()
|
| 25 |
+
for (const statusJson of statuses) {
|
| 26 |
+
const status = Status(statusJson)
|
| 27 |
+
const $article = document.createElement('article')
|
| 28 |
+
$timeline.append($article)
|
| 29 |
+
await status.thread($article)
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
async function showTimeline (header, querySuffix) {
|
| 34 |
+
await showStatusList(header, await server.timeline(querySuffix))
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
async function showAccountTimeline (accountId, querySuffix) {
|
| 38 |
+
await showStatusList(
|
| 39 |
+
'🧑',
|
| 40 |
+
await server.accountTimeline(accountId, querySuffix)
|
| 41 |
+
)
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
async function hasServer () {
|
| 45 |
+
server.setAuthorizeHref($login)
|
| 46 |
+
server.updateNavButtons()
|
| 47 |
+
settings(false)
|
| 48 |
+
if (!document.location.hash || document.location.hash === '#') {
|
| 49 |
+
document.location.hash = server.isLoggedIn() ? '#home' : '#public'
|
| 50 |
+
} else {
|
| 51 |
+
app()
|
| 52 |
+
}
|
| 53 |
+
settings(false)
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
async function noServer () {
|
| 57 |
+
server.updateNavButtons()
|
| 58 |
+
settings(true)
|
| 59 |
+
$header.innerHTML = ''
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
let appRunning = false
|
| 63 |
+
async function app () {
|
| 64 |
+
if (appRunning) {
|
| 65 |
+
return
|
| 66 |
+
}
|
| 67 |
+
appRunning = true
|
| 68 |
+
|
| 69 |
+
const codeMatch = document.location.search.match(/code=(.+)$/)
|
| 70 |
+
if (codeMatch) {
|
| 71 |
+
await server.login(codeMatch[1])
|
| 72 |
+
document.location.search = ''
|
| 73 |
+
document.location.hash = '#home'
|
| 74 |
+
appRunning = false
|
| 75 |
+
return
|
| 76 |
+
}
|
| 77 |
+
switch (document.location.hash) {
|
| 78 |
+
case '#home':
|
| 79 |
+
await showTimeline('🏠', 'home?limit=40')
|
| 80 |
+
break
|
| 81 |
+
case '#public':
|
| 82 |
+
await showTimeline('🌐', 'public?limit=40')
|
| 83 |
+
break
|
| 84 |
+
case '#public/local':
|
| 85 |
+
await showTimeline('🧑🏽🤝🧑🏽', 'public?limit=40&local=true')
|
| 86 |
+
break
|
| 87 |
+
case '#settings':
|
| 88 |
+
settings(true)
|
| 89 |
+
break
|
| 90 |
+
default: {
|
| 91 |
+
const hashtagMatch = document.location.hash.match(/#tags\/(.+)$/)
|
| 92 |
+
if (hashtagMatch) {
|
| 93 |
+
const hashtag = hashtagMatch[1]
|
| 94 |
+
await showTimeline(`#${hashtag}`, `tag/${hashtag}?limit=40`)
|
| 95 |
+
break
|
| 96 |
+
}
|
| 97 |
+
const accountMatch = document.location.hash.match(/#accounts\/(.+)$/)
|
| 98 |
+
if (accountMatch) {
|
| 99 |
+
const accountId = accountMatch[1]
|
| 100 |
+
await showAccountTimeline(accountId, 'limit=40')
|
| 101 |
+
break
|
| 102 |
+
}
|
| 103 |
+
console.warn(`Unexpected hash ${document.location.hash}`)
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
appRunning = false
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
window.onhashchange = app
|
| 110 |
+
|
| 111 |
+
if (server.hasHostname()) {
|
| 112 |
+
hasServer()
|
| 113 |
+
} else {
|
| 114 |
+
noServer()
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
$server.addEventListener('keyup', async (event) => {
|
| 118 |
+
if (event.key === 'Enter') {
|
| 119 |
+
const hostname = $server.value.trim()
|
| 120 |
+
if (hostname && hostname.match(/[a-z]+\.[a-z]+/)) {
|
| 121 |
+
server.setHostname(hostname)
|
| 122 |
+
await hasServer()
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
})
|
| 126 |
+
|
| 127 |
+
$cssSelect.addEventListener('change', (event) => {
|
| 128 |
+
server.setCssTheme()
|
| 129 |
+
settings(false)
|
| 130 |
+
})
|
| 131 |
+
|
| 132 |
+
app()
|
server.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* global $cssSelect $cssLink $header $login $home $server */
|
| 2 |
+
|
| 3 |
+
/** Singleton object encapsulating interactions with the Mastodon server. */
|
| 4 |
+
export default (() => {
|
| 5 |
+
// server PRIVATE:
|
| 6 |
+
const SERVER_KEY = 'server'
|
| 7 |
+
const ACCESS_TOKEN_KEY = 'access_token'
|
| 8 |
+
const TOKEN_TYPE_KEY = 'token_type'
|
| 9 |
+
const CSS_KEY = 'css_index'
|
| 10 |
+
const headers = {}
|
| 11 |
+
const origin = 'https://allmastodon.com/simplodon/'
|
| 12 |
+
const scope = 'read+write+follow'
|
| 13 |
+
/* eslint-disable camelcase -- because Mastodon API has camelcase JSON fields */
|
| 14 |
+
const client_id = 'S1X3r40DyEN6qX8RjxkoL4uRm6arRqEcoYK2NVrHSf8'
|
| 15 |
+
const client_secret = '6nnyTmudEH6l0iL2nP7ONDoeUUFkgll0N7r7iC3EEzg'
|
| 16 |
+
const redirect_uri = document.location.origin + document.location.pathname
|
| 17 |
+
/* eslint-enable */
|
| 18 |
+
|
| 19 |
+
const urlParams = (object) =>
|
| 20 |
+
Object.keys(object)
|
| 21 |
+
.map((k) => `${k}=${object[k]}`)
|
| 22 |
+
.join('&')
|
| 23 |
+
|
| 24 |
+
const token = async (code) =>
|
| 25 |
+
await (
|
| 26 |
+
await fetch(`https://${$server.value}/oauth/token`, {
|
| 27 |
+
method: 'POST',
|
| 28 |
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
| 29 |
+
body: urlParams({
|
| 30 |
+
grant_type: 'authorization_code',
|
| 31 |
+
code,
|
| 32 |
+
/* eslint-disable camelcase -- because Mastodon API has camelcase JSON fields */
|
| 33 |
+
client_id,
|
| 34 |
+
client_secret,
|
| 35 |
+
redirect_uri,
|
| 36 |
+
/* eslint-enable */
|
| 37 |
+
scope
|
| 38 |
+
})
|
| 39 |
+
})
|
| 40 |
+
).json()
|
| 41 |
+
|
| 42 |
+
function updateCssTheme () {
|
| 43 |
+
$cssLink.setAttribute('href', $cssSelect.value)
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
const isLoggedIn = () => !!accessToken
|
| 47 |
+
|
| 48 |
+
const updateNavButtons = () => {
|
| 49 |
+
if (isLoggedIn()) {
|
| 50 |
+
// When logged in show $home
|
| 51 |
+
$home.classList.remove('hidden')
|
| 52 |
+
$login.classList.add('hidden')
|
| 53 |
+
} else {
|
| 54 |
+
// When not logged in show $login
|
| 55 |
+
$home.classList.add('hidden')
|
| 56 |
+
$login.classList.remove('hidden')
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
function update () {
|
| 61 |
+
updateCssTheme()
|
| 62 |
+
|
| 63 |
+
$header.innerHTML = $server.value || '(no hostname)'
|
| 64 |
+
if (accessToken) {
|
| 65 |
+
headers.Authorization = `${tokenType} ${accessToken}`
|
| 66 |
+
} else {
|
| 67 |
+
delete headers.Authorization
|
| 68 |
+
}
|
| 69 |
+
updateNavButtons()
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
// server CONSTRUCTOR:
|
| 73 |
+
$server.value = window.localStorage.getItem(SERVER_KEY)
|
| 74 |
+
let accessToken = window.localStorage.getItem(ACCESS_TOKEN_KEY)
|
| 75 |
+
let tokenType = window.localStorage.getItem(TOKEN_TYPE_KEY)
|
| 76 |
+
$cssSelect.selectedIndex = window.localStorage.getItem(CSS_KEY) || 0
|
| 77 |
+
update()
|
| 78 |
+
|
| 79 |
+
// server PUBLIC:
|
| 80 |
+
return Object.freeze({
|
| 81 |
+
/** Has a hostname been defined (from user or from localStorage)? */
|
| 82 |
+
hasHostname: () => !!$server.value,
|
| 83 |
+
|
| 84 |
+
/** Set hostname as entered by user, and store in localStorage */
|
| 85 |
+
setHostname: (name) => {
|
| 86 |
+
$server.value = name
|
| 87 |
+
window.localStorage.setItem(SERVER_KEY, $server.value)
|
| 88 |
+
// TODO: update select to correct option (be careful of infinite loop)
|
| 89 |
+
update()
|
| 90 |
+
},
|
| 91 |
+
|
| 92 |
+
setCssTheme: () => {
|
| 93 |
+
window.localStorage.setItem(CSS_KEY, $cssSelect.selectedIndex)
|
| 94 |
+
updateCssTheme()
|
| 95 |
+
},
|
| 96 |
+
|
| 97 |
+
/** Have we gone through the OAuth flow? */
|
| 98 |
+
isLoggedIn,
|
| 99 |
+
|
| 100 |
+
/** Kick off the first step in the OAuth flow by sending the user to the server. */
|
| 101 |
+
setAuthorizeHref: ($anchor) => {
|
| 102 |
+
$anchor.href = `https://${$server.value}/oauth/authorize?${urlParams({
|
| 103 |
+
force_login: false,
|
| 104 |
+
scope,
|
| 105 |
+
/* eslint-disable camelcase -- because Mastodon API has camelcase JSON fields */
|
| 106 |
+
client_id,
|
| 107 |
+
redirect_uri,
|
| 108 |
+
/* eslint-enable */
|
| 109 |
+
origin,
|
| 110 |
+
response_type: 'code',
|
| 111 |
+
lang: navigator.language
|
| 112 |
+
})}`
|
| 113 |
+
},
|
| 114 |
+
|
| 115 |
+
/** Execute the second step of the OAuth flow after receiving the code from the server */
|
| 116 |
+
login: async (code) => {
|
| 117 |
+
({ access_token: accessToken, token_type: tokenType } = await token(
|
| 118 |
+
code
|
| 119 |
+
))
|
| 120 |
+
window.localStorage.setItem(ACCESS_TOKEN_KEY, accessToken)
|
| 121 |
+
window.localStorage.setItem(TOKEN_TYPE_KEY, tokenType)
|
| 122 |
+
|
| 123 |
+
update()
|
| 124 |
+
},
|
| 125 |
+
|
| 126 |
+
/** Logout and disconnect from the server (deleting everything from localstorage) */
|
| 127 |
+
removeHostname: () => {
|
| 128 |
+
$server.value = null
|
| 129 |
+
accessToken = null
|
| 130 |
+
window.localStorage.removeItem(SERVER_KEY)
|
| 131 |
+
window.localStorage.removeItem(ACCESS_TOKEN_KEY)
|
| 132 |
+
window.localStorage.removeItem(TOKEN_TYPE_KEY)
|
| 133 |
+
update()
|
| 134 |
+
},
|
| 135 |
+
|
| 136 |
+
/** Fetch data for a list of posts. */
|
| 137 |
+
timeline: async (querySuffix) =>
|
| 138 |
+
await (
|
| 139 |
+
await fetch(
|
| 140 |
+
`https://${$server.value}/api/v1/timelines/${querySuffix}`,
|
| 141 |
+
{
|
| 142 |
+
headers
|
| 143 |
+
}
|
| 144 |
+
)
|
| 145 |
+
).json(),
|
| 146 |
+
|
| 147 |
+
/** Fetch data for an account's list of posts. */
|
| 148 |
+
accountTimeline: async (accountId, querySuffix) =>
|
| 149 |
+
await (
|
| 150 |
+
await fetch(
|
| 151 |
+
`https://${$server.value}/api/v1/accounts/${accountId}/statuses?${querySuffix}`,
|
| 152 |
+
{
|
| 153 |
+
headers
|
| 154 |
+
}
|
| 155 |
+
)
|
| 156 |
+
).json(),
|
| 157 |
+
|
| 158 |
+
/** Fetch data for one post. */
|
| 159 |
+
status: async (id) =>
|
| 160 |
+
await (
|
| 161 |
+
await fetch(`https://${$server.value}/api/v1/statuses/${id}`, {
|
| 162 |
+
headers
|
| 163 |
+
})
|
| 164 |
+
).json(),
|
| 165 |
+
|
| 166 |
+
/** Lookup account information for a user. */
|
| 167 |
+
lookupAccount: async (username) =>
|
| 168 |
+
await (
|
| 169 |
+
await fetch(
|
| 170 |
+
`https://${$server.value}/api/v1/accounts/lookup?acct=${username}`,
|
| 171 |
+
{ headers }
|
| 172 |
+
)
|
| 173 |
+
).json(),
|
| 174 |
+
|
| 175 |
+
/** fav or unfav a status, sent asynchronously without waiting for the result */
|
| 176 |
+
fav: (statusId, isfaved) => {
|
| 177 |
+
const command = isfaved ? 'favourite' : 'unfavourite'
|
| 178 |
+
fetch(`https://${$server.value}/api/v1/statuses/${statusId}/${command}`, {
|
| 179 |
+
method: 'POST',
|
| 180 |
+
headers
|
| 181 |
+
})
|
| 182 |
+
},
|
| 183 |
+
|
| 184 |
+
/** boost or unboost a status, sent asynchronously without waiting for the result */
|
| 185 |
+
boost: (statusId, isboosted) => {
|
| 186 |
+
const command = isboosted ? 'reblog' : 'unreblog'
|
| 187 |
+
fetch(`https://${$server.value}/api/v1/statuses/${statusId}/${command}`, {
|
| 188 |
+
method: 'POST',
|
| 189 |
+
headers
|
| 190 |
+
})
|
| 191 |
+
},
|
| 192 |
+
|
| 193 |
+
/** bookmark or unbookmark a status, sent asynchronously without waiting for the result */
|
| 194 |
+
bookmark: (statusId, isBookmarked) => {
|
| 195 |
+
const command = isBookmarked ? 'bookmark' : 'unbookmark'
|
| 196 |
+
fetch(`https://${$server.value}/api/v1/statuses/${statusId}/${command}`, {
|
| 197 |
+
method: 'POST',
|
| 198 |
+
headers
|
| 199 |
+
})
|
| 200 |
+
},
|
| 201 |
+
|
| 202 |
+
/** View or hide nav buttons depending on whether hostname is set and user is logged in. */
|
| 203 |
+
updateNavButtons
|
| 204 |
+
})
|
| 205 |
+
})()
|