洛谷用户查找

在洛谷主页添加类似Codeforces的Find User(暂不支持自动补全)

当前为 2019-09-17 提交的版本,查看 最新版本

// ==UserScript==
// @name         洛谷用户查找
// @version      0.1.2
// @description  在洛谷主页添加类似Codeforces的Find User(暂不支持自动补全)
// @author       叶ID (KMnO4y_Fish, yezhiyi9670)
// @match        *://www.luogu.org/
// @match        *://www.luogu.org/
// @namespace    https://greasyfork.org/zh-CN/users/370663-yezhiyi9670
// ==/UserScript==

(function () {
  $('document').ready(function(){setTimeout(function () {
    $sidebar = $('#app-old .lg-index-content .lg-right');
    $firstele = $($sidebar.children()[0]);
    // console.log($firstele);
    $finder = $(`
      <div class="lg-article" id="find-user-form">
        <h2>查找用户</h2>
        <form id="find-user-form">
          <input type="text" class="am-form-field" name="finder-uid" placeholder="用户名或uid" autocomplete="off" />
        </form>
        <button class="am-btn am-btn-sm am-btn-primary" style="margin-top:16px;visibility:hidden">查找</button>
        <button class="am-btn am-btn-sm am-btn-primary lg-right" id="find-user-button" style="margin-top:16px;">查找</button>
      </div>
    `);
    $finder.insertAfter($firstele);
    var find_func = function() {
      $('#find-user-button').addClass('am-disabled');
      $.get("/space/ajax_getuid?username=" + $('[name=finder-uid]')[0].value,
        function (data) {
          var arr = eval('(' + data + ')');
          if (arr['code'] != 200) {
            $('#find-user-button').removeClass('am-disabled');
            show_alert("好像哪里有点问题", arr["message"]);
          }
          else {
            location.href = "/space/show?uid="+arr['more']['uid'];
          }
        }
      );
      return false;
    };
    $('#find-user-button').click(find_func);
    $('#find-user-form').submit(find_func);
    
  },500)});
})();