// ==UserScript== // @name KBin Redirect // @namespace http://herzberd.dev/ // @version 0.1 // @description redirects Lemmy shortlinks to the appropriate page on KBin // @author @herzberd@kbin.social https://github.com/herzberd https://herzberd.dev/ // @match https://kbin.social/* // @icon https://www.google.com/s2/favicons?sz=64&domain=kbin.social // @grant none // @license CC0 1.0 Universal // @downloadURL none // ==/UserScript== 'use strict'; const pattern = /!([A-Za-z0-9_]+)@([A-Za-z0-9.-]+)\b/g var elements = document.getElementsByTagName('a') for (var i = 0; i < elements.length; i++) { const matches = [...elements[i].innerText.matchAll(pattern)] if (matches.length > 0) { matches.forEach((match) => { const topic = match[1] const domain = match[2] elements[i].href = '/m/' + topic + '@' + domain }) } }