Toggle DLsite Language

Switch between english and japanese language in DLsite

Verze ze dne 06. 04. 2021. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Toggle DLsite Language
// @namespace    zero.toogledlsitelan
// @description  Switch between english and japanese language in DLsite
// @include      *://www.dlsite.com/*
// @version      1.4
// @grant        none
// @project page https://greasyfork.org/en/scripts/402452-toggle-dlsite-language
// ==/UserScript==

(function () {
  var url = window.location.href;
  var cookies = document.cookie.split(';');
  var locale = '';

  // Get locale from cookies
  cookies.forEach(element => {
    if (element.includes('locale'))
      locale = element.substring(element.indexOf('=') + 1);
  });

  // If locale isn't found finish script and give error
  if (locale === '') {
    console.log("DLsite Toogle couldn't find locale cookie, stopping script");
    return false;
  }

  // Add toggle button
  if (url.includes('maniax')) {
    var navlink = document.getElementsByClassName('floorNavLink');
    let enButton = '<div class="floorNavLink-item type-general" style="width:125px"><a style="font-weight:bold"' +
                   'id="toggle">Toggle Site (EN)</a></div>';
    let jpButton = '<div class="floorNavLink-item type-general" style="width:125px"><a style="font-weight:bold"' +
                   'id="toggle">Toggle Site (JP)</a></div>';

    if (url.includes('?locale=')) {
      if (url.includes('ja_JP')) {
        navlink[0].innerHTML =  enButton + navlink[0].innerHTML;
      } else {
        navlink[0].innerHTML = jpButton + navlink[0].innerHTML;
      }
    } else {
      if (locale === 'ja-jp') {
        navlink[0].innerHTML = enButton + navlink[0].innerHTML;
      } else {
        navlink[0].innerHTML = jpButton + navlink[0].innerHTML;
      }
    }
  }

  // Create link on toggle button once rest of document is loaded
  document.addEventListener('DOMContentLoaded', function () {
    var toggle = document.getElementById('toggle');

    if (url.includes('?locale=')) {
      if (url.includes('ja_JP')) url = url.replace('ja_JP', 'en_US');
      else url = url.replace('en_US', 'ja_JP');
    } else {
      if (locale === 'ja-jp') url += '?locale=en_US';
      else url += '?locale=ja_JP';
    }

    toggle.href = url;
  });
})();