Mastodon identicon adder

Apply eyeballs to URIs better.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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()
})();