PageSourceSearch

https://www.grandline.ru/verstka/shop/js/jivo-tg-bot.js?1733040456

js grandline.ru collected 2026-10-03 19:49:33 UTC 3,156 bytes, 1 lines download raw bytes

1const TELEGRAM_BOT_LINK="https://t.me/grandlineru_customers_bot",API_SAVE_MSG_URL="https://stage.chatbot.grandline.com/api/v1/widget-messages",Senders=Object.freeze({CLIENT:"client",AGENT:"agent"});function prepareClientMessageData(e){return{sender:{id:`${e.message.chat_id}`},message:{type:"text",id:`${e.message.msg_id}`,date:Date.now(),text:`${e.message.text}`}}}function prepareAgentMessageData(e){return{sender:{id:`${e.message.chat_id}`},recipient:{id:`${e.message.chat_id}`},message:{type:"text",id:`${e.message.msg_id}`,date:Date.now(),text:`${e.message.text}`}}}function getJdivElementByClass(e){const t=document.getElementsByTagName("jdiv");for(const s of t)if(s.classList&&s.classList.length>0&&s.classList[0].startsWith(e))return s;return null}function waitForElement(e){return new Promise((t=>{if(document.querySelector(e))return t(document.querySelector(e));const s=new MutationObserver((n=>{document.querySelector(e)&&(s.disconnect(),t(document.querySelector(e)))}));s.observe(document.body,{childList:!0,subtree:!0})}))}function collectMesssages(e,t,s){const n=[];for(const a of e)for(const e of t)if(a.includes(e)){message=JSON.parse(localStorage.getItem(a)),message.from==s&&n.push({key:a,message:message}),t.splice(t.indexOf(e),1);break}return n}function getMessagesKeys(e){const t=e.filter((e=>e.startsWith("jv_messages")));return t.length>1?(localStorage.clear(),sessionStorage.getItem("reloaded")||(sessionStorage.setItem("reloaded","true"),window.location.reload())):sessionStorage.removeItem("reloade"),JSON.parse(localStorage.getItem(t))}function getLastMessage(e){let t=null,s=null,n=!1;function a(o=999,r=500){return t&&t.message&&t.message.chat_id?(n||(data=e==Senders.CLIENT?prepareClientMessageData(t):prepareAgentMessageData(t),saveMessageToDb(data),n=!0),t):o<=0?t:void(!t||t.message&&t.message.chat_id||setTimeout((()=>{o--,r+=200,t={key:s,message:JSON.parse(localStorage.getItem(s))},a(o,r)}),r))}!function n(o=999,r=500){return t?(s=t.key,a(),t):o<=0?t:void(t||setTimeout((()=>{o--,r+=200,t=function(){const t=Object.keys(localStorage),s=collectMesssages(t,getMessagesKeys(t),e);return s.sort(((e,t)=>e.message.created_ts-t.message.created_ts)),s[s.length-1]}(),n(o,r)}),r))}()}function waitForJdivElement(e,t,s=200,n=10){const a=getJdivElementByClass(e);a?t(a):n>0&&setTimeout((()=>waitForJdivElement(e,t,s,n-1)),s)}function saveMessageToDb(e){fetch(API_SAVE_MSG_URL,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}function jivo_onMessageReceived(){getLastMessage(Senders.AGENT)}function jivo_onOpen(){waitForElement("jdiv[class^='inputContainer'] textarea").then((e=>{e&&e.addEventListener("keydown",(e=>{13==e.keyCode&&getLastMessage(Senders.CLIENT)}))})),waitForElement("jdiv[class^='sendButton']").then((e=>{e&&e.addEventListener("click",(()=>{getLastMessage(Senders.CLIENT)}))}))}function jivo_onChangeState(e){"chat"==e&&jivo_onOpen()}const tg_link_selector="jdiv a[href^='https://t.me'], jdiv a[href^='tg://']";function jivo_onClose(){waitForElement(tg_link_selector).then((e=>{e.href=TELEGRAM_BOT_LINK}))}waitForElement(tg_link_selector).then((e=>{e.href=TELEGRAM_BOT_LINK}));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.