Skip to content

Instantly share code, notes, and snippets.

@tripleee
Forked from dzaima/reply_to_self.user.js
Last active May 25, 2022 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripleee/20e523a3a4d0b459172ac8a21c97e6ab to your computer and use it in GitHub Desktop.
Save tripleee/20e523a3a4d0b459172ac8a21c97e6ab to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Reply to self
// @namespace https://github.com/dzaima
// @version 0.1
// @description reply to self
// @author dzaima
// @match https://chat.stackexchange.com/*
// @match https://chat.stackoverflow.com/*
// @match https://chat.meta.stackexchange.com/*
// @match https://chat.meta.stackoverflow.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
setInterval(() => {
[...$(".message:not(.dParsed)")].map(c => {
c.classList.add("dParsed");
let mono = c.parentElement.parentElement;
if (mono.classList.contains("mine")) {
let meta = c.querySelector(".meta");
let l = $('<span class="meta"/>');
l.append($('<span class="newreply"/>').click(H).attr("title", "link my next chat message as a reply to this"));
$(meta).replaceWith(l);
}
if (mono.classList.contains("user-319249")) {
let rep = c.querySelector(".newreply");
$(rep).click(IRC);
}
})
}, 1000);
function IRC(e) {
let m = e.currentTarget.closest(".message");
let name = m.querySelector(".content").innerText.match("<([^>]+)>")[1]; // errors when it's not an IRC message. ¯\_(ツ)_/¯
let p = $("#input").focus().val().replace(/^:[0-9]+\s+([a-zA-Z_-]+:\s+)?/, "");
r(name+": "+p)
}
function H(e) {
let id = $(e.currentTarget.closest(".message")).messageId();
let p = $("#input").focus().val().replace(/^:[0-9]+\s+([a-zA-Z_-]+:\s+)?/, "");
r(":"+id+" "+p)
}
function r(e) {
return $("#input").val(e).trigger("change").focus()
}
let st = document.createElement('style');
st.type = 'text/css';
st.innerHTML = ".timestamp:hover+div.message .meta, div.message:hover .meta { display: inline-block !important; }";
document.head.appendChild(st);
})();
@tripleee
Copy link
Author

I forked this to add a couple of the StackExchange servers which were missing at the time, but the original has now been updated to include those, too. https://gist.github.com/dzaima/dd13554c462ab4fc02e4c69d3ebd492a?permalink_comment_id=3760626#gistcomment-3760626

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment