PageSourceSearch

https://donagra.ru/js/yatranslate.js

js donagra.ru collected 2026-10-08 09:30:02 UTC 3,405 bytes, 79 lines download raw bytes

1/*!***************************************************
2 * yatranslate.js v1.0.0
3 * https://Get-Web.Site/
4 * author: Vitalii P.
5 *****************************************************/
6
7const yatranslate = {
8    /* Original language */
9    lang: "ru",
10    /* The language we translate into on the first visit */
11    /* Язык, на который переводим при первом посещении */
12    // langFirstVisit: 'en',
13};
14
15document.addEventListener('DOMContentLoaded', function () {
16    // Start
17    yaTranslateInit();
18})
19
20function yaTranslateInit() {
21
22    if (yatranslate.langFirstVisit && !localStorage.getItem('yt-widget')) {
23        /* Если установлен язык перевода для первого посещения и в localStorage нет yt-widget */
24        /* If the translation language is installed for the first visit and in localStorage no yt-widget */
25        yaTranslateSetLang(yatranslate.langFirstVisit);
26    }
27
28    // Подключаем виджет yandex translate
29    // Connecting the yandex translate widget
30    let script = document.createElement('script');
31    script.src = `https://translate.yandex.net/website-widget/v1/widget.js?widgetId=ytWidget&pageLang=${yatranslate.lang}&widgetTheme=light&autoMode=false`;
32    document.getElementsByTagName('head')[0].appendChild(script);
33
34    // Получаем и записываем язык на который переводим
35    // We get and write down the language into which we translate
36    let code = yaTranslateGetCode();
37
38    // Показываем текущий язык в меню
39    // Show the current language in the menu
40    yaTranslateHtmlHandler(code);
41
42    // Вешаем событие клик на флаги
43    // We hang the event click on the flags
44    yaTranslateEventHandler('click', '[data-ya-lang]', function (el) {
45        yaTranslateSetLang(el.getAttribute('data-ya-lang'));
46        // Перезагружаем страницу
47        // Reloading the page
48        window.location.reload();
49    })
50}
51
52function yaTranslateSetLang(lang) {
53    // Записываем выбранный язык в localStorage объект yt-widget 
54    // Writing the selected language to localStorage 
55    localStorage.setItem('yt-widget', JSON.stringify({
56        "lang": lang,
57        "active": true
58    }));
59}
60
61function yaTranslateGetCode() {
62    // Возвращаем язык на который переводим
63    // Returning the language to which we are translating
64    return (localStorage["yt-widget"] != undefined && JSON.parse(localStorage["yt-widget"]).lang != undefined) ? JSON.parse(localStorage["yt-widget"]).lang : yatranslate.lang;
65}
66
67function yaTranslateHtmlHandler(code) {
68    // Получаем язык на который переводим и производим необходимые манипуляции с DOM
69    // We get the language to which we translate and produce the necessary manipulations with DOM 
70    document.querySelector('[data-lang-active]').innerHTML = `<img class="lang__img lang__img_select" src="./images/lang/lang__${code}.png" alt="${code}">`;
71    document.querySelector(`[data-ya-lang="${code}"]`).remove();
72}
73
74function yaTranslateEventHandler(event, selector, handler) {
75    document.addEventListener(event, function (e) {
76        let el = e.target.closest(selector);
77        if (el) handler(el);
78    });
79}

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.