Mastodon identicon adder

Apply eyeballs to URIs better.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Mastodon identicon adder
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Apply eyeballs to URIs better.
// @author       feonixrift
// @grant        none
// @require      https://cdn.jsdelivr.net/npm/[email protected]
// @match        *://hackers.town/*
// ==/UserScript==

// Techniques learned from https://openuserjs.org/scripts/nokeya/Direct_links_out/source
// Jquery dependency only exists because I can't figure out how to get the jdenticon function to run directly

(function() {
    'use strict';

    function identicate(link){
        if (link.hasAttribute('identicated')){
            return;
        }
        var identicon = document.createElement("svg")
        var holder = document.createElement("div")
        var components = link.href.split("/")
        identicon.setAttribute('data-jdenticon-value', components[2])
        holder.setAttribute('style', 'width: 48px; height: 48px; flex: none; float: inline-end')
        holder.appendChild(identicon)
        jdenticon.update(identicon)
        link.setAttribute('identicated', 'true')
        link.setAttribute('style', 'width: 96px;')
        link.appendChild(holder)
        link.appendChild(link.children[0])
        holder.innerHTML += " "
    }

    function alldenticate(){
        var links = document.getElementsByClassName('status__avatar');
        for (var i=0; i<links.length; ++i){
            identicate(links[i])
        }
    }

    document.addEventListener('DOMNodeInserted', function(event){
        if (!event || !event.target || !(event.target instanceof HTMLElement)){
            return;
        }
        var node = event.target;
        if (node instanceof HTMLAnchorElement){
            if (node.classList.contains('status__avatar')){
                identicate(node)
            }
        }
        var links = node.getElementsByClassName('status__avatar');
        for (var i=0; i<links.length; ++i){
            identicate(links[i]);
        }
    }, false);

    console.log('loading')
    alldenticate()
})();