Last active
October 18, 2018 14:40
-
-
Save defufna/2e4bebbd953a10d46df05f04fefcfada to your computer and use it in GitHub Desktop.
This file contains hidden or 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== | |
// @name Proslji | |
// @version 1 | |
// @grant none | |
// @include https://*.slack.com/* | |
// ==/UserScript== | |
var fixit = {"proslji" : "prošli", | |
"prosljeg":"prošlog", | |
"prosljem":"prošlom", | |
"prosljim":"prošlim", | |
"proslje":"prošle", | |
"proslju":"prošlu"}; | |
var keys = Object.keys(fixit); | |
for(var i = 0; i < keys.length; i++){ | |
var replacement = fixit[keys[i]]; | |
fixit[keys[i]] = [new RegExp(keys[i], "ig"), replacement]; | |
} | |
var chatBox = document.getElementById("col_messages"); | |
var re = new RegExp("\\b(" + keys.join("|") + ")\\b", "ig"); | |
var callback = function(mutationsList, observer) { | |
for(var mutation of mutationsList) { | |
for(var node of mutation.addedNodes){ | |
var messages = node.querySelectorAll("span.c-message__body"); | |
for(var message of messages){ | |
var m = message.textContent.match(re); | |
if(m){ | |
for(var i = 0; i < m.length; i++){ | |
var pair = fixit[m[i].toLowerCase()] | |
var r = pair[0]; | |
message.textContent = message.textContent.replace(r, pair[1]); | |
} | |
} | |
} | |
} | |
} | |
} | |
var config = { attributes: false, childList: true, subtree: true }; | |
var observer = new MutationObserver(callback); | |
observer.observe(chatBox, config); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment