krasnovpro / Adobe Help Language Switch

// ==UserScript==
// @name         Adobe Help Language Switch
// @license      MIT
// @namespace    https://openuserjs.org/users/krasnovpro/
// @version      2020.06.04
// @description  Easily switching Adobe Help language.
// @author       krasnovpro
// @include      /^https?://helpx?\.adobe\.com/.*$/
// @updateURL    https://openuserjs.org/meta/krasnovpro/Adobe_Help_Language_Switch.meta.js
// @grant        none
// ==/UserScript==

(() => {
  let from = /(\.com|\.html|\?topic=)\//g, to = "$1/ru/";
  function lang(){
    if (document.URL.match(/\.com\/ru\//)) {
      from = /(\.com|\.html|\?topic=)\/ru\//g;
      to = "$1/";
      document.querySelector("#lang").innerText = "EN";
    }
    document.querySelector("#lang").setAttribute("href", document.URL.replace(from, to));
  };
  document.body.insertAdjacentHTML('beforeend', `
  <a id="top" href="#" title="top"></a><a id="lang">RU</a><style>
  #lang {
    background: #9993;
    border-radius: 0 5px 5px 0;
    display: block;
    color: white;
    font-family: sans-serif;
    font-size: 9px;
    font-weight: bold;
    left: 0;
    margin-top: 5px;
    padding: 5px 5px 3px 7px;
    position: fixed;
    top: 0;
    width: 26px;
    z-index: 999 !important;
  }
  #lang:hover {background: #999;}
  #top {
    background: transparent;
    color: transparent;
    display: block;
    position: fixed;
    height: 100%;
    top: 0;
    width: 15px;
    z-index: 998 !important;
  }
  </style>`.trim());
  document.querySelector("#lang").addEventListener("mouseleave", (event) => {lang()});
  lang();
})();