Reddit Auto Translator

Automatically switches to the Japanese translation when opening a Reddit post that supports translation.

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

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

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.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

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!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

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

// ==UserScript==
// @name            Reddit Auto Translator
// @name:ja         Reddit自動翻訳
// @namespace       https://greasyfork.org/users/1324207
// @match           https://www.reddit.com/*
// @version         1.0
// @author          Lark8037
// @description     Automatically switches to the Japanese translation when opening a Reddit post that supports translation.
// @description:ja  翻訳対応済みのRedditの投稿を開いた際に自動で日本語翻訳版に切り替えます。
// @run-at          document-start
// @license         MIT
// @icon            https://reddit.com/favicon.ico
// ==/UserScript==

(()=>{
  'use strict';
  let l='';
  setInterval(()=>{
    let h=location.href;
    if(h===l)return;
    l=h;
    let u=new URL(h),p=u.pathname;
    if(!/^\/r\/[^/]+\/comments\//.test(p))return;
    let k='r_tl_'+p,s=sessionStorage,st=s.getItem(k),tl=u.searchParams.get('tl');
    if(tl=='ja'){
      if(+st>0&&Date.now()-st>10000)s.removeItem(k);
    }else if(st!='failed'){
      if(+st>0&&Date.now()-st<10000){
        s.setItem(k,'failed');
      }else{
        s.setItem(k,Date.now());
        u.searchParams.set('tl','ja');
        location.replace(u);
      }
    }
  },200);
})();