Toggle DLsite Language

Switch between english and japanese language in DLsite

06.04.2021 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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