Greasyfork in your language

Whenever a link to localized greasyfork page is clicked, redirect it to the specified language

2018-04-06 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name          Greasyfork in your language
// @description   Whenever a link to localized greasyfork page is clicked, redirect it to the specified language
// @namespace     wOxxOm.scripts
// @author        wOxxOm
// @version       3.0.4
// @match         https://greatest.deepsurf.us/*
// @exclude       https://greatest.deepsurf.us/system/*
// @run-at        document-start
// @grant         GM_getValue
// @grant         GM_setValue
// ==/UserScript==
/* jshint lastsemic:true, multistr:true, laxbreak:true, -W030, -W041, -W084 */

var language = GM_getValue('language', 'en');

maybeRedirect(location);

window.addEventListener('load', function _() {
  window.removeEventListener('load', _);
  var _timer, _title;
  document.getElementById('language-selector-locale').addEventListener('change', function() {
    GM_setValue('language', this.value);
    _title = _title || this.title;
    this.title = this.value + ' saved in ' + GM_info.script.name;
    clearTimeout(_timer);
    _timer = setTimeout(function() {
      this.title = _title;
      _title = null;
    }, 5000);
  });
});

window.addEventListener('mousedown', function(e) {
  var a = e.target.closest('a');
  if (a &&
      a.origin == 'https://greatest.deepsurf.us' &&
      a.pathname.lastIndexOf('/system/', 0) < 0 &&
      !a.pathname.match(/\/code\/.*?\.user\.js/))
    maybeRedirect(a);
});

function maybeRedirect(url) {
  var m = url.pathname.match(/^(?:\/(\w\w(?:-\w\w)?)(?:\/|$))?(.*)$/i);
  if (m[1] !== language) {
    var path = '/' + language + '/' + m[2].replace(/[?&]locale_override[^&]*/, '').replace(/^\//, '');
    url.href = url.origin + path +
      (path.indexOf('/forum/') > 0 ? '' : (path.indexOf('?') > 0 ? '&' : '?') + 'locale_override=1');
    console.log('Redirected greasyfork url language from %s to %s', m[1], language);
  }
}