Toggle DLsite Language

Switch between english and japanese language in DLsite

Ajankohdalta 6.4.2021. Katso uusin versio.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

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