Last active
October 13, 2016 03:52
-
-
Save ohAitch/9675344 to your computer and use it in GitHub Desktop.
Rudimentary urbit chat tagging, notifications.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @include http://chat.urbit.org/ | |
// ==/UserScript== | |
$.getScript("https://cdn.rawgit.com/boronine/husl/v2.0.0/husl.min.js"); | |
colorMap = {}; memo={}; $('.hl').contents().unwrap(); | |
getColor = function (s) { | |
var hash = s.split("").reduce(function (a, b) { | |
a = ((a << 5) - a) + b.charCodeAt(0); | |
return a & a | |
}, 0); | |
return $.husl.toHex( | |
hash % 360, | |
85 - 10*Math.log(s.length) + (hash >> 8) % 30, //TODO: tweak/UI | |
75 + (hash >> 16) % 15) | |
}; | |
highlightNames = function () { | |
$('#body, #membership').contents().each(function (s) { | |
if (this.nodeType != 3|| this.textContent in memo) return; | |
rep = this.textContent.replace(/~([a-z]{3}|-)+\b/g, function (s) { | |
if (!(s in colorMap)) { | |
colorMap[s] = getColor(s); | |
} | |
return '<span class="hl" style="background-color: ' + colorMap[s] + '">' + s + '</span>' | |
}) | |
if(this.textContent == rep) memo[rep]=true; | |
else $(this).replaceWith(rep); | |
}); | |
}; | |
setInterval(highlightNames,400) //this would ideally hook the actual dom update |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @include http://chat.urbit.org/ | |
// ==/UserScript== | |
notify = function(a){new Notification(a), {icon:"http://urbit.org/favicon.png"}}; //TODO: Sounds | |
//Notification.requestPermissions() must be run manually once beforehand, 'in response to a user event' e.g. $(document).one('click',…) | |
bod = $('#body')[0].innerText; | |
check = function(){ | |
cur = $('#body')[0].innerText; | |
added = cur.slice(bod.length); | |
bod = cur; | |
if(added) notify(added); | |
} | |
setInterval(check, 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment