Kbin Kibby Avatars

Displays a Kibby icon as the default for people with no avatars set.

  1. // ==UserScript==
  2. // @name Kbin Kibby Avatars
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3.1
  5. // @description Displays a Kibby icon as the default for people with no avatars set.
  6. // @author minnieo
  7. // @match https://kbin.social/*
  8. // @icon https://minnie.untone.uk/kibpfps/kib1.png
  9. // @grant none
  10. // @run-at document-idle
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. const pref = 'https://minnie.untone.uk/kibpfps/kib'
  15. const max = 25;
  16.  
  17. const commentSection = document.querySelector('section.comments.entry-comments.comments-tree');
  18. const noAvatarElements = Array.from(commentSection.querySelectorAll('div.no-avatar'));
  19.  
  20. const filledUsers = {}
  21.  
  22. noAvatarElements.forEach((defaultAvatar) => {
  23. let assignedAvatar;
  24. const username = defaultAvatar.parentElement.href.split('/')[4]
  25. if (filledUsers[username]) {
  26. assignedAvatar = filledUsers[username];
  27. } else {
  28. const randomIndex = Math.floor(Math.random() * max) + 1;
  29. assignedAvatar = randomIndex
  30. filledUsers[username] = assignedAvatar;
  31.  
  32. }
  33. const kibbyAvatar = document.createElement('img');
  34. kibbyAvatar.alt = 'Default avatar';
  35. kibbyAvatar.src = pref + assignedAvatar + '.png';
  36. kibbyAvatar.style.cssText = `
  37. max-width: 40px;
  38. max-height: 40px;
  39. `;
  40. defaultAvatar.parentNode.replaceChild(kibbyAvatar, defaultAvatar);
  41. });