Skip to content

Instantly share code, notes, and snippets.

@prokopiff
Created April 30, 2021 11:47
Show Gist options
  • Save prokopiff/383321305781252f444ed411e627d93c to your computer and use it in GitHub Desktop.
Save prokopiff/383321305781252f444ed411e627d93c to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Linkedin Name Highlight
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.linkedin.com/*
// @icon https://www.google.com/s2/favicons?domain=linkedin.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
var transliteration = function (word) {
var rules = [
{'pattern': 'а', 'replace': 'a'},
{'pattern': 'б', 'replace': 'b'},
{'pattern': 'в', 'replace': 'v'},
{'pattern': 'зг', 'replace': 'zgh'},
{'pattern': 'Зг', 'replace': 'Zgh'},
{'pattern': 'г', 'replace': 'h'},
{'pattern': 'ґ', 'replace': 'g'},
{'pattern': 'д', 'replace': 'd'},
{'pattern': 'е', 'replace': 'e'},
{'pattern': '^є', 'replace': 'ye'},
{'pattern': 'є', 'replace': 'ie'},
{'pattern': 'ж', 'replace': 'zh'},
{'pattern': 'з', 'replace': 'z'},
{'pattern': 'и', 'replace': 'y'},
{'pattern': 'і', 'replace': 'i'},
{'pattern': '^ї', 'replace': 'yi'},
{'pattern': 'ї', 'replace': 'i'},
{'pattern': '^й', 'replace': 'y'},
{'pattern': 'й', 'replace': 'i'},
{'pattern': 'к', 'replace': 'k'},
{'pattern': 'л', 'replace': 'l'},
{'pattern': 'м', 'replace': 'm'},
{'pattern': 'н', 'replace': 'n'},
{'pattern': 'о', 'replace': 'o'},
{'pattern': 'п', 'replace': 'p'},
{'pattern': 'р', 'replace': 'r'},
{'pattern': 'с', 'replace': 's'},
{'pattern': 'т', 'replace': 't'},
{'pattern': 'у', 'replace': 'u'},
{'pattern': 'ф', 'replace': 'f'},
{'pattern': 'х', 'replace': 'kh'},
{'pattern': 'ц', 'replace': 'ts'},
{'pattern': 'ч', 'replace': 'ch'},
{'pattern': 'ш', 'replace': 'sh'},
{'pattern': 'щ', 'replace': 'shch'},
{'pattern': 'ьо', 'replace': 'io'},
{'pattern': 'ьї', 'replace': 'ii'},
{'pattern': 'ь', 'replace': ''},
{'pattern': '^ю', 'replace': 'yu'},
{'pattern': 'ю', 'replace': 'iu'},
{'pattern': '^я', 'replace': 'ya'},
{'pattern': 'я', 'replace': 'ia'},
{'pattern': 'А', 'replace': 'A'},
{'pattern': 'Б', 'replace': 'B'},
{'pattern': 'В', 'replace': 'V'},
{'pattern': 'Г', 'replace': 'H'},
{'pattern': 'Ґ', 'replace': 'G'},
{'pattern': 'Д', 'replace': 'D'},
{'pattern': 'Е', 'replace': 'E'},
{'pattern': '^Є', 'replace': 'Ye'},
{'pattern': 'Є', 'replace': 'Ie'},
{'pattern': 'Ж', 'replace': 'Zh'},
{'pattern': 'З', 'replace': 'Z'},
{'pattern': 'И', 'replace': 'Y'},
{'pattern': 'І', 'replace': 'I'},
{'pattern': '^Ї', 'replace': 'Yi'},
{'pattern': 'Ї', 'replace': 'I'},
{'pattern': '^Й', 'replace': 'Y'},
{'pattern': 'Й', 'replace': 'I'},
{'pattern': 'К', 'replace': 'K'},
{'pattern': 'Л', 'replace': 'L'},
{'pattern': 'М', 'replace': 'M'},
{'pattern': 'Н', 'replace': 'N'},
{'pattern': 'О', 'replace': 'O'},
{'pattern': 'П', 'replace': 'P'},
{'pattern': 'Р', 'replace': 'R'},
{'pattern': 'С', 'replace': 'S'},
{'pattern': 'Т', 'replace': 'T'},
{'pattern': 'У', 'replace': 'U'},
{'pattern': 'Ф', 'replace': 'F'},
{'pattern': 'Х', 'replace': 'Kh'},
{'pattern': 'Ц', 'replace': 'Ts'},
{'pattern': 'Ч', 'replace': 'Ch'},
{'pattern': 'Ш', 'replace': 'Sh'},
{'pattern': 'Щ', 'replace': 'Shch'},
{'pattern': 'Ь', 'replace': ''},
{'pattern': '^Ю', 'replace': 'Yu'},
{'pattern': 'Ю', 'replace': 'Iu'},
{'pattern': '^Я', 'replace': 'Ya'},
{'pattern': 'Я', 'replace': 'Ia'},
{'pattern': '’', 'replace': ''},
{'pattern': '\'', 'replace': ''},
{'pattern': '`', 'replace': ''}
];
for (var i = 0; i < rules.length; i++) {
word = word.replace(
new RegExp(rules[i]['pattern'], 'gm'),
rules[i]['replace']
);
}
return word;
};
var setWarning = function(matchesFound, input) {
var warning = document.querySelector('#tm-warning');
if (warning) {
warning.innerText = matchesFound > 0 ? "Name found" : "Custom message doesn't contain correct name";
warning.style.backgroundColor = matchesFound > 0 ? 'green' : 'yellow';
} else {
var d = document.createElement("div");
d.id = "tm-warning";
d.style.backgroundColor = matchesFound > 0 ? 'green' : 'yellow';
input.parentElement.appendChild(d);
}
}
setTimeout(function() {
setInterval(function() {
var nameHeader = document.querySelector('#send-invite-modal');
if (!nameHeader || nameHeader.innerText == 'You can customize this invitation') {
return;
}
var nameEng = nameHeader.innerText.split(' ')[1];
console.log('Found name ' + nameEng);
var input = document.querySelector('#custom-message');
if (!input) {
return;
}
var wordsUa = input.value.split(/[\s]|[ ,.!?;:()]/);
console.log("Words: " + wordsUa);
var nameFound = 0;
for (var i = 0; i < wordsUa.length; i++) {
var word = wordsUa[i];
if (!word) continue;
console.log('Checking word ' + word);
if (word.length > 4) {
var tp = transliteration(word.substring(0, word.length - 2));
console.log('Looking for transliterated part ' + tp);
var match = nameEng.indexOf(tp) == 0;
if (match) {
nameFound++;
}
}
}
setWarning(nameFound, input);
}, 2000);
}, 5000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment