1(() => { 2 const widgetSrc = document.getElementsByClassName('medflexMedtochkaWidgetButton')[0].dataset.src 3 const widgetUrl = new URL(widgetSrc) 4 const searchParams = new URLSearchParams(widgetUrl.search) 5 const user = searchParams.get('user') 6 7 if (!user) { 8 return 9 } 10 11 const BASE_URL = widgetUrl.origin 12 const MT_URL = `https://app.medtochka${BASE_URL.includes('stage') ? '-stage' : ''}.ru/` 13 const WIDGET_SETTINGS_URL = `${BASE_URL}/utils/mt_widget_settings/` 14 const CDN_AXIOS_ULR = 'https://unpkg.com/axios/dist/axios.min.js' 15 16 function loadScript(src, callback) { 17 const script = document.createElement('script') 18 19 script.src = src 20 21 script.onload = () => { 22 callback() 23 } 24 25 document.head.append(script) 26 } 27 28 function createMedtochkaWidgetButton(isRecommended) { 29 const widget = document.createElement('button') 30 31 widget.classList.add('medflex-medtochka-widget') 32 33 widget.innerHTML = ` 34 <img 35 src="${BASE_URL}/static/images/${isRecommended ? 'medtochka-icon.svg' : 'medtochka-icon-white.svg'}" 36 alt="" 37 style="margin-right: 8px" 38 /> 39 ÐиÑнÑй ÐºÐ°Ð±Ð¸Ð½ÐµÑ 40 ` 41 42 widget.onmousedown = (ev) => { 43 const circle = document.createElement('div') 44 const offset = widget.getBoundingClientRect() 45 const x = ev.pageX - offset.left - document.body.scrollLeft 46 const y = ev.pageY - offset.top - document.body.scrollTop 47 48 circle.setAttribute( 49 'style', 50 ` 51 background: #${isRecommended ? '000' : 'fff'}; 52 width: 10px; 53 height: 10px; 54 opacity: 0; 55 border-radius: 100em; 56 position: absolute; 57 top: ${y}px; 58 left: ${x}px; 59 animation: ripple 0.7s 1 ease-in-out; 60 ` 61 ) 62 widget.append(circle) 63 ev.stopPropagation() 64 setTimeout(() => { 65 circle.parentNode.removeChild(circle) 66 }, 400) 67 } 68 69 widget.onclick = () => { 70 // source=lpu_site - обÑзаÑелÑÐ½Ð°Ñ Ð¼ÐµÑка Ð´Ð»Ñ Ð°Ð½Ð°Ð»Ð¸Ñики ÐедТоÑки 71 72 window.open(`${MT_URL}?lpu_hash=${user}&source=lpu_site`, '_blank') 73 } 74 75 return widget 76 } 77 78 function setWidgetsCss(isRecommended, bgColor) { 79 const css = document.createElement('style') 80 81 css.innerText = ` 82 .medflex-medtochka-widget { 83 box-sizing: border-box; 84 display: flex; 85 align-items: center; 86 padding: 6px 11px; 87 margin-top: 3px; 88 border: 1px solid gray; 89 border-radius: 4px; 90 background-color: #${isRecommended ? 'fff' : bgColor}; 91 color: #${isRecommended ? '1A5DD0' : 'fff'}; 92 font-size: 12px; 93 font-weight: 700; 94 font-family: Inter, sans-serif; 95 position: relative; 96 overflow: hidden; 97 cursor: pointer; 98 user-select: none; 99 } 100 101 .medflex-medtochka-widget:hover { 102 box-shadow: 0px 3px 5px -2px rgba(0, 0, 0, 0.2), 0px 3px 7px rgba(0, 0, 0, 0.14), 0px 1px 8px rgba(0, 0, 0, 0.08); 103 } 104 105 @keyframes ripple { 106 0% { 107 transform: scale(0.01); 108 opacity: 0.2; 109 } 110 80% { 111 transform: scale(100); 112 opacity: 0; 113 } 114 } 115 ` 116 117 document.getElementsByTagName('head')[0].append(css) 118 } 119 120 function setWidgetToPage(isRecommended, bgColor) { 121 const containers = document.getElementsByClassName('medflexMedtochkaWidgetButton') 122 123 124 if (!containers) { 125 return 126 } 127 Array.from(containers).forEach((container) => { 128 console.log(container); 129 const medtochkaWidgetButton = createMedtochkaWidgetButton(isRecommended) 130 container.append(medtochkaWidgetButton) 131 }) 132 133 setWidgetsCss(isRecommended, bgColor) 134 } 135 136 function getWidgetSettings() { 137 return window.axios({
138 url: WIDGET_SETTINGS_URL, 139 method: 'GET', 140 headers: {user} 141 }) 142 .then(({ data }) => data) 143 } 144 145 async function widgetSetup() { 146 try { 147 const { 148 is_active: isActive, 149 use_recommended_colors: isRecommended, 150 bg_color: bgColor 151 } = await getWidgetSettings() 152 153 if (!isActive) { 154 return 155 } 156 157 setWidgetToPage(isRecommended, bgColor) 158 } catch { 159 } 160 } 161 162 if (!window.axios) { 163 loadScript(CDN_AXIOS_ULR, () => { 164 widgetSetup() 165 }) 166 } else { 167 widgetSetup() 168 } 169})()
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.