Skip to content

Instantly share code, notes, and snippets.

@ConorOBrien-Foxx
Last active March 16, 2016 01:45
Show Gist options
  • Save ConorOBrien-Foxx/f702b4554d964a58110e to your computer and use it in GitHub Desktop.
Save ConorOBrien-Foxx/f702b4554d964a58110e to your computer and use it in GitHub Desktop.
Caret Patthfinder
// ==UserScript==
// @name Caret Pathfinder
// @namespace ^
// @version 1
// @description ^^^
// @author Conor O'Brien
// @match *://chat.stackexchange.com/*
// @grant none
// ==/UserScript==
(function(){
var elements = {}, messages;
function findCarrotMessage(){
messages = Array.prototype.slice.call(document.querySelectorAll("[id^='message-']"));
messages.forEach(function(e){
if(!elements[e.id] && e.className==="message"){
elements[e.id] = true;
e.addEventListener("click", function(s){
// count the number of ^'s
var num = this.textContent.match(/\^+/g), self = this;
if(num){
var maxHash = -1;
num.forEach(function(k){
var destinationMessage = messages[Array.from(messages).indexOf(self)-k.length];
destinationMessage.style.background = "yellow";
setTimeout(function(e){e.style.background = "";}, 3500, destinationMessage);
maxHash = Math.max(destinationMessage.id.slice(destinationMessage.id.indexOf("-")+1), maxHash);
elements[self.id] = false;
});
window.location.hash = "#message-" + maxHash;
}
this.removeEventListener("click", arguments.callee, false);
}, false);
}
});
}
setInterval(findCarrotMessage,50);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment