Skip to content

Instantly share code, notes, and snippets.

@Radvylf
Created October 28, 2021 13:41
Show Gist options
  • Save Radvylf/873b11a7cc8546d525e3713f1eab3589 to your computer and use it in GitHub Desktop.
Save Radvylf/873b11a7cc8546d525e3713f1eab3589 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Self Reply
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Adds button to reply to self
// @author Redwolf Programs (Ryan Tosh)
// @match https://chat.stackexchange.com/rooms/*
// @match https://chat.stackoverflow.com/rooms/*
// @match https://chat.meta.stackexchange.com/rooms/*
// @grant none
// ==/UserScript==
(() => {
var style = document.createElement("style");
document.head.appendChild(style);
style.sheet.insertRule("html #chat-body .monologue.mine:hover .message .meta { display: inline-block; }");
style.sheet.insertRule("html #chat-body .monologue .meta { background-color: inherit; }");
style.sheet.insertRule(".monologue .message { background-color: inherit; }");
style.sheet.insertRule("html #chat-body .monologue.mine .newreply { filter: grayscale(100%) contrast(0%) brightness(0%); opacity: 20%; }");
var observer = new MutationObserver((records) => {
var span;
var data = records.filter(r => r.type == "childList" && r.target.parentNode).reduce((d, r) => [...d, ...[...r.target.querySelectorAll("span.meta")].filter(t => !d.find(i => i == t))], []);
for (var i = 0; i < data.length; i++) {
if ([...data[i].childNodes].some(n => n.className == "newreply"))
continue;
span = document.createElement("span");
span.className = "newreply";
span.title = "link my next chat message as a reply to this";
span.onclick = ((span) => () => {
var input = document.getElementById("input");
input.focus();
input.value = ":" + span.parentNode.parentNode.id.split("-")[1] + " " + input.value.replace(/^:([0-9]+)\s+/, "");
})(span);
while (data[i].firstChild)
data[i].removeChild(data[i].firstChild);
data[i].appendChild(span);
}
});
observer.observe(document.getElementById("chat"), {attributes: false, childList: true, subtree: true});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment