Toggle DLsite Language

Switch between english and japanese language in DLsite

Stan na 06-04-2021. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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;
  });
})();