// ==UserScript== // @name @-posting // @version 0.5.0.0 // @namespace atposting // @license WTFPL // @include *://boards.4chan.org/* // @run-at document-end // @grant none // @description Link to posts in the same 4chan thread with "@". // @downloadURL none // ==/UserScript== // This keeps the events. var replaceHTML = function(node, innerHTML) { while (node.firstChild) { node.removeChild(node.firstChild); }; var replacementContent = document.createElement('span'); replacementContent.innerHTML = innerHTML; node.appendChild(replacementContent); } var twitterify = function(targets) { Array.prototype.forEach.call(targets, function(target) { replaceHTML(target, target.innerHTML.replace( /@([0-9]+)/, '@$1' ).replace( /Dear ([0-9]+)/, 'Dear $1' )); }); }; var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { twitterify(mutation.addedNodes); }); }); observer.observe(document.querySelector('.board .thread'), { attributes: true, childList: true }); twitterify(document.querySelectorAll('.postMessage'));