From 83995ab0b8332a2d4823cac4fe3e47f676845e15 Mon Sep 17 00:00:00 2001 From: Andreas Grasser Date: Sat, 19 Nov 2022 16:56:09 +0100 Subject: [PATCH] Initial Commit --- README.md | 2 + create-circle.js | 141 +++++++++++++++++++++++++++++++++++++++++++++++ index.html | 18 ++++++ 3 files changed, 161 insertions(+) create mode 100644 create-circle.js create mode 100644 index.html diff --git a/README.md b/README.md index c35f97b..8149e26 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # Mastodon-Circles Producing a visual representation of Mastodon interactions with JS + +README follows... \ No newline at end of file diff --git a/create-circle.js b/create-circle.js new file mode 100644 index 0000000..0e14c2f --- /dev/null +++ b/create-circle.js @@ -0,0 +1,141 @@ +/* +Dies ist eine erste Implementierung, da ist noch vieeeel zu tun :) +*/ + +let userInfo; +let connection_list = {}; + +// The main function called by the button-click +function circle_main() { + // Get handle from Textfield + let mastodon_handle = document.getElementById("txt_mastodon_handle").value; + userInfo = formatedUserHandle(mastodon_handle); + getStatuses(); + setTimeout(showConnections,3000); +} + +// Format the Mastodon Handle to an array: [username, userID, instance.tld] +function formatedUserHandle(mastodon_handle) { + // Remove leading @ + if (mastodon_handle.charAt(0) === '@') mastodon_handle = mastodon_handle.substr(1); + // Split handle into name and + mastodon_handle = mastodon_handle.split("@"); + // Return the array + return [mastodon_handle[0], getIdFromName(mastodon_handle[0], mastodon_handle[1]), mastodon_handle[1]]; +} + +// Get the user ID from the handle +function getIdFromName(name, server) { + // https://mieke.club/api/v1/accounts/lookup?acct=HeilandSanremo + var xmlHttp = new XMLHttpRequest(); + let url = "https://"+server+"/api/v1/accounts/lookup?acct="+name; + xmlHttp.open( "GET", url, false ); // false for synchronous request + xmlHttp.send( null ); + return JSON.parse(xmlHttp.responseText)["id"]; +} + +// Get a JSON String with all the posted statuses from the account and call processStatuses() +function getStatuses() { + // Build the URL + let url = "https://"+userInfo[2]+"/api/v1/accounts/"+userInfo[1]+"/statuses"; + // Do the async http request and call processStatuses() + httpRequest(url, processStatuses); +} + +// Process the JSON String into an array +function processStatuses(statuses) { + jsonStat = JSON.parse(statuses); + + let request_limit = Math.min(30, jsonStat.length); + + console.log(request_limit) + + for (var i=0; i0), (jsonStat[i]["reblogs_count"]>0)); + //} + } +} + +function evaluateStatus(id, faved, rebloged) { + // Build the URL + let url1 = "https://"+userInfo[2]+"/api/v1/statuses/"+id+"/reblogged_by"; + // Do the async http request + if (rebloged) httpRequest(url1, addRepostConnections, 3); + + // Build the URL + let url2 = "https://"+userInfo[2]+"/api/v1/statuses/"+id+"/favourited_by"; + // Do the async http request + if (faved) httpRequest(url2, addRepostConnections, 1); +} + +function addRepostConnections(jsonString, plus) { + let jsonArray = JSON.parse(jsonString); + + for (var i=0; i { return [key, connection_list[key]] }); + + items.sort( + (first, second) => { return second[1]["conStrength"] - first[1]["conStrength"] } + ); + + for (var i=0; i"+usr["name"]+"\t"+usr["acct"]; + document.getElementById("outDiv").appendChild(usrElement); +} + + +// Function for the http request +function httpRequest(url, callback, callbackVal=null) +{ + var xmlHttp = new XMLHttpRequest(); + xmlHttp.onreadystatechange = function() { + if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { + callback(xmlHttp.responseText, callbackVal); + } else if (xmlHttp.readyState == 4 && xmlHttp.status == 404) + callback("[]", callbackVal); + } + xmlHttp.open("GET", url, true); + xmlHttp.send(null); +} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..875e5d8 --- /dev/null +++ b/index.html @@ -0,0 +1,18 @@ + + + + +Mastodon Circle Creator + + + + + + + + +


+
+ + \ No newline at end of file