Kurzes Zwischenspeichern vor async

This commit is contained in:
Andreas Grasser 2022-11-19 17:53:53 +01:00
parent 83995ab0b8
commit 7199ce91b8
3 changed files with 55 additions and 17 deletions

View file

@ -7,6 +7,8 @@ let connection_list = {};
// The main function called by the button-click // The main function called by the button-click
function circle_main() { function circle_main() {
// Make Button invisible to prevent clicking
document.getElementById("btn_create").style.display = "none";
// Get handle from Textfield // Get handle from Textfield
let mastodon_handle = document.getElementById("txt_mastodon_handle").value; let mastodon_handle = document.getElementById("txt_mastodon_handle").value;
userInfo = formatedUserHandle(mastodon_handle); userInfo = formatedUserHandle(mastodon_handle);
@ -46,30 +48,46 @@ function getStatuses() {
function processStatuses(statuses) { function processStatuses(statuses) {
jsonStat = JSON.parse(statuses); jsonStat = JSON.parse(statuses);
let request_limit = Math.min(30, jsonStat.length); let request_limit = 30;
console.log(request_limit) for (var i=0; i<jsonStat.length; i++) {
if (!jsonStat[i]["reblog"]) {
for (var i=0; i<request_limit; i++) {
//if (jsonStat[i]["reblog"] != null) {
evaluateStatus(jsonStat[i]["id"], (jsonStat[i]["favourites_count"]>0), (jsonStat[i]["reblogs_count"]>0)); evaluateStatus(jsonStat[i]["id"], (jsonStat[i]["favourites_count"]>0), (jsonStat[i]["reblogs_count"]>0));
//} request_limit--;
if (request_limit<0) break;
}
} }
} }
// Get all Reblogs and Favs for a status update
function evaluateStatus(id, faved, rebloged) { function evaluateStatus(id, faved, rebloged) {
// Build the URL // Build the URL
let url1 = "https://"+userInfo[2]+"/api/v1/statuses/"+id+"/reblogged_by"; let url1 = "https://"+userInfo[2]+"/api/v1/statuses/"+id+"/reblogged_by";
// Do the async http request // Do the async http request
if (rebloged) httpRequest(url1, addRepostConnections, 3); if (rebloged) httpRequest(url1, evalStatusInteractions, 1.3);
// Build the URL // Build the URL
let url2 = "https://"+userInfo[2]+"/api/v1/statuses/"+id+"/favourited_by"; let url2 = "https://"+userInfo[2]+"/api/v1/statuses/"+id+"/context";
// Do the async http request // Do the async http request
if (faved) httpRequest(url2, addRepostConnections, 1); if (faved) httpRequest(url2, evalReplies, 1.1);
// Build the URL
let url3 = "https://"+userInfo[2]+"/api/v1/statuses/"+id+"/favourited_by";
// Do the async http request
if (faved) httpRequest(url3, evalStatusInteractions, 1.0);
} }
function addRepostConnections(jsonString, plus) { // Evaluate the direct replies to tweets (no trees yet :( )
function evalReplies(jsonString, plus) {
let jsonArray = JSON.parse(jsonString)["descendants"];
for (var i=0; i<jsonArray.length; i++) {
incConnectionValue(jsonArray[i]["account"], plus);
}
}
// Evaluate the Favs and Reposts
function evalStatusInteractions(jsonString, plus) {
let jsonArray = JSON.parse(jsonString); let jsonArray = JSON.parse(jsonString);
for (var i=0; i<jsonArray.length; i++) { for (var i=0; i<jsonArray.length; i++) {
@ -105,23 +123,27 @@ function addNewConnection(jsonArray) {
function showConnections() { function showConnections() {
// Remove own User from Dict
if (userInfo[1] in connection_list) delete connection_list[userInfo[1]];
// Sort dict into Array items
var items = Object.keys(connection_list).map( var items = Object.keys(connection_list).map(
(key) => { return [key, connection_list[key]] }); (key) => { return [key, connection_list[key]] });
items.sort( items.sort(
(first, second) => { return second[1]["conStrength"] - first[1]["conStrength"] } (first, second) => { return second[1]["conStrength"] - first[1]["conStrength"] }
); );
// Render the Objects
for (var i=0; i<items.length; i++) { for (var i=0; i<items.length; i++) {
//createUserObj(items[i][1]) //createUserObj(items[i][1])
if (!items[i][1]["bot"]) createUserObj(items[i][1]); if (!items[i][1]["bot"]) createUserObj(items[i][1]);
} }
document.getElementById("btn_create").style.display = "inline";
} }
function createUserObj(usr) { function createUserObj(usr) {
console.log(usr)
let usrElement = document.createElement("div"); let usrElement = document.createElement("div");
usrElement.innerHTML = "<img src=\""+usr["pic"]+"\" width=\"20px\"><b>"+usr["name"]+"</b>\t"+usr["acct"]; usrElement.innerHTML = "<img src=\""+usr["pic"]+"\" width=\"20px\">\t\t<b>"+usr["name"]+"</b>\t"+usr["acct"];
document.getElementById("outDiv").appendChild(usrElement); document.getElementById("outDiv").appendChild(usrElement);
} }

View file

@ -4,14 +4,16 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Mastodon Circle Creator</title> <title>Mastodon Circle Creator</title>
<meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href=""> <link rel="stylesheet" href="style.css">
<style> <style>
</style> </style>
<script src=""></script> <script src=""></script>
<body> <body>
<script src="create-circle.js"></script> <script src="create-circle.js"></script>
<input id="txt_mastodon_handle" type="text"> <h1>Mastodon Circle Creator (die unrunde Version)</h1>
<button onClick="circle_main()">Circle Erstellen</button> <!-- Logo? -->
<input id="txt_mastodon_handle" type="text" placeholder="@sonnenbrandi@mieke.club" style="width: 300px;">
<button id="btn_create" onClick="circle_main()">Circle Erstellen</button>
<br><br><br> <br><br><br>
<div id="outDiv"></div> <div id="outDiv"></div>
</body> </body>

14
style.css Normal file
View file

@ -0,0 +1,14 @@
body {
background-color: #191b22;
color: #d9e1e8;
font-size: 20px;
line-height: 200%;
padding-left: 10%;
padding-right: 10%;
padding-top: 75px;
}
input {
}