User:Opencooper/IPtoEmoji.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:Opencooper/IPtoEmoji. |
// Converts IP addresses to emoji for better recognizability
// Uses a lookup table of 256 arbritrary emoji and uses the 8-bit hex parts of the
// address to pick the emoji. For IPv6, 16-bit hextets are split into two bytes.
// Doesn't work in IE due to method used to pad strings, but if you're still
// using that, you probably don't even know what emoji are ;)
// Stolen from: https://gist.github.com/windytan/7910910/
var emojiTable = [ "🌀", "🌂", "🌅", "🌈", "🌙", "🌞", "🌟", "🌠", "🌰", "🌱", "🌲", "🌳", "🌴", "🌵", "🌷", "🌸", "🌹", "🌺", "🌻", "🌼", "🌽", "🌾", "🌿", "🍀", "🍁", "🍂", "🍃", "🍄", "🍅", "🍆", "🍇", "🍈", "🍉", "🍊", "🍋", "🍌", "🍍", "🍎", "🍏", "🍐", "🍑", "🍒", "🍓", "🍔", "🍕", "🍖", "🍗", "🍘", "🍜", "🍝", "🍞", "🍟", "🍠", "🍡", "🍢", "🍣", "🍤", "🍥", "🍦", "🍧", "🍨", "🍩", "🍪", "🍫", "🍬", "🍭", "🍮", "🍯", "🍰", "🍱", "🍲", "🍳", "🍴", "🍵", "🍶", "🍷", "🍸", "🍹", "🍺", "🍻", "🍼", "🎀", "🎁", "🎂", "🎃", "🎄", "🎅", "🎈", "🎉", "🎊", "🎋", "🎌", "🎍", "🎎", "🎏", "🎒", "🎓", "🎠", "🎡", "🎢", "🎣", "🎤", "🎥", "🎦", "🎧", "🎨", "🎩", "🎪", "🎫", "🎬", "🎭", "🎮", "🎯", "🎰", "🎱", "🎲", "🎳", "🎴", "🎵", "🎷", "🎸", "🎹", "🎺", "🎻", "🎽", "🎾", "🎿", "🏀", "🏁", "🏂", "🏃", "🏄", "🏆", "🏇", "🏈", "🏉", "🏊", "🐀", "🐁", "🐂", "🐃", "🐄", "🐅", "🐆", "🐇", "🐈", "🐉", "🐊", "🐋", "🐌", "🐍", "🐎", "🐏", "🐐", "🐑", "🐒", "🐓", "🐔", "🐕", "🐖", "🐗", "🐘", "🐙", "🐚", "🐛", "🐜", "🐝", "🐞", "🐟", "🐠", "🐡", "🐢", "🐣", "🐤", "🐥", "🐦", "🐧", "🐨", "🐩", "🐪", "🐫", "🐬", "🐭", "🐮", "🐯", "🐰", "🐱", "🐲", "🐳", "🐴", "🐵", "🐶", "🐷", "🐸", "🐹", "🐺", "🐻", "🐼", "🐽", "🐾", "👀", "👂", "👃", "👄", "👅", "👆", "👇", "👈", "👉", "👊", "👋", "👌", "👍", "👎", "👏", "👐", "👑", "👒", "👓", "👔", "👕", "👖", "👗", "👘", "👙", "👚", "👛", "👜", "👝", "👞", "👟", "👠", "👡", "👢", "👣", "👤", "👥", "👦", "👧", "👨", "👩", "👪", "👮", "👯", "👺", "👻", "👼", "👽", "👾", "👿", "💀", "💁", "💂", "💃", "💄", "💅" ];
function addEmoji() {
var IP = $(this).text();
var emoji = convertIP(IP);
$(this).append("<span class='IP-emoji'> [" + emoji + "]</span>");
}
function convertIP(IP) {
var conversion = "";
var groups = [];
if (/\./.test(IP)) { // IPv4
groups = IP.split(".");
} else if (/:/.test(IP)) { // IPv6
return;
// Sometimes two consecutive zero-groups are omitted with "::"
IP = IP.replace(/::/g, ":0:0:");
v6groups = IP.split(":");
// Since IPv6 has 2-byte groups, we need to split those bytes
for (let i=0; i<v6groups.length; i++) {
var v6group = v6groups[i];
if (v6group.length < 4) {
v6group = v6group.padStart(4, "0");
}
groups.push(v6group.slice(0, 2));
groups.push(v6group.slice(2, 4));
}
} else {
console.error("User:Opencooper/IPtoEmoji.js: " + IP + " was not readable as an IP address");
return;
}
for (let i=0; i<groups.length; i++) {
var index = parseInt(groups[i], 16);
conversion += emojiTable[index];
}
return conversion;
}
$(".mw-anonuserlink").each(addEmoji);