Skip to content

Instantly share code, notes, and snippets.

@scsmash3r
Last active July 19, 2021 21:04
Show Gist options
  • Save scsmash3r/b55950b47a09470090ecb6790a2cb141 to your computer and use it in GitHub Desktop.
Save scsmash3r/b55950b47a09470090ecb6790a2cb141 to your computer and use it in GitHub Desktop.
Changes YouTube chat letters
// ==UserScript==
// @name YouTube Chat Letter Changer
// @description Gives a sᴘᴇᴄɪᴀʟ ᴛʀᴇᴀᴛᴍᴇɴᴛ to default font in chat window
// @author [SC]Smash3r
// @oujs:author [SC]Smash3r
// @namespace scsmash3r@gmail.com
// @version 0.1
// @include http://www.youtube.com/watch?*
// @include https://www.youtube.com/watch?*
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/livequery/1.1.1/jquery.livequery.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js
// @grant GM_xmlhttpRequest
// ==/UserScript==
/* Options */
var YT_input_ID = '#input.yt-live-chat-text-input-field-renderer';
var YT_chatframe_ID = '#chatframe';
/* Charsets to change */
var AsciiCodeToUtfChars = '{"32":" ","65":"ᴀ","66":"ʙ","67":"ᴄ","68":"ᴅ","69":"ᴇ","70":"ғ","71":"ɢ","72":"ʜ","73":"ɪ","74":"ᴊ","75":"ᴋ","76":"ʟ","77":"ᴍ","78":"ɴ","79":"ᴏ","80":"ᴘ","81":"ϙ","82":"ʀ","83":"s","84":"ᴛ","85":"ᴜ","86":"ᴠ","87":"ᴡ","88":"x","89":"ʏ","90":"ᴢ"}';
var utfToAsciiChars = [
["ᴀ", "ᴀ"],
["b", "ʙ"],
["c", "ᴄ"],
["d", "ᴅ"],
["e", "ᴇ"],
["f", "ғ"],
["g", "ɢ"],
["h", "ʜ"],
["i", "ɪ"],
["j", "ᴊ"],
["k", "ᴋ"],
["l", "ʟ"],
["m", "ᴍ"],
["n", "ɴ"],
["o", "ᴏ"],
["p", "ᴘ"],
["q", "ϙ"],
["r", "ʀ"],
["s", "s"],
["t", "ᴛ"],
["u", "ᴜ"],
["v", "ᴠ"],
["w", "ᴡ"],
["x", "x"],
["y", "ʏ"],
["z", "ᴢ"],
];
/* ----- When jQuery is ready ----- */
$(document).ready(function(){
initChecking();
});
/*
First of all, we need to set a time interval, that will be checking for needed element to appear on a page.
When element is on page, we can init main functions, since YT live chat is loading via iframe
*/
var initChecking = function() {
var intervalInt = window.setInterval(function(){
var inputCheck = $(YT_chatframe_ID).contents().find(YT_input_ID).html();
/* If our element appeared on page, we can bind some events now */
if (inputCheck !== undefined) {
initToastrMessages();
initLettersChange();
window.clearInterval(intervalInt);
}
}, 1000);
};
/*
------> Here we are tracking keyup events and replacing letters with the needed ones
*/
var initLettersChange = function() {
var chatFrameContents = $(YT_chatframe_ID).contents().find('body');
var chatInput = $(YT_chatframe_ID).contents().find(YT_input_ID);
var chatUnderline = $(YT_chatframe_ID).contents().find("#underline");
var iframeNode = $(YT_chatframe_ID).get(0);
var AsciiCodeToUtfCharsArray = $.parseJSON(AsciiCodeToUtfChars);
/* When the key is used */
$(chatFrameContents).on('keyup',function(data) {
var keycode = data.which.toString();
var newletter = AsciiCodeToUtfCharsArray[keycode];
console.log(data);
var nodeValue = data.target.childNodes[0].nodeValue;
/*TODO: whats next? */
});
toastr.info("Letters replacement activated!");
};
/*
Toast messages for visual feedback
*/
var initToastrMessages = function() {
/* Add Toast messages css, unless it already exists @see: https://github.com/CodeSeven/toastr */
var link = document.createElement("link");
link.href = "https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css";
link.type = "text/css";
link.rel = "stylesheet";
document.getElementsByTagName("head")[0].appendChild(link);
/* Setting up toastr messages for notices */
toastr.options = {"closeButton": false,"debug": false,"newestOnTop": false,"progressBar": true,"positionClass": "toast-bottom-right","preventDuplicates": false,"onclick": null,"showDuration": "200","hideDuration": "200","timeOut": "6000","extendedTimeOut": "2000","showEasing": "swing","hideEasing": "linear","showMethod": "fadeIn","hideMethod": "fadeOut"};
};
function convertText(text)
{
for (var i = 0; i < utfToAsciiChars.length; i++)
{
text = text.replace(new RegExp(utfToAsciiChars[i][0], 'g'), utfToAsciiChars[i][1]);
}
return text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment