-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add google-translate.js v1.0.4 using Earth emoji, add Google Analytic…
…s, some changes to the web install page design.
- Loading branch information
Showing
7 changed files
with
284 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
document.addEventListener("DOMContentLoaded", function () { | ||
var titleElement = document.querySelector('.md-header__title'); | ||
if (titleElement) { | ||
var customBlock = document.createElement('div'); | ||
customBlock.innerHTML = ` | ||
<div class="language-selector"> | ||
<div class="flag-icon">🌍</div> | ||
<div class="language-list" style="display: none;"> | ||
<a href="#" alt="EN" data-google-lang="en" class="language__img">🇬🇧</a> | ||
<a href="#" alt="UA" data-google-lang="uk" class="language__img">🇺🇦</a> | ||
<a href="#" alt="PL" data-google-lang="pl" class="language__img">🇵🇱</a> | ||
<a href="#" alt="IL" data-google-lang="iw" class="language__img">🇮🇱</a> | ||
<a href="#" alt="DE" data-google-lang="de" class="language__img">🇩🇪</a> | ||
<a href="#" alt="FR" data-google-lang="fr" class="language__img">🇫🇷</a> | ||
<a href="#" alt="ES" data-google-lang="es" class="language__img">🇪🇸</a> | ||
<a href="#" alt="IT" data-google-lang="it" class="language__img">🇮🇹</a> | ||
<a href="#" alt="NL" data-google-lang="nl" class="language__img">🇳🇱</a> | ||
<a href="#" alt="RU" data-google-lang="ru" class="language__img">🇷🇺</a> | ||
<a href="#" alt="ZH" data-google-lang="zh-CN" class="language__img">🇨🇳</a> | ||
</div> | ||
</div>`; | ||
customBlock.className = 'language'; | ||
titleElement.parentNode.insertBefore(customBlock, titleElement.nextSibling); | ||
} | ||
}); | ||
|
||
|
||
document.addEventListener('DOMContentLoaded', function () { | ||
var flagIcon = document.querySelector('.flag-icon'); | ||
var languageList = document.querySelector('.language-list'); | ||
|
||
flagIcon.addEventListener('click', function () { | ||
languageList.style.display = languageList.style.display === 'none' ? 'flex' : 'none'; | ||
}); | ||
|
||
document.addEventListener('click', function (event) { | ||
if (!flagIcon.contains(event.target) && !languageList.contains(event.target)) { | ||
languageList.style.display = 'none'; | ||
} | ||
}); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/*!*************************************************** | ||
* google-translate.js v1.0.4 | ||
* https://Get-Web.Site/ | ||
* author: Vitalii P. | ||
*****************************************************/ | ||
|
||
const googleTranslateConfig = { | ||
/* Original language */ | ||
lang: "en", | ||
|
||
/* The language we translate into on the first visit*/ | ||
/* Язык, на который переводим при первом посещении */ | ||
/* langFirstVisit: 'uk', */ | ||
|
||
/* Если скрипт не работает или работает неправильно, раскомментируйте и укажите основной домен в свойстве domain */ | ||
/* If the script does not work or does not work correctly, uncomment and specify the main domain in the domain property */ | ||
domain: "xyzroe.cc" | ||
}; | ||
|
||
document.addEventListener("DOMContentLoaded", (event) => { | ||
/* Подключаем виджет google translate */ | ||
/* Connecting the google translate widget */ | ||
let script = document.createElement("script"); | ||
script.src = `//translate.google.com/translate_a/element.js?cb=TranslateWidgetIsLoaded`; | ||
document.getElementsByTagName("head")[0].appendChild(script); | ||
}); | ||
|
||
function TranslateWidgetIsLoaded() { | ||
TranslateInit(googleTranslateConfig); | ||
} | ||
|
||
function TranslateInit(config) { | ||
if (config.langFirstVisit && !Cookies.get("googtrans")) { | ||
/* Если установлен язык перевода для первого посещения и куки не назначены */ | ||
/* If the translation language is installed for the first visit and cookies are not assigned */ | ||
TranslateCookieHandler("/auto/" + config.langFirstVisit); | ||
} | ||
|
||
let code = TranslateGetCode(config); | ||
|
||
TranslateHtmlHandler(code); | ||
|
||
if (code == config.lang) { | ||
/* Если язык по умолчанию, совпадает с языком на который переводим, то очищаем куки */ | ||
/* If the default language is the same as the language we are translating into, then we clear the cookies */ | ||
TranslateCookieHandler(null, config.domain); | ||
} | ||
|
||
/* Инициализируем виджет с языком по умолчанию */ | ||
/* Initialize the widget with the default language */ | ||
new google.translate.TranslateElement({ | ||
pageLanguage: config.lang, | ||
}); | ||
|
||
/* Вешаем событие клик на флаги */ | ||
/* Assigning a handler to the flags */ | ||
TranslateEventHandler("click", "[data-google-lang]", function (e) { | ||
TranslateCookieHandler( | ||
"/" + config.lang + "/" + e.getAttribute("data-google-lang"), | ||
config.domain | ||
); | ||
/* Перезагружаем страницу */ | ||
/* Reloading the page */ | ||
window.location.reload(); | ||
}); | ||
} | ||
|
||
function TranslateGetCode(config) { | ||
/* Если куки нет, то передаем дефолтный язык */ | ||
/* If there are no cookies, then we pass the default language */ | ||
let lang = | ||
Cookies.get("googtrans") != undefined && Cookies.get("googtrans") != "null" | ||
? Cookies.get("googtrans") | ||
: config.lang; | ||
return lang.match(/(?!^\/)[^\/]*$/gm)[0]; | ||
} | ||
|
||
function TranslateCookieHandler(val, domain) { | ||
/* Записываем куки /язык_который_переводим/язык_на_который_переводим */ | ||
/* Writing down cookies /language_for_translation/the_language_we_are_translating_into */ | ||
Cookies.set("googtrans", val); | ||
Cookies.set("googtrans", val, { | ||
domain: "." + document.domain, | ||
}); | ||
|
||
if (domain == "undefined") return; | ||
/* записываем куки для домена, если он назначен в конфиге */ | ||
/* Writing down cookies for the domain, if it is assigned in the config */ | ||
Cookies.set("googtrans", val, { | ||
domain: domain, | ||
}); | ||
|
||
Cookies.set("googtrans", val, { | ||
domain: "." + domain, | ||
}); | ||
} | ||
|
||
function TranslateEventHandler(event, selector, handler) { | ||
document.addEventListener(event, function (e) { | ||
let el = e.target.closest(selector); | ||
if (el) handler(el); | ||
}); | ||
} | ||
|
||
function TranslateHtmlHandler(code) { | ||
/* Получаем язык на который переводим и производим необходимые манипуляции с DOM */ | ||
/* We get the language to which we translate and produce the necessary manipulations with DOM */ | ||
if (document.querySelector('[data-google-lang="' + code + '"]') !== null) { | ||
document | ||
.querySelector('[data-google-lang="' + code + '"]') | ||
.classList.add("language__img_active"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* Виджет назначает height: 100% , что может привести к непредксказуемому результату, если вы этого не планровали */ | ||
|
||
html { | ||
height: auto !important; | ||
} | ||
|
||
/* Фиксируем позицию body, которую меняет панель гугла */ | ||
|
||
body { | ||
top: 0 !important; | ||
position: static !important; | ||
} | ||
|
||
/* Прячем панель гугла */ | ||
|
||
.skiptranslate { | ||
display: none !important; | ||
} | ||
|
||
/* Убираем подсветку ссылок */ | ||
|
||
.goog-text-highlight { | ||
background-color: inherit; | ||
box-shadow: none; | ||
box-sizing: inherit; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,14 +147,21 @@ extra: | |
link: https://github.com/xyzroe | ||
- icon: fontawesome/solid/paper-plane | ||
link: https://t.me/xyzroe | ||
analytics: | ||
provider: google | ||
property: G-VWB99VELNE | ||
|
||
extra_javascript: | ||
- https://cdn.jsdelivr.net/npm/[email protected]/src/tablesort.min.js | ||
- assets/javascripts/tables.js | ||
- assets/javascripts/google-translate.js | ||
- https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js | ||
- assets/javascripts/custom.js | ||
|
||
extra_css: | ||
- assets/stylesheets/custom.css | ||
- https://cdn.jsdelivr.net/gh/rod2ik/cdn@main/mkdocs/css/massilia-columns.css | ||
- assets/stylesheets/google-translate.css | ||
|
||
nav: | ||
- Home: index.md | ||
|