AddLinkToNewAtcoder

ja

As of 2017-11-24. See the latest version.

// ==UserScript==
// @name         AddLinkToNewAtcoder
// @namespace    AddLinkToNewAtcoder
// @version      1.3
// @author       Luzhiled
// @description  ja
// @include      http://*atcoder.jp/*
// @include      https://*atcoder.jp/*
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  function ConvertToNewAtcodersURL() {
    let pathName = location.pathname;
    let query = location.search;
    if (pathName.match(/settings/) || pathName.match(/users/)) {
      return 'https://beta.atcoder.jp' + pathName;
    }
    if (location.href.match(/contest.atcoder.jp/)) {
      let contestName = location.href.replace(/^https?:\/\//, '').split('.')[0];
      pathName = pathName.replace(/assignments/g, "tasks");
      pathName = pathName.replace(/\/all/g, "");
      query = query.replace(/user_screen_name/g, "f.User");
      pathName = pathName.replace(/editorial/g, "");
      pathName = pathName.replace(/statistics/g, "");
      return 'https://beta.atcoder.jp/contests/' + contestName + pathName + query;
    } else {
      console.log(pathName);
      console.log(query);
      pathName = pathName.replace(/contest/g, "contests");
      pathName = pathName.replace(/user/g, "users");
      query = query.replace(/categories/g, "category");
      query = query.replace(/p=/g, "page=");
      return 'https://beta.atcoder.jp' + pathName + query;
    }
  }

  function AddLinkToNewAtcoder() {
    if (location.href.match(/contest.atcoder.jp/)) {
      $('div.nav-collapse').prepend(`
        <ul class="nav">
          <li class="divider-vertical"></li>
          <li><a href="${ConvertToNewAtcodersURL()}"><span class="lang lang-selected"><span class="lang-en lang-child hidden-lang">go to beta.atcoder.jp</span><span class="lang-ja lang-child">Beta版へ</span></span></a></li>
        </ul>
      `);
    }
    else {
      $('ul.nav.navbar-nav').not('.navbar-right').append(`<li><a href="${ConvertToNewAtcodersURL()}">Beta版へ</a></li>`);
    }
  }

  // function AddLinkToAtcoder() {}

  if (location.href.match(/beta.atcoder.jp/)) {
    // AddLinkToAtcoder();
  } else {
    AddLinkToNewAtcoder();
  }

})();