// ==UserScript==
// @name KG_Full_Emoticons
// @namespace http://klavogonki.ru/
// @version 1.2.1
// @description Display a popup panel with every available emoticon on the site, remembering the last selected emoticon per category by name.
// @match *://klavogonki.ru/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=klavogonki.ru
// @grant none
// ==/UserScript==
(()=>{"use strict";var e={56:(e,t,o)=>{e.exports=function(e){var t=o.nc;t&&e.setAttribute("nonce",t)}},72:e=>{var t=[];function o(e){for(var o=-1,n=0;n<t.length;n++)if(t[n].identifier===e){o=n;break}return o}function n(e,n){for(var i={},a=[],c=0;c<e.length;c++){var s=e[c],l=n.base?s[0]+n.base:s[0],u=i[l]||0,m="".concat(l," ").concat(u);i[l]=u+1;var d=o(m),p={css:s[1],media:s[2],sourceMap:s[3],supports:s[4],layer:s[5]};if(-1!==d)t[d].references++,t[d].updater(p);else{var g=r(p,n);n.byIndex=c,t.splice(c,0,{identifier:m,updater:g,references:1})}a.push(m)}return a}function r(e,t){var o=t.domAPI(t);o.update(e);return function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap&&t.supports===e.supports&&t.layer===e.layer)return;o.update(e=t)}else o.remove()}}e.exports=function(e,r){var i=n(e=e||[],r=r||{});return function(e){e=e||[];for(var a=0;a<i.length;a++){var c=o(i[a]);t[c].references--}for(var s=n(e,r),l=0;l<i.length;l++){var u=o(i[l]);0===t[u].references&&(t[u].updater(),t.splice(u,1))}i=s}}},113:e=>{e.exports=function(e,t){if(t.styleSheet)t.styleSheet.cssText=e;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(e))}}},314:e=>{e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var o="",n=void 0!==t[5];return t[4]&&(o+="@supports (".concat(t[4],") {")),t[2]&&(o+="@media ".concat(t[2]," {")),n&&(o+="@layer".concat(t[5].length>0?" ".concat(t[5]):""," {")),o+=e(t),n&&(o+="}"),t[2]&&(o+="}"),t[4]&&(o+="}"),o})).join("")},t.i=function(e,o,n,r,i){"string"==typeof e&&(e=[[null,e,void 0]]);var a={};if(n)for(var c=0;c<this.length;c++){var s=this[c][0];null!=s&&(a[s]=!0)}for(var l=0;l<e.length;l++){var u=[].concat(e[l]);n&&a[u[0]]||(void 0!==i&&(void 0===u[5]||(u[1]="@layer".concat(u[5].length>0?" ".concat(u[5]):""," {").concat(u[1],"}")),u[5]=i),o&&(u[2]?(u[1]="@media ".concat(u[2]," {").concat(u[1],"}"),u[2]=o):u[2]=o),r&&(u[4]?(u[1]="@supports (".concat(u[4],") {").concat(u[1],"}"),u[4]=r):u[4]="".concat(r)),t.push(u))}},t}},540:e=>{e.exports=function(e){var t=document.createElement("style");return e.setAttributes(t,e.attributes),e.insert(t,e.options),t}},601:e=>{e.exports=function(e){return e[1]}},659:e=>{var t={};e.exports=function(e,o){var n=function(e){if(void 0===t[e]){var o=document.querySelector(e);if(window.HTMLIFrameElement&&o instanceof window.HTMLIFrameElement)try{o=o.contentDocument.head}catch(e){o=null}t[e]=o}return t[e]}(e);if(!n)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");n.appendChild(o)}},825:e=>{e.exports=function(e){if("undefined"==typeof document)return{update:function(){},remove:function(){}};var t=e.insertStyleElement(e);return{update:function(o){!function(e,t,o){var n="";o.supports&&(n+="@supports (".concat(o.supports,") {")),o.media&&(n+="@media ".concat(o.media," {"));var r=void 0!==o.layer;r&&(n+="@layer".concat(o.layer.length>0?" ".concat(o.layer):""," {")),n+=o.css,r&&(n+="}"),o.media&&(n+="}"),o.supports&&(n+="}");var i=o.sourceMap;i&&"undefined"!=typeof btoa&&(n+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(i))))," */")),t.styleTagTransform(n,e,t.options)}(t,e,o)},remove:function(){!function(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e)}(t)}}}},911:(e,t,o)=>{o.d(t,{A:()=>c});var n=o(601),r=o.n(n),i=o(314),a=o.n(i)()(r());a.push([e.id,"@import url(https://fonts.googleapis.com/css2?family=Noto+Color+Emoji&display=swap);"]),a.push([e.id,':root{--active-button-mixed: color-mix( in srgb, var(--third-accent-color) 40%, transparent 60% );--saved-button-mixed: color-mix( in srgb, var(--fourth-accent-color) 40%, transparent 60% );--hover-button-mixed: color-mix( in srgb, var(--third-accent-color) 25%, transparent 85% );--label-unfocused-mix: color-mix( in srgb, var(--background-color) 85%, var(--third-accent-color) 15% );--label-focused-mix: color-mix( in srgb, var(--background-color) 85%, var(--fourth-accent-color) 15% )}.emoticons-popup{border-radius:.4em !important;box-shadow:0 2px 8px rgba(0,0,0,.15) !important;opacity:0;transition:opacity .3s cubic-bezier(0.25, 0.8, 0.25, 1);position:fixed;display:grid;grid-template-rows:50px auto;padding:.5em;gap:.5em;background-color:var(--background-color, var(--popup-background));border:1px solid var(--border-color, transparent);z-index:2000;top:10vh;left:50vw;transform:translateX(-50%);min-width:300px;width:800px;max-height:90vh;overflow:hidden}.emoticons-popup .header-buttons{display:flex;flex-direction:row;justify-content:space-between;gap:.5em}.emoticons-popup .header-buttons .clear-button{border-radius:.2em !important;border:none;cursor:pointer;box-sizing:border-box;width:50px;height:50px;font-size:1.4em;background:hsl(40,50%,15%);border:2px solid hsl(40,50%,25%)}.emoticons-popup .header-buttons .clear-button svg{stroke:#ca6}.emoticons-popup .header-buttons .close-button{border-radius:.2em !important;border:none;cursor:pointer;box-sizing:border-box;width:50px;height:50px;font-size:1.4em;background:hsl(0,50%,15%);border:2px solid hsl(0,50%,25%)}.emoticons-popup .header-buttons .close-button svg{stroke:#c66}.emoticons-popup .header-buttons .header-button{transition:filter .15s}.emoticons-popup .header-buttons .header-button:hover{filter:brightness(1.1)}.emoticons-popup .header-buttons .category-buttons{display:flex;justify-content:center;gap:.5em;font-family:"Noto Color Emoji",sans-serif !important}.emoticons-popup .header-buttons .category-buttons .category-button{border-radius:.2em !important;border:none;cursor:pointer;box-sizing:border-box;width:50px;height:50px;font-size:1.4em;text-shadow:0 0 .6px rgba(0,0,0,.8588235294);background:var(--highlight-color, var(--default-button))}.emoticons-popup .header-buttons .category-buttons .category-button.active{background:var(--active-button-mixed, var(--active-button))}.emoticons-popup .header-buttons .category-buttons .category-button:hover{background:var(--hover-button-mixed, var(--hover-button))}.emoticons-popup .header-buttons .category-buttons .category-button.disabled{opacity:.5;pointer-events:none}.emoticons-popup .label{font-size:.9em !important;font-weight:normal !important;color:var(--third-accent-color, var(--selected-button));padding:.2em .6em;border-radius:.2em !important;border:1px solid rgba(0,0,0,0);background-color:var(--label-unfocused-mix, var(--default-button));display:inline-flex;margin:1em 0 .5em 0}.emoticons-popup .label.focused-section{color:var(--fourth-accent-color, var(--default-button));background-color:var(--label-focused-mix, var(--selected-button))}.emoticons-popup .recent-emoticon-buttons{display:flex;flex-wrap:wrap}.emoticons-popup .recent-emoticon-buttons .emoticon-button{height:fit-content}.emoticons-popup .category-emoticon-buttons{display:grid}.emoticons-popup .recent-emoticon-buttons,.emoticons-popup .category-emoticon-buttons{gap:.5em;overflow-y:auto;overflow-x:hidden;scrollbar-width:none}.emoticons-popup .recent-emoticon-buttons::-webkit-scrollbar,.emoticons-popup .category-emoticon-buttons::-webkit-scrollbar{display:none}.emoticons-popup .recent-emoticon-buttons .emoticon-button,.emoticons-popup .category-emoticon-buttons .emoticon-button{display:flex;justify-content:center;align-items:center;border-radius:.2em !important;border:none;cursor:pointer;position:relative;background:var(--highlight-color, var(--default-button));padding:.5em}.emoticons-popup .recent-emoticon-buttons .emoticon-button img,.emoticons-popup .category-emoticon-buttons .emoticon-button img{display:block}.emoticons-popup .recent-emoticon-buttons .emoticon-button.selected,.emoticons-popup .category-emoticon-buttons .emoticon-button.selected{background:var(--active-button-mixed, var(--selected-button))}.emoticons-popup .recent-emoticon-buttons .emoticon-button.favorite,.emoticons-popup .category-emoticon-buttons .emoticon-button.favorite{background:var(--saved-button-mixed, var(--active-button))}.emoticons-popup .recent-emoticon-buttons .emoticon-button:hover,.emoticons-popup .category-emoticon-buttons .emoticon-button:hover{background:var(--hover-button-mixed, var(--hover-button))}.emoticons-toggle{position:fixed !important;bottom:5em !important;right:-1px !important;transform:translateY(-50%) !important;z-index:1050 !important;display:flex;align-items:center !important;justify-content:center !important;padding:.4em !important;background-color:var(--foreground-color, #17191c) !important;font-size:18px !important;font-family:"Noto Color Emoji",sans-serif !important;font-weight:bold !important;border:1px solid var(--border-color, #4d4d4d) !important;border-radius:.4em 0 0 .4em !important;cursor:pointer !important;transition:background .2s ease,opacity .2s ease !important}.emoticons-toggle:hover{background-color:var(--background-color, rgba(23, 25, 28, 0.5019607843)) !important}@media screen and (max-width: 1200px){.emoticons-popup{width:100%;top:30px;max-height:70vh}.emoticons-popup .recent-emoticon-buttons,.emoticons-popup .category-emoticon-buttons{max-height:calc(70vh - 70px)}}@media screen and (max-width: 530px){.emoticons-popup{display:flex;flex-direction:row;top:0}.emoticons-popup .header-buttons{flex-direction:column;justify-content:flex-start}.emoticons-popup .header-buttons button{width:40px !important;height:40px !important}.emoticons-popup .header-buttons button svg{width:18px !important;height:18px !important}.emoticons-popup .header-buttons .category-buttons{flex-direction:column}.emoticons-popup .header-buttons .category-buttons .category-button{font-size:1.2em}.emoticons-popup .recent-emoticon-buttons,.emoticons-popup .category-emoticon-buttons{display:flex;flex-direction:row;flex-wrap:wrap;min-height:320px;height:fit-content}.emoticons-popup .recent-emoticon-buttons .emoticon-button,.emoticons-popup .category-emoticon-buttons .emoticon-button{min-height:40px;min-width:40px;height:fit-content}}',""]);const c=a}},t={};function o(n){var r=t[n];if(void 0!==r)return r.exports;var i=t[n]={id:n,exports:{}};return e[n](i,i.exports,o),i.exports}o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.nc=void 0;var n=o(72),r=o.n(n),i=o(825),a=o.n(i),c=o(659),s=o.n(c),l=o(56),u=o.n(l),m=o(540),d=o.n(m),p=o(113),g=o.n(p),y=o(911),h={};h.styleTagTransform=g(),h.setAttributes=u(),h.insert=s().bind(null,"head"),h.domAPI=a(),h.insertStyleElement=d();r()(y.A,h);y.A&&y.A.locals&&y.A.locals;const f={Boys:["hello","hi","smile","wink","biggrin","laugh","happy","cool","rofl","rofl2","rolleyes","spiteful","crazy","acute","silence","tongue","whistle","music","ph34r","excl","no","yes","ok","bye","victory","good","clapping","dance","cult","power","boystroking","complaugh","badcomp","gamer","first","second","third","formula1","friends","popcorn","tea","beer","grats","birthday","holmes","kidtruck","musketeer","pioneer","mellow","dry","sleep","cry","sick","sorry","unsure","boredom","facepalm","scare","blink","sad","confuse","nervous","wacko","huh","ohmy","megashok","shok","bad","russian","dash","angry","angry2"],Girls:["cheerful","cheerleader","clapgirl","curtsey","enjoygift","girlblum","girlconfuse","girlcrazy","girlcry","girlicecream","girlimpossible","girlinlove","girlkiss","girlkissboy","girlmad","girlmusic","girlnervous","girlnotebook","girlobserve","girlrevolve","girlsad","umbrage","girlscare","girlshighfive","girlsick","girlsilence","girlstop","girlstroking","girlsuper","girltea","girlwacko","girlwink","girlwitch","girlwonder","goody","hairdryer","hiya","hysteric","kgagainstaz","kgrace","primp","respect","spruceup","spruceup1","supergirl","tender","angrygirl","girldevil"],Christmas:["firework","confetti","cheers","wine","champ","champ2","santa","santa2","santa3","snowhand","snowhit","heyfrombag","snowgirlwave","snowball","snegurochka","santasnegurka","snowman","merrychristmas","spruce","moose","christmasevil"],Inlove:["inlove","hug","boykiss","wecheers","wedance","adultery","cave","leisure","wedding","airkiss","kissed","flowers","grose","flowers2","rose","smell","frog","girlfrog","rocker","serenade","val","girlval","bemine","heartcake","heart2","girlheart2","girllove","nolove","heart","blush","wub"],Army:["uzi","ak47","barret","chaingun","pogranminigun","partizan","dandy","gangster","mafia","foolrifle","cowboy","armyscare","armystar","armyfriends","armytongue","soldier","bayanist","pogranmail","pogran","pogranflowers","pogranrose","pograntort","girlpogran","pogranmama","budenov","captain","vdv","comandos","kirpich","girlvdv","girlranker","ranker","girlrogatka","rogatka","radistka","prival","vtik","vpered","tank","fly"],Halloween:["alien","ghost","cyborg","robot","terminator","turtle","batman","bebebe","bite","corsair","girlpirate","indigenous","clown","jester","death","paladin","pirate","dwarf","pirates","witch","wizard","spider","diablo","vampire","carpet"],Favourites:[]},v={Boys:"🎩",Girls:"🎀",Christmas:"🎄",Inlove:"❤️",Army:"🔫",Halloween:"🎃",Favourites:"🌟"},b=20,E=300,x="22",w="http://www.w3.org/2000/svg",S="0 0 24 24",C=`\n <svg xmlns="${w}"\n width="${x}"\n height="${x}"\n viewBox="${S}"\n stroke="currentColor"\n fill="none"\n stroke-width="2"\n stroke-linecap="round"\n stroke-linejoin="round">\n <polyline points="3 6 5 6 21 6"></polyline>\n <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>\n <line x1="10" y1="11" x2="10" y2="17"></line>\n <line x1="14" y1="11" x2="14" y2="17"></line>\n </svg>`,k=`\n <svg xmlns="${w}"\n width="${x}"\n height="${x}"\n viewBox="${S}"\n stroke="currentColor" \n fill="none"\n stroke-width="2"\n stroke-linecap="round"\n stroke-linejoin="round">\n <rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect>\n <line x1="9" y1="9" x2="15" y2="15"></line>\n <line x1="15" y1="9" x2="9" y2="15"></line>\n </svg>`;function I(e,t){const{state:o,toggleEmoticonsPopup:n,removeEmoticonsPopup:r}=t;if("KeyV"===e.code&&e.ctrlKey){document.querySelector(".emoticons-popup")&&r()}else"KeyQ"===e.code?function(e,t,o,n,r){const{state:i}=r,a=Date.now();e.code===t?a-(i.lastKeyTimes[t]||0)<o?(e.preventDefault(),n(),i.lastKeyTimes[t]=0):i.lastKeyTimes[t]=a:i.lastKeyTimes[t]=0}(e,"KeyQ",500,(function(){if(o.lastFocusedInput){let e=o.lastFocusedInput.value;e.length>=2&&e.slice(-1)===e.slice(-2,-1)?e=e.slice(0,-2):e.length>=1&&(e=e.slice(0,-1)),o.lastFocusedInput.value=e;const t=e.length;o.lastFocusedInput.setSelectionRange(t,t)}n()}),t):o.lastKeyTimes.KeyQ=0}function U(e,t){let o,n=null;e.addEventListener("pointerdown",(e=>{const r=e.target.closest("button.emoticon-button");r&&(n=r,o=setTimeout((()=>{n&&(e.preventDefault(),t(n),n=null)}),E))}));const r=()=>{o&&(clearTimeout(o),o=null)};return e.addEventListener("pointerup",r),e.addEventListener("pointerleave",r),e.addEventListener("pointercancel",r),()=>n}function K(e,t,o){const n=e.target.closest("button.emoticon-button");if(!n||!t())return;e.stopPropagation();o(n.title,e)}function L(e){const t=[{event:"keydown",handler:t=>function(e,t){const{state:o,insertEmoticonCode:n,incrementEmoticonUsage:r,removeEmoticonsPopup:i,updateEmoticonHighlight:a,navigateSelection:c}=t;if(!document.querySelector(".emoticons-popup"))return;if(new Set(["Enter","Semicolon","KeyA","ArrowLeft","ArrowRight","KeyJ","KeyK","KeyS","KeyF","KeyD"]).has(e.code)){if(e.preventDefault(),"KeyD"===e.code){const e=null!==document.querySelector(".recent-emoticon-buttons");return"category"===o.focusedSection&&e?(o.focusedSection="recent",(o.lastUsedRecentEmoticon<0||o.lastUsedRecentEmoticon>=o.recentEmoticons.length)&&(o.lastUsedRecentEmoticon=0,localStorage.setItem("lastUsedRecentEmoticon",JSON.stringify(0)))):o.focusedSection="category",void a()}if("Enter"===e.code||"Semicolon"===e.code||"KeyA"===e.code){let t;return"category"===o.focusedSection?t=o.lastUsedCategoryEmoticons[o.activeCategory]:"recent"===o.focusedSection&&o.lastUsedRecentEmoticon<o.recentEmoticons.length&&(t=o.recentEmoticons[o.lastUsedRecentEmoticon]),void(t&&(n(t),r(t),e.shiftKey||i()))}"ArrowLeft"===e.code||"KeyJ"===e.code||"KeyS"===e.code?c(-1):"ArrowRight"!==e.code&&"KeyK"!==e.code&&"KeyF"!==e.code||c(1)}}(t,e)},{event:"keydown",handler:t=>function(e,t){const{state:o,getSortedEmoticons:n,changeActiveCategoryOnClick:r,updateToggleButtonIcon:i}=t;if(!document.querySelector(".emoticons-popup")||!["Tab","KeyH","KeyL","KeyW","KeyR"].includes(e.code)&&("Tab"!==e.code||!e.shiftKey))return;e.preventDefault();const a=Object.keys(f),c=0===(JSON.parse(localStorage.getItem("favoriteEmoticons"))||[]).length?a.filter((e=>"Favourites"!==e)):a;let s=c.indexOf(o.activeCategory);-1===s&&(s=0);let l=("Tab"===e.code&&!e.shiftKey||"KeyL"===e.code||"KeyR"===e.code)&&s<c.length-1?s+1:("KeyH"===e.code||"KeyW"===e.code||"Tab"===e.code&&e.shiftKey)&&s>0?s-1:s;if(l===s)return;const u=c[l];o.currentSortedEmoticons=n(u),localStorage.setItem("activeCategory",u),r(u),i()}(t,e)},{event:"keydown",handler:t=>function(e,t){const{removeEmoticonsPopup:o}=t;!document.querySelector(".emoticons-popup")||"Escape"!==e.code&&"KeyQ"!==e.code||(e.preventDefault(),o())}(t,e)},{event:"click",handler:t=>function(e,t){const{removeEmoticonsPopup:o}=t,n=document.querySelector(".emoticons-popup");n&&!n.contains(e.target)&&o()}(t,e)}];return t.forEach((({event:e,handler:t})=>{document.addEventListener(e,t)})),t.map((({event:e,handler:t})=>({event:e,handler:t})))}!function(){const e={eventListeners:[],activeCategory:localStorage.getItem("activeCategory")||"Boys",isPopupCreated:!1,categoryHistory:[],currentSortedEmoticons:[],lastFocusedInput:null,latestCategoryRequest:null,lastKeyTimes:{},lastUsedCategoryEmoticons:JSON.parse(localStorage.getItem("lastUsedCategoryEmoticons"))||{},recentEmoticons:JSON.parse(localStorage.getItem("recentEmoticons"))||[],lastUsedRecentEmoticon:JSON.parse(localStorage.getItem("lastUsedRecentEmoticon"))||0,focusedSection:"recent",isMobile:/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)||"ontouchstart"in window},t=function(e){const t=e.match(/\d+/g);if(t&&3===t.length){const[e,o,n]=t.map(Number),r=Math.max(e,o,n)/255,i=Math.min(e,o,n)/255;return Math.round((r+i)/2*100)}return 0}(window.getComputedStyle(document.body).backgroundColor),o={popupBackground:n("popupBackground"),defaultButton:n("defaultButton"),hoverButton:n("hoverButton"),activeButton:n("activeButton"),selectedButton:n("selectedButton")};function n(e){const o={popupBackground:10,defaultButton:15,hoverButton:25,activeButton:35,selectedButton:50}[e]||0;return`hsl(0, 0%, ${t<50?t+o:t-o}%)`}function r(){return JSON.parse(localStorage.getItem("emoticonUsageData"))||{}}function i(t){const o=r();o[e.activeCategory]=o[e.activeCategory]||{},o[e.activeCategory][t]=(o[e.activeCategory][t]||0)+1,function(e){localStorage.setItem("emoticonUsageData",JSON.stringify(e))}(o)}function a(e){const t=r()[e]||{};return f[e].slice().sort(((e,o)=>(t[o]||0)-(t[e]||0)))}function c(e){return(JSON.parse(localStorage.getItem("favoriteEmoticons"))||[]).includes(e)}function s(){const e=window.location.pathname,t=window.location.hash,o=new URLSearchParams(window.location.search).get("gmid"),n=t.match(/#\/(\d+)\//);return{isForum:e.includes("/forum/"),isGamelist:e.includes("/gamelist/"),isGame:!!o,isProfile:"/u/"===e&&!!n,gmid:o||null,profileId:n?.[1]||null}}function l(t){const o=s();let n=e.lastFocusedInput;if(!n){if(n=o.isForum?document.getElementById("fast-reply_textarea"):o.isGamelist?document.querySelector("#chat-general.chat .messages input.text"):o.isGame?document.querySelector('[id^="chat-game"].chat .messages input.text'):document.querySelector("#app-chat-container #message-input"),!n){const e={isForum:"the forum",isProfile:"the profile",isGamelist:"general chat",isGame:"game chat"},t=Object.entries(e).filter((([e])=>o[e])).map((([e,t])=>t)).join(", ");return void alert(`Please focus on a text field in ${t}.`)}e.isMobile||n.focus(),e.lastFocusedInput=n}const r=function(t){const{isForum:o}=s();return o&&e.lastFocusedInput&&"textarea"===e.lastFocusedInput.tagName.toLowerCase()?`[img]https://klavogonki.ru/img/smilies/${t}.gif[/img] `:`:${t}: `}(t),i=n.selectionStart||0;n.value=n.value.slice(0,i)+r+n.value.slice(i),n.setSelectionRange(i+r.length,i+r.length),e.isMobile||n.focus(),function(t){const o=e.recentEmoticons.filter((e=>e!==t));e.recentEmoticons=[t,...o].slice(0,b),localStorage.setItem("lastUsedRecentEmoticon",JSON.stringify(e.lastUsedRecentEmoticon)),localStorage.setItem("recentEmoticons",JSON.stringify(e.recentEmoticons))}(t)}function u(e,t){"show"===t?(document.body.appendChild(e),requestAnimationFrame((()=>{e.style.opacity="1"}))):(e.style.opacity="0",setTimeout((()=>e.remove()),300))}function m(){const t=document.querySelector(".emoticons-popup");if(!t)return;e.eventListeners.forEach((({event:e,handler:t})=>{document.removeEventListener(e,t)})),e.eventListeners=[],u(t,"hide"),e.isPopupCreated=!1;const o=e.lastFocusedInput;if(o){o.focus();const e=o.value.length;o.setSelectionRange(e,e)}}function d(){e.isPopupCreated?m():setTimeout((()=>{!function(t){if(e.isPopupCreated)return;f.Favourites=JSON.parse(localStorage.getItem("favoriteEmoticons"))||[];const o=document.createElement("div");o.className="emoticons-popup";const n=document.createElement("div");n.className="header-buttons";const r=(e,t,o,n)=>{const r=document.createElement("button");return r.className=e,r.title=t,r.innerHTML=o,n&&r.addEventListener("click",n),r},a=r("header-button clear-button","Clear usage data",C,(()=>{if(confirm("Clear emoticon usage data?")){localStorage.removeItem("emoticonUsageData"),localStorage.removeItem("recentEmoticons"),e.recentEmoticons=[],localStorage.setItem("lastUsedRecentEmoticon",JSON.stringify(e.lastUsedRecentEmoticon));const t=document.querySelector(".recent-emoticons");t&&t.remove();const o=document.querySelector(".category-label");o&&o.remove()}})),c=r("header-button close-button","Close emoticons panel",k,m);n.appendChild(a),n.appendChild(function(){const t=document.createElement("div");t.className="category-buttons",Object.keys(f).forEach((o=>{const n=document.createElement("button");n.className=["category-button",o===e.activeCategory&&"active","Favourites"===o&&!f.Favourites.length&&"disabled"].filter(Boolean).join(" "),n.dataset.category=o,n.innerHTML=v[o],n.title=o,t.appendChild(n)}));return function(e,t,o){e.addEventListener("click",(e=>{const n=e.target.closest("button.category-button");if(!n)return;const r=n.dataset.category;"Favourites"===r&&e.ctrlKey?o(e):t(r,e)}))}(t,((e,t)=>{if(!t.shiftKey&&!t.ctrlKey){S(e)}}),(t=>{if(t.ctrlKey){localStorage.removeItem("favoriteEmoticons");f.Favourites=[];O();if(e.categoryHistory.length){e.activeCategory=e.categoryHistory.pop();localStorage.setItem("activeCategory",e.activeCategory);w(e.activeCategory);F();p()}}})),t}()),n.appendChild(c),o.appendChild(n),e.recentEmoticons.length>0&&async function(){const t=document.createElement("div");t.className="recent-emoticons";const o=g("recent-emoticon-buttons"),n=document.createElement("span");n.className="label recent-label",n.textContent="Recently used",t.appendChild(n);const r=e.recentEmoticons.map((e=>{const{btn:t,imgSrc:n}=y(e,"recent-button");return o.appendChild(t),h(n)})),a=(t,o)=>{const n=e.recentEmoticons.indexOf(t);if(-1!==n&&(e.recentEmoticons.splice(n,1),localStorage.setItem("recentEmoticons",JSON.stringify(e.recentEmoticons)),e.lastUsedRecentEmoticon>=e.recentEmoticons.length&&(e.lastUsedRecentEmoticon=Math.max(0,e.recentEmoticons.length-1),localStorage.setItem("lastUsedRecentEmoticon",JSON.stringify(e.lastUsedRecentEmoticon))),o.remove(),0===e.recentEmoticons.length)){const e=document.querySelector(".recent-emoticons");e&&e.remove()}},c=(t,o)=>{if(o.ctrlKey){const e=o.target.closest("button.emoticon-button");return void a(t,e)}const n=e.recentEmoticons.indexOf(t);-1!==n&&(e.lastUsedRecentEmoticon=n,localStorage.setItem("lastUsedRecentEmoticon",JSON.stringify(e.lastUsedRecentEmoticon))),l(t),i(t),e.lastUsedCategoryEmoticons[e.activeCategory]=t,localStorage.setItem("lastUsedCategoryEmoticons",JSON.stringify(e.lastUsedCategoryEmoticons)),e.isMobile||o.shiftKey||m(),O()};return function(e,t,o){const n=U(e,(e=>{t(e.title,e)}));e.addEventListener("click",(e=>K(e,n,o)))}(o,a,c),await Promise.all(r),await E(o,e.recentEmoticons),t.appendChild(o),t}().then((e=>{o.appendChild(e)}));x(t).then((e=>{o.appendChild(e),requestAnimationFrame(O)})),e.eventListeners=L(N),document.body.appendChild(o),u(o,"show"),e.isPopupCreated=!0}(e.activeCategory)}),10)}function p(){const t=document.querySelector(".emoticons-toggle");t&&(t.innerHTML=v[e.activeCategory]||"😊",t.title=`Open emoticons panel (${e.activeCategory})`)}function g(e="category-emoticon-buttons"){const t=document.createElement("div");return t.className=e,t.addEventListener("contextmenu",(e=>e.preventDefault())),t}function y(e,t=""){const o=document.createElement("button");o.className=`emoticon-button ${t}`,o.title=e;const n=`/img/smilies/${e}.gif`;return o.innerHTML=`<img src="${n}" alt="${e}">`,{btn:o,imgSrc:n}}function h(e){return new Promise((t=>{const o=new Image;o.onload=t,o.src=e}))}async function E(e,t){const{maxImageWidth:o,maxImageHeight:n}=await async function(e){const t=34,o=await Promise.all(e.map((e=>new Promise((t=>{const o=new Image;o.onload=()=>t({width:o.width,height:o.height}),o.src=`/img/smilies/${e}.gif`}))))),n=Math.max(t,...o.map((e=>e.width))),r=Math.max(t,...o.map((e=>e.height)));return{maxImageWidth:n,maxImageHeight:r}}(t);Object.assign(e.style,{gridTemplateColumns:`repeat(auto-fit, minmax(${o}px, 1fr))`,gridAutoRows:`minmax(${n}px, auto)`})}async function x(t){const o=document.createElement("div");o.className="category-emoticons";const n=g();if(e.recentEmoticons.length>0&&!document.querySelector(".category-emoticons .category-label")){const e=document.createElement("span");e.className="label category-label",e.textContent="Category section",o.appendChild(e)}e.currentSortedEmoticons=a(t);const r=e.currentSortedEmoticons.map((t=>{let o="";t===e.lastUsedCategoryEmoticons[e.activeCategory]?o="selected":"Favourites"!==e.activeCategory&&c(t)&&(o="favorite");const{btn:r,imgSrc:i}=y(t,o);return n.appendChild(r),h(i)})),s=e=>{const o=JSON.parse(localStorage.getItem("favoriteEmoticons"))||[],n=o.indexOf(e);"Favourites"===t&&-1!==n?(o.splice(n,1),f.Favourites.splice(n,1)):"Favourites"!==t&&-1===n&&(o.push(e),f.Favourites.push(e)),localStorage.setItem("favoriteEmoticons",JSON.stringify(o)),w(t),"Favourites"===t&&F(),O()};return function(e,t,o){const n=U(e,(e=>{t(e.title)}));e.addEventListener("click",(e=>K(e,n,o)))}(n,(e=>{s(e)}),((t,o)=>{o.shiftKey?l(t):o.ctrlKey?s(t):(l(t),i(t),e.lastUsedCategoryEmoticons[e.activeCategory]=t,localStorage.setItem("lastUsedCategoryEmoticons",JSON.stringify(e.lastUsedCategoryEmoticons)),e.isMobile||m()),O()})),await Promise.all(r),await E(n,e.currentSortedEmoticons),o.appendChild(n),o}function w(e){document.querySelectorAll(".category-buttons button").forEach((t=>{t.dataset.category===e?t.classList.add("active"):t.classList.remove("active"),"Favourites"===t.dataset.category&&(0===f.Favourites.length?t.classList.add("disabled"):t.classList.remove("disabled"))}))}function S(t){"Favourites"===t&&0===f.Favourites.length||("Favourites"!==e.activeCategory&&e.categoryHistory.push(e.activeCategory),e.activeCategory=t,localStorage.setItem("activeCategory",e.activeCategory),e.currentSortedEmoticons=a(e.activeCategory),w(e.activeCategory),F(),p())}function O(){requestAnimationFrame((()=>{document.querySelectorAll(".emoticon-button").forEach((e=>{e.classList.remove("selected","favorite","section-focused")})),document.querySelectorAll(".category-label, .recent-label").forEach((e=>e.classList.remove("focused-section")));const t="category"===e.focusedSection?".category-label":".recent-label",o=document.querySelector(t);if(o&&o.classList.add("focused-section"),e.activeCategory){document.querySelectorAll(".category-emoticon-buttons button").forEach((t=>{const o=t.title;o===e.lastUsedCategoryEmoticons[e.activeCategory]?(t.classList.add("selected"),"category"===e.focusedSection&&t.classList.add("section-focused")):"Favourites"!==e.activeCategory&&c(o)&&t.classList.add("favorite")}))}if(e.recentEmoticons.length>0){const t=document.querySelectorAll(".recent-emoticon-buttons button"),o=Math.min(e.lastUsedRecentEmoticon,t.length-1);if(o>=0&&o<t.length){const n=t[o];n.classList.add("selected"),"recent"===e.focusedSection&&n.classList.add("section-focused")}}}))}function F(){const t=Date.now();e.latestCategoryRequest=t;const o=document.querySelector(".category-emoticons");o&&o.remove(),x(e.activeCategory).then((o=>{if(e.latestCategoryRequest!==t)return;const n=document.querySelector(".emoticons-popup");n&&(n.appendChild(o),O())}))}Object.entries({"popup-background":o.popupBackground,"default-button":o.defaultButton,"hover-button":o.hoverButton,"active-button":o.activeButton,"selected-button":o.selectedButton}).forEach((([e,t])=>{document.documentElement.style.setProperty(`--${e}`,t)})),Object.keys(f).forEach((t=>{Object.prototype.hasOwnProperty.call(e.lastUsedCategoryEmoticons,t)&&f[t].includes(e.lastUsedCategoryEmoticons[t])||(e.lastUsedCategoryEmoticons[t]=f[t][0]||"")})),function(){const t=document.createElement("button");t.className="emoticons-toggle",t.title=`Open emoticons panel (${e.activeCategory})`,t.innerHTML=v[e.activeCategory]||"😊",t.addEventListener("click",d),document.body.appendChild(t)}();const N={state:e,toggleEmoticonsPopup:d,removeEmoticonsPopup:m,insertEmoticonCode:l,incrementEmoticonUsage:i,updateEmoticonHighlight:O,getSortedEmoticons:a,changeActiveCategoryOnClick:S,updateToggleButtonIcon:p,navigateSelection:function(t){if("category"===e.focusedSection){const o=e.currentSortedEmoticons.indexOf(e.lastUsedCategoryEmoticons[e.activeCategory]);let n=-1===o?0:o+t;n<0&&(n=e.currentSortedEmoticons.length-1),n>=e.currentSortedEmoticons.length&&(n=0),e.lastUsedCategoryEmoticons[e.activeCategory]=e.currentSortedEmoticons[n],localStorage.setItem("lastUsedCategoryEmoticons",JSON.stringify(e.lastUsedCategoryEmoticons))}else{if(0===e.recentEmoticons.length)return;let o=e.lastUsedRecentEmoticon+t;o<0&&(o=e.recentEmoticons.length-1),o>=e.recentEmoticons.length&&(o=0),e.lastUsedRecentEmoticon=o,localStorage.setItem("lastUsedRecentEmoticon",JSON.stringify(e.lastUsedRecentEmoticon))}O()}};!function(e){document.addEventListener("focusin",(t=>function(e,t){const{state:o}=t;e.target.matches("textarea, input.text, input#message-input")&&(o.lastFocusedInput=e.target)}(t,e))),document.addEventListener("mouseup",(t=>function(e,t){const{toggleEmoticonsPopup:o}=t;e.ctrlKey&&0===e.button&&e.target.matches("textarea, input.text, input#message-input")&&(e.preventDefault(),o())}(t,e))),document.addEventListener("keydown",(t=>I(t,e)))}(N)}()})();