known_instances+misskey: actually record mk instances when logged into

This commit is contained in:
codl 2021-12-09 17:45:45 +01:00
parent e5971e3848
commit f7f2276cec
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
1 changed files with 7 additions and 5 deletions

View File

@ -194,10 +194,10 @@ import {known_load, known_save} from './known_instances.js'
}) })
} }
function bump_instance(instance_name){ function bump_instance(service, instance_name){
let known_instances = known_load(); let known_instances = known_load();
let found = false; let found = false;
for(let instance of known_instances){ for(let instance of known_instances[service]){
if(instance['instance'] == instance_name){ if(instance['instance'] == instance_name){
instance.hits ++; instance.hits ++;
found = true; found = true;
@ -206,15 +206,17 @@ import {known_load, known_save} from './known_instances.js'
} }
if(!found){ if(!found){
let instance = {"instance": instance_name, "hits": 1}; let instance = {"instance": instance_name, "hits": 1};
known_instances.push(instance); known_instances[service].push(instance);
} }
known_save(known_instances); known_save(known_instances);
} }
if(viewer_from_dom['service'] == 'mastodon' && location.hash == '#bump_instance'){ if(location.hash == '#bump_instance' && (
bump_instance(viewer_from_dom['id'].split('@')[1]) viewer_from_dom['service'] == 'mastodon' || viewer_from_dom['service'] == 'misskey'
)){
bump_instance(viewer_from_dom['service'], viewer_from_dom['id'].split('@')[1])
let url = new URL(location.href) let url = new URL(location.href)
url.hash = ''; url.hash = '';
history.replaceState('', '', url); history.replaceState('', '', url);