diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2c67cf8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +Dist/* diff --git a/Build.py b/Build.py new file mode 100755 index 0000000..f832a6b --- /dev/null +++ b/Build.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +import os +from pathlib import Path + +os.makedirs('./Dist', exist_ok=True) + +with open('./Friendiiverse.html', 'r') as Base: + Base = Base.read() + +def FragReplace(Find, Replace, Pattern='*.*', Folder='./'): + global Base + for File in Path('./').rglob(Pattern): + with open(File, 'r') as Frag: + Frag = Replace[0] + Frag.read() + Replace[1] + for Prefix in ('', './'): + Base = Base.replace(Find[0] + Prefix + str(File) + Find[1], Frag) + +FragReplace((''), (''), '*.css') +FragReplace((''), (''), '*.js') + +with open('./Dist/Friendiiverse.html', 'w') as Build: + Build.write(Base) + diff --git a/Friendiiverse.html b/Friendiiverse.html index 2708729..b9c60a0 100644 --- a/Friendiiverse.html +++ b/Friendiiverse.html @@ -3,12 +3,7 @@ - - + -
+
LOGO Loading...
-
+
No Script!
-
-
- - + + - + })(); diff --git a/Main.js b/Main.js new file mode 100644 index 0000000..3f261b6 --- /dev/null +++ b/Main.js @@ -0,0 +1,136 @@ +NoscriptView.remove(); + +var CurrentTimeline = []; +var CurrentTimelineExp = 0; + +var FakeApi = {}; +FakeApi.F = {}; +FakeApi.My = {}; + +function LogDebug(Data, Status) { + if (Debug) { + for (var i=0; i + ${Item.created_at} + ${Item.friendica_author.url} + ${Item.friendica_html} +
`; + }); + }}); +}; +*/ + +function DisplayFriendicaTimeline(Timeline) { + ApiCall({Target: "Friendica", Method: Timeline, CallFine: function(Res){ + DataView.innerHTML = Res.responseText; + JSON.parse(DataView.innerHTML).forEach(function(Item){ + var Title = Item.friendica_title ? `

${Item.friendica_title}

` : ''; + TimelineView.innerHTML += `
+ ${Item.created_at} + ${Item.friendica_author.url} + ${Title} + ${Item.friendica_html} +
`; + }); + }}); +}; + +function FetchMastodon() { + return ApiCall({Target: "Mastodon", Method: "timelines/public", CallFine: function(Res){ + //console.log(JSON.parse(Res.responseText)[0]) + console.log([TransParsers.Mastodon.Status(JSON.parse(Res.responseText)[0])]) + //return [ + // TransParsers.Mastodon.Status(JSON.parse(Res.responseText)[0]) + //]; + CurrentTimeline = CurrentTimeline.concat([TransParsers.Mastodon.Status(JSON.parse(Res.responseText)[0])]); + CurrentTimelineExp -= 1; + }}); +}; + +function FillTimeline(Notes) { + console.log('notes', Notes) + Notes.forEach(function(Note){ + TimelineView.innerHTML += `
+ ${Note.Time} + ${Note.Author} + ${Note.Content} +
`; + }); +}; + +PlazasView.innerHTML = ` +
+

Featured

+ +
+
+

Categories

+ +
+`; + diff --git a/Style.css b/Style.css new file mode 100644 index 0000000..3db7e4f --- /dev/null +++ b/Style.css @@ -0,0 +1,13 @@ +img, video { + max-width: 100%; +} + +#DataView { + white-space: break-spaces; +} + +.PostView { + border: 4px solid purple; + margin: 12px; +} + diff --git a/Test.txt b/Test.txt new file mode 100644 index 0000000..9331434 --- /dev/null +++ b/Test.txt @@ -0,0 +1,33 @@ +function ApiCall(f) { + var Req = new XMLHttpRequest(); + Req.onloadend = function(){ f(this) }; + Req.open('GET', `https://mastodon.social/api/v1/timelines/public`, true); + Req.send(); +}; + +function Retry(Text, f) { + console.log(f) + if (Text) { + return Text; + } else { + setTimeout(f, 50, Text, f); + }; +}; + +function PrintRes(Res) { + var Text = Res.responseText; + setTimeout(Retry, 50, Text, Retry); + return Res.responseText; +}; + +/* +function PrintRes(Res) { + console.log(Res.responseText); + return Res.responseText; +}; +*/ + +function FetchContent() { + return ApiCall(PrintRes); +}; + diff --git a/Translations.js b/Translations.js new file mode 100644 index 0000000..784c129 --- /dev/null +++ b/Translations.js @@ -0,0 +1,50 @@ +var TransSchemas = { + Mastodon: { + Account: { + "__": "Author", + "url": "Url", + }, + Status: { + "__": "Note", + "account": {"__": "Account"}, + "content": "Content", + "created_at": "Time", + "url": "Url", + }, + }, +}; + +var TransParsers = { + Mastodon: { + Account(Data) { + return JsonTranslate(Data, TransSchemas.Mastodon.Author); + }, + Status(Data) { + return JsonTranslate(Data, TransSchemas.Mastodon.Status); + }, + }, +}; + +function JsonTranslate(Old, Schema) { + var New = {}; + Object.keys(Old).forEach(function(OldKey){ + var Content = Old[OldKey]; + var NewKey = (OldKey in Schema ? Schema[OldKey]: OldKey); + if (typeof(Content) == 'object' && Content !== null) { + if (Array.isArray(Content)) { + // Lists + //New[NewKey] = Content; + //Content.forEach(function()); + } else { + // Dicts + NewKey.__ ||= OldKey; + New[NewKey.__] = JsonTranslate(Content, NewKey); + }; + } else { + // Values + New[NewKey] = Content; + }; + }); + return New; +}; +