跳到正文

剪贴板

剪贴板 40hfk7qm

原文
剪贴板信息

剪贴板信息

收录
更新
油猴上好用的代码——洛谷版\color{steelblue}\colorbox{steelblue}{\boxed{\Huge\color{cadetblue}\colorbox{powderblue}{\text{油猴上好用的代码——洛谷版}}}}

1.洛谷首页置项助手

洛谷首页顶部置顶任意链接(1个)

代码
// ==UserScript==
// @name         洛谷首页置顶助手
// @namespace    http://tampermonkey.net/
// @license      MIT
// @version      1.3.1
// @description  洛谷首页顶部置顶任意链接(1个)
// @author       神虎
// @match        https://www.luogu.org
// @match        https://www.luogu.com.cn
// @require      https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==



(function() {
    'use strict';
    $(function(){
        function setLink()
        {
            var link = prompt("请输入链接地址(点按取消以不变)");
            if (link == undefined)
                { return; }
            var text = prompt("请输入链接文字");
            GM_setValue("user_link", link);
            GM_setValue("user_link_text", text);
            location.reload();
        }
        var title = $(".link-container");
        var prelink = GM_getValue("user_link");
        var pretext = GM_getValue("user_link_text")
        var link = '<a data-v-44f42e53="" data-v-02d4dc3d="" href="' + prelink + '" target="_blank" class="header-link color-none"><span data-v-02d4dc3d="" data-v-44f42e53="" style="color: rgb(38, 38, 38);">' + pretext + '</span></a>';
        var button = document.createElement("button");
        button.innerText = '编辑';
        button.className = 'am-btn am-btn-sm am-btn-primary'
        button.addEventListener('click', setLink);
        var helper = '<span data-v-86f2b1fc data-v-5b9d45a0 class="helper"></span>';
        console.log(button);
        if (pretext != undefined)
        {
            title.append(link, helper);
        }
        title.append(button, helper);
    });
})();

2.万能搜索

洛谷题目跳转器优化

代码
// ==UserScript==
// @name         万能搜索
// @namespace    n/a
// @version      0.0.2.8
// @description  洛谷题目跳转器优化
// @author       神虎
// @match        https://www.luogu.com.cn
// @match        https://www.luogu.com.cn/
// @match        https://www.luogu.com.cn/#feed
// @match        https://www.luogu.com.cn/#feed/
// @match        http://www.luogu.com.cn
// @match        http://www.luogu.com.cn/
// @match        http://www.luogu.com.cn/#feed
// @match        http://www.luogu.com.cn/#feed/
// @grant        none
// ==/UserScript==

(function()
{
    'use strict';

    var href = "https://www.luogu.com.cn/problem";

    function jumpfn()
    {
        var target = document.getElementsByClassName("am-form-field")[0].value;
        if(target === "")return;

        var go = href + "/list?keyword=" + target + "&content=false";

        location.href = go;
    }

    function searchfn()
    {
        var target = document.getElementsByClassName("am-form-field")[0].value;
        if(target === "")return;

        var targetu = target.toUpperCase();
        var go = href;

        if(target.match(/^[1-9][0-9][0-9][0-9]+$/) == target)go = go + "/P" + target;
        else if(targetu.match(/^[0-9]+[A-Z][0-9]?$/) == targetu)go = go + "/CF" + targetu;
        else if(targetu.match(/^(?:U|P|T|CF|SP|AT|UVA)[0-9]+[A-Z]?[0-9]?$/) == targetu)go = go + "/" + targetu;
        else{go = href + "/list?keyword=" + target + "&content=false";}

        location.href = go;
    }

    var locations =
        document.getElementsByClassName("lg-index-content")[0]
    .getElementsByClassName("lg-article lg-index-stat")[0]
    .getElementsByClassName("am-btn am-btn-primary am-btn-sm")[0]
    .parentNode;

    var button = document.createElement("button");
    button.className = "am-btn am-btn-success am-btn-sm";
    button.name = "gotosearch";
    button.id = "gotosearch";
    button.innerHTML = "搜索";
    button.onclick = function(){jumpfn();};

    locations.appendChild(button);

    document.getElementsByClassName("am-form-field")[0].placeholder = "输入题号或题目名";
    document.getElementsByClassName("am-form-field")[0].onkeyup = function(event){if(event.keyCode === 13){searchfn();}};

    document.getElementsByClassName("lg-article lg-index-stat")[0].getElementsByTagName("h2")[0].innerHTML = "万能跳转";

    document.getElementsByName("gotorandom")[0].innerHTML = "随机";
})();

3.Luogu Problem Jumper

双击题号,自动跳转

代码
// ==UserScript==
// @name         Luogu Problem Jumper
// @version      2.0
// @description  双击题号,自动跳转
// @author       神虎
// @match        https://www.luogu.com.cn/*
// @match        https://*.blog.luogu.com.cn/*
// @grant        none
// @namespace    Anguei
// ==/UserScript==

function isProblemId(text) {
  if (text.match(/AT[0-9]{1,4}/) == text) return true;
  if (text.match(/CF[0-9]{1,4}[A-Z][0-9]{0,1}/) == text) return true;
  if (text.match(/SP[0-9]{1,5}/) == text) return true;
  if (text.match(/P[0-9]{4}/) == text) return true;
  if (text.match(/UVA[0-9]{1,5}/) == text) return true;
  if (text.match(/U[0-9]{1,6}/) == text) return true;
  if (text.match(/T[0-9]{1,6}/) == text) return true;
  return false;
}

function jump() {
  var selection = window.getSelection();
  var selected = selection.toString().replace(' ', '').toUpperCase();
  var url;

  if (event.ctrlKey) {
    var myBlog = document.querySelectorAll('.ops>a[href*=blog]')[0];
    url = myBlog.href + 'solution-';
  } else {
    url = 'https://www.luogu.com.cn/problem/';
  }

  if (isProblemId(selected)) {
    window.open(url + selected);
  }
}

function jumpMobile() {
  var selection = window.getSelection();
  var selected = selection.toString().replace(' ', '').toUpperCase();
  var url = window.location.href;

  if (isProblemId(selected)) {
    var parent = selection.anchorNode.parentNode;
    if (parent.className == 'am-comment-bd' &&
      parent.parentNode.innerHTML.match(/href="\/space\/show\?uid=3"/) != undefined) {
      window.open('https://' + url.match(/uid=([0-9]+)/)[1] + '.blog.luogu.com.cn/solution-' + selected);
    } else {
      window.open('https://www.luogu.com.cn/problem/' + selected);
    }
  }
}

function checkMobile() {
  var ua = navigator.userAgent;
  return window.screen.width / window.screen.height < 0.6 ||
      ua.indexOf('Android') > -1;
}

if (checkMobile()) {
  document.addEventListener('selectionchange', jumpMobile);
} else {
  document.ondblclick = jump;
}

4.神虎牌删犇器

自动删犇

详情这里

5.神虎牌犇犇屏蔽器

快捷屏蔽他人

详情这里

6.洛谷显示他人咕值

在洛谷中显示他人的咕值详情(仅限rk前1000用户)

C++
// ==UserScript==
// @name         洛谷显示他人咕值
// @version      0.2.4
// @description  在洛谷中显示他人的咕值详情(仅限rk前1000用户)
// @author       神虎
// @match        *://www.luogu.com.cn/user/*
// @namespace    https://greasyfork.org/zh-CN/users/370663-yezhiyi9670
// @require      https://code.jquery.com/jquery-3.4.1.min.js
// ==/UserScript==

(function () {
  $('document').ready(function(){setTimeout(function(){
    setInterval(function() {
      if($('.add-rating-inspector').length) return

      // console.log('iakioi');
      var $sidebar = $('section.side');
      var $firstele = $($sidebar.children()[0]);
      var $setting = $('.btn.btn-config.lfe-form-sz-middle');
      if($setting.length) return; // 是自己的账户
      var $rankbox = $('.stats.normal :nth-child(5) :nth-child(2)');
      if(!$rankbox.length) return; // 已开启完全隐私保护
      console.log($rankbox);

      $show_ele = $(`
        <div data-v-796309f8 class="card padding-default add-rating-inspector">
          <h3 class="lfe-h3"><svg aria-hidden="true" focusable="false" data-prefix="fad" data-icon="dice-d6" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" class="svg-inline--fa fa-dice-d6 fa-w-14" style="color: rgb(52, 152, 219);"><g data-v-d4260d54="" data-v-796309f8="" class="fa-group"><path data-v-d4260d54="" data-v-796309f8="" fill="currentColor" d="M25.87 124.42a8.54 8.54 0 0 1-.06-14.42l166-100.88a61.72 61.72 0 0 1 64.43 0L422.19 110a8.54 8.54 0 0 1-.05 14.47L224 242.55z" class="fa-secondary"></path><path data-v-d4260d54="" data-v-796309f8="" fill="currentColor" d="M0 161.83v197.7c0 23.77 12.11 45.74 31.79 57.7L184 509.71c10.67 6.48 24.05-1.54 24.05-14.44V271.46L12 154.58c-5.36-3.17-12 .85-12 7.25zm436-7.25L240 271.46v223.82c0 12.89 13.39 20.92 24.05 14.43l152.16-92.48c19.68-12 31.79-33.94 31.79-57.7v-197.7c0-6.41-6.64-10.42-12-7.25z" class="fa-primary"></path></g></svg>
            &nbsp;
            咕值
          </h3>
          <p id="add-rating-error" style="display:none;margin-bottom:0;">该用户排名大于1000,不能获取其咕值详情。</p>
          <button data-v-dc8d06e8="" data-v-4929b25c="" data-v-796309f8="" solid="" class="btn" id="add-rating-button" style="border-color: rgb(255, 255, 255); color: rgb(255, 255, 255); background-color: rgb(52, 152, 219);margin-top:16px;padding:4px 10px;">显示</button>
          <div id="add-rating-showbox" style="display:none;">
            <div data-v-d4260d54="" data-v-796309f8="" class="flex-lr info-row" style="margin-bottom: 0.5em;">
              <span data-v-d4260d54="" data-v-796309f8="">基础信用</span>
              <span data-v-d4260d54="" data-v-796309f8="" class="info-content add-rating-basic">-</span>
            </div>
            <div data-v-d4260d54="" data-v-796309f8="" class="flex-lr info-row" style="margin-bottom: 0.5em;">
              <span data-v-d4260d54="" data-v-796309f8="">练习情况</span>
              <span data-v-d4260d54="" data-v-796309f8="" class="info-content add-rating-practice">-</span>
            </div>
            <div data-v-d4260d54="" data-v-796309f8="" class="flex-lr info-row" style="margin-bottom: 0.5em;">
              <span data-v-d4260d54="" data-v-796309f8="">社区贡献</span>
              <span data-v-d4260d54="" data-v-796309f8="" class="info-content add-rating-community">-</span>
            </div>
            <div data-v-d4260d54="" data-v-796309f8="" class="flex-lr info-row" style="margin-bottom: 0.5em;">
              <span data-v-d4260d54="" data-v-796309f8="">比赛情况</span>
              <span data-v-d4260d54="" data-v-796309f8="" class="info-content add-rating-contest">-</span>
            </div>
            <div data-v-d4260d54="" data-v-796309f8="" class="flex-lr info-row" style="margin-bottom: 0.5em;">
              <span data-v-d4260d54="" data-v-796309f8="">获得成就</span>
              <span data-v-d4260d54="" data-v-796309f8="" class="info-content add-rating-achievement">-</span>
            </div>
            <div data-v-d4260d54="" data-v-796309f8="" class="flex-lr info-row" style="margin-bottom: 0.5em;">
              <span data-v-d4260d54="" data-v-796309f8="">总咕值</span>
              <span data-v-d4260d54="" data-v-796309f8="" class="info-content add-rating-total">-</span>
            </div>
            <div data-v-d4260d54="" data-v-796309f8="" class="flex-lr info-row" style="margin-bottom: 0.5em;">
              <span data-v-d4260d54="" data-v-796309f8="">更新日期</span>
              <span data-v-d4260d54="" data-v-796309f8="" class="info-content add-rating-date">-</span>
            </div>
          </div>
        </div>
        <style>
          .info-content[data-v-d4260d54][data-v-796309f8] {
            color: rgba(0, 0, 0, 0.45);
            float: right;
          }
        </style>
      `);
      $show_ele.insertAfter($firstele);

      var ranktxt = $rankbox.html().trim();

      var show_result = function(res, date) {
        $('.add-rating-basic').html(res['basicRating']);
        $('.add-rating-practice').html(res['practiceRating']);
        $('.add-rating-community').html(res['socialRating']);
        $('.add-rating-contest').html(res['contestRating']);
        $('.add-rating-achievement').html(res['prizeRating']);
        $('.add-rating-total').html(res['rating']);
        $('.add-rating-date').html(date);
      }
      var another_show_func = function() {
      };
      var show_error = function(str) {
        $('#add-rating-error').css('display','block');
        $('#add-rating-error').html(str);
        $('#add-rating-button')[0].removeAttribute('disabled');
      };
      if(ranktxt.indexOf("k")!=-1 || ranktxt > 1000) {
        $('#add-rating-error').css('display','block');
        $('#add-rating-button').click(another_show_func);
        $('#add-rating-button').css('display','none');
      }
      else if(ranktxt.indexOf("-")!=-1) {
        $('#add-rating-error').css('display','block');
        $('#add-rating-error').html('用户没有排名,不能获取其咕值详情。');
        $('#add-rating-button').click(another_show_func);
        $('#add-rating-button').css('display','none');
      }
      else {
        var tt_user_rk = ranktxt;
        // show_alert("用户排名:"+tt_user_rk);
        var tt_rk_page = Math.floor((tt_user_rk-1)/50) + 1;
        // show_alert("排名信息在第"+tt_rk_page+"页");

        var tt_username = location.href.match(/^(\w+):\/\/www.luogu.com.cn\/user\/(\d+)/)[2];
        // else show_alert("调试","用户uid:"+tt_username);

        var akioi = function(pageid,remain = 10){
          if(remain == 0 || pageid>20) {
            if(pageid<=20) show_error("找不到用户的咕值信息,请刷新重试。");
            else show_error("找不到用户的咕值信息。");
            return;
          }
          $('#add-rating-button')[0].setAttribute('disabled','disabled');
          var url = "https://www.luogu.com.cn/ranking?page="+pageid+"&_contentOnly=1";
          console.log("获取排名网址:",url);
          $.get(url,
            function (data) {
              // var arr = eval('(' + data + ')');
              // var arr = JSON.parse(data);
              var arr = data;
              console.log("用户数据:",arr);
              if (arr['code'] != 200) {
                show_error(arr["message"]);
              }
              else {
                var dat = arr['currentData']['rankList']['result'];
                for(var i = 0;i < 50;i++) {
                  if(!dat[i]) continue;
                  if(dat[i]['user']['uid'] == tt_username) {
                    // show_alert("找到用户");
                    $('#add-rating-button').css("display",'none');
                    /*$(function () {
                      $('#add-rating-display').highcharts({
                        chart:{
                          polar:true,type:'line',backgroundColor:"rgba(0,0,0,0)"
                        },
                        pane:{size:'36%'},title:{text:"",floating:true},legend:{enabled:false},credits:{enabled:false},
                        xAxis: {
                          categories: ['基础信用', '练习情况', '社区贡献', '比赛情况', '获得成就'],
                          tickmarkPlacement: 'on',
                          lineWidth: 0
                        },
                        yAxis: {
                          gridLineInterpolation: 'polygon',
                          lineWidth: 0,
                          min: 0,
                          max: 100
                        },
                        tooltip: {
                          shared: true,
                          pointFormat: '<b>{point.y:,.0f}</b>/100<br/>'
                        },
                        series: [{
                          name: '咕值',
                          data: [
                            dat[i]['basicRating'],
                            dat[i]['practiceRating'],
                            dat[i]['socialRating'],
                            dat[i]['contestRating'],
                            dat[i]['prizeRating']
                          ],
                          pointPlacement: 'on'
                        }]
                      });
                    });*/
                    function getdate(t) {
                      var now = new Date(t),
                      y = now.getFullYear(),
                      m = now.getMonth() + 1,
                      d = now.getDate();
                      return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d);
                    }
                    show_result(dat[i],getdate(dat[i]['calculateTime']*1000));
                    // $('#add-rating-date').html(getdate(dat[i]['calculateTime']*1000));
                    $('#add-rating-showbox').css('display','block');
                    return;
                  }
                }
                // show_alert("脚本:洛谷显示他人咕值", "找不到用户的咕值信息,请刷新重试。");
                akioi(pageid+1,remain-1);
              }
            }
          );
        };

        $('#add-rating-button').click(function(){akioi(tt_rk_page,10);});
      }
    },200);
  },800)});
})();

7.洛谷自动签到

只要登陆过洛谷,下一次打开chrome即可自动签到(仅支持最新版chrome:登陆过洛谷重启浏览器可以保持登陆状态的)

代码
// ==UserScript==
// @name         洛谷自动签到
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  只要登陆过洛谷,下一次打开chrome即可自动签到(仅支持最新版chrome:登陆过洛谷重启浏览器可以保持登陆状态的)
// @author       神虎
// @match        *://*
// @match        *://www.luogu.org/*
// @match        *://www.luogu.com.cn/*
// @grant        GM_xmlhttpRequest
// ==/UserScript==
GM_xmlhttpRequest({
  method: "GET",
  url: "https://www.luogu.com.cn/index/ajax_punch",
  onload: function(response) {
      console.log(JSON.parse(response["response"])["message"]);
  }
});

8.洛谷用户查找

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

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

(function () {
  $('document').ready(function(){setTimeout(function () {
    $sidebar = $('#app-old .lg-index-content .lg-right.am-u-lg-3');
    $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("/fe/api/user/search?keyword=" + $('[name=finder-uid]')[0].value,
        function (data) {
          var arr = data;
          if (!arr['users'][0]) {
            $('#find-user-button').removeClass('am-disabled');
            show_alert("好像哪里有点问题", "无法找到指定用户");
          }
          else {
            location.href = "/user/"+arr['users'][0]['uid'];
          }
        }
      );
      return false;
    };
    $('#find-user-button').click(find_func);
    $('#find-user-form').submit(find_func);

  },500)});
})();

9.洛谷按难度随机跳题

添加可以选择难度的随机跳题功能

代码
// ==UserScript==
// @name         洛谷按难度随机跳题
// @version      0.1.5
// @description  添加可以选择难度的随机跳题功能
// @author       神虎
// @match        *://www.luogu.com.cn/
// @match        *://www.luogu.com.cn/
// @namespace    https://greasyfork.org/zh-CN/users/370663-yezhiyi9670
// ==/UserScript==

(function () {
  $('document').ready(function(){setTimeout(function () {
    $sidebar = $('#app-old .lg-index-content .lg-right.am-u-lg-3');
    $firstele = $($sidebar.children()[0]);
    // console.log($firstele);
    $finder = $(`
      <div class="lg-article" id="rand-problem-form">
        <h2>按难度随机跳题</h2>
        <select class="am-form-field" style="background-color:#DDD;" name="rand-problem-rating" autocomplete="off" placeholder="选择难度">
          <option value="0">暂无评定</option>
          <option value="1">入门</option>
          <option value="2">普及-</option>
          <option selected value="3">普及/提高-</option>
          <option value="4">普及+/提高</option>
          <option value="5">提高+/省选-</option>
          <option value="6">省选/NOI-</option>
          <option value="7">NOI/NOI+/CTSC</option>
        </select>
        <select class="am-form-field" style="background-color:#DDD;margin-top:16px;" name="rand-problem-source" autocomplete="off" placeholder="选择来源">
          <option selected value="P">洛谷题库</option>
          <option value="CF">CodeForces</option>
          <option value="SP">SPOJ</option>
          <option value="AT">AtCoder</option>
          <option value="UVA">UVa</option>
        </select>
        <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="rand-problem-button" style="margin-top:16px;">跳转</button>
      </div>
    `);
    $finder.insertAfter($firstele);
    $('#rand-problem-button').click(function() {
      $('#rand-problem-button').addClass('am-disabled');
      $.get("https://www.luogu.com.cn/problem/list?difficulty=" + $('[name=rand-problem-rating]')[0].value + "&type=" + $('[name=rand-problem-source]')[0].value + "&page=1&_contentOnly=1",
        function (data) {
          //var arr = eval('(' + data + ')');
          var arr = data;
          if (arr['code'] != 200) {
            $('#rand-problem-button').removeClass('am-disabled');
            show_alert("好像哪里有点问题", arr["message"]);
          }
          else {
            // show_alert('调试','成功(题目数:'+arr['currentData']['problems']['count']+')');
            var problem_count = arr['currentData']['problems']['count'];
            var page_count = Math.ceil(problem_count / 50);
            var rand_page = Math.floor(Math.random()*page_count) + 1;
            // show_alert('调试',rand_page+'/'+page_count);
            $.get("https://www.luogu.com.cn/problem/list?difficulty=" + $('[name=rand-problem-rating]')[0].value + "&type=" + $('[name=rand-problem-source]')[0].value + "&page=" + rand_page + "&_contentOnly=1",
              function(data) {
                var list = data['currentData']['problems']['result'];
                var rand_idx = Math.floor(Math.random()*list.length);
                var pid = list[rand_idx]['pid'];
                // show_alert('调试',pid);
                location.href = "https://www.luogu.com.cn/problem/" + pid;
              }
            );
          }
        }
      );
    });

    var zzlist = document.querySelectorAll('h2');

    for(var i=0;i<zzlist.length;i++) {
      if(zzlist[i].innerHTML=='智能推荐') zzlist[i].innerHTML='智障推荐';
    }
  },499)});
})();

10.洛谷超级任务计划(第三方)

洛谷超级任务计划(第三方),不限题目数量

代码
// ==UserScript==
// @name         洛谷超级任务计划(第三方)
// @namespace    http://tampermonkey.net/
// @version      1.12
// @description  洛谷超级任务计划(第三方),不限题目数量
// @author       神虎
// @match        https://www.luogu.org/problemnew/show/*
// @match        https://www.luogu.org/
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==


// 可能将要实现的功能:
// 1. 添加异常处理,如 get 请求没有 200
// 2. 显示当前任务计划总数
// 3. 在只知道题号的情况下进行导入

// 感谢 @memset0 提供创意
// 感谢 @Legendword 协助完成 jQuery 相关代码
// 感谢 @memset0, @Legendword 帮助找 bug


var originalLimit = 28;
var nowUrl = window.location.href;
var LuoguSuperTodolist = {
    settings: {
        keepOriginalList: false,
        debugMode: false // 发布前将此设为 false
    }
};
// var myUid = document.cookie.match(/_uid=[0-9]+/)[0].substr(5);
// console.log(myUid)
// console.log('如果上面获取到的 uid 不正确,请反馈作者,谢谢')
var myUid = GM_getValue("myUid");
if (myUid == undefined || myUid == 'undefined')
    myUid = prompt("任务计划脚本更新,请正确输入您的 uid(数字)以保障插件正常运行");
GM_setValue("myUid", myUid);


function getOriginalList() {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'https://www.luogu.org/', false);
    xhr.send(null);
    if (xhr.status == 200) {
        console.log('get original todo list: 200');
        return extractData(xhr.responseText);
    } else {
        return {};
    }

    function extractData(content) {
        var psid = content.split('" target="_blank"><b>');
        if (psid[0].indexOf("还没有计划完成的题目<br>") != -1) {
            return {};
        }
        return clearData(psid);

        function clearData(psid) { // psid: problems' id
            var res = {}
            for (var i = 1; i < psid.length; i++) { // 从 1 开始循环,因为 split 导致 psid[0] 是垃圾文本串
                var pId = '', pName = '', j = 0;
                for (; j < psid[i].length; j++) { // 获取题号
                    if (psid[i][j] != '<') {
                        pId = pId.concat(psid[i][j]);
                    } else break;
                }
                for (j += 5; j < psid[i].length; j++) { // 获取题目名称
                    if (psid[i][j] != '<') {
                        pName = pName.concat(psid[i][j]);
                    } else break;
                }
                res[pId] = pName;
                if (psid[i].match(/智能推荐/) != null) break;
            }
            return res;
        }
    }
}


function syncList() {
    console.log('syncing');
    LuoguSuperTodolist.problems = getOriginalList();
    initList(); // 把洛谷原计划保存到脚本

    function initList() {
        var old = GM_getValue('problems');
        if (old != undefined || old != 'undefined') {
            for (var i in old) {
                LuoguSuperTodolist.problems[i] = old[i]
            }
        }
        GM_setValue('problems', LuoguSuperTodolist.problems);
    }
}


function getAc(uid) { // 从原来代码复制过来的
    // 向指定的个人空间发送 get 请求,获取 AC 列表
    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'https://' + window.location.host + '/space/show?uid=' + uid, false);
    xhr.send(null);
    console.log('got ' + uid + "'s AC list: " + xhr.status);
    if (xhr.status == 200) {
        return extractData(xhr.responseText); // 返回 AC 列表
    } else {
        return []; // 空列表
    }

    function extractData(content) {
        // 如果你有一个问题打算用正则表达式来解决,那么就是两个问题了。
        // 所以窝还是用 split() 解决这一个问题吧!
        var acs = content.replace(/<span style=\"display:none\">\n.*?\n<\/span>/g, ''); // 把随机的干扰题号去除
        acs = acs.split('[<a data-pjax href="/problem/show?pid='); // 使用 split() 方法把通过的题目分割出来
        acs = clearData(acs); // 把分割好的数据清洁一下
        return acs;

        function clearData(acs) {
            var res = new Array();
            res.push(new Array());
            res.push(new Array());
            var g = 0;
            for (var i = 1; i < acs.length; i++) { // 把每一行非题号字符删掉(从 1 开始循环为了避开 split 之后产生的垃圾)
                var tmpStr = "";
                for (var j = 0; j < acs[i].length; j++) {
                    if (acs[i][j] != '"') { // 引号后面的不是题号部分字符
                        tmpStr = tmpStr.concat(acs[i][j]); // 拼接字符串
                    }
                    else break;
                }
                res[g].push(tmpStr);
                if (acs[i].length > 50) { // 这是最后一个题目 / 下一个是「尝试过的题目」
                    g++;
                }
            }
            return res;
        }
    }
}


function getDictLength(dict) {
    var res = 0;
    for (var i in dict) res++;
    return res;
}


function updateMainPageList() {
    var tmp = getAc(myUid);
    var myAc = tmp[0], myAttempt = tmp[1];
    myAc.sort();
    myAttempt.sort();

    // 清除官方的任务计划
    if (!LuoguSuperTodolist.settings.keepOriginalList) {
        $("h2:contains('智能推荐')").prevAll().remove();
        // 当官方计划为空时,删除那句话
        if ($("h2:contains('智能推荐')").parent().html().indexOf("<h2") > 0) {
            $("h2:contains('智能推荐')").parent().html($("h2:contains('智能推荐')").parent().html().slice($("h2:contains('智能推荐')").parent().html().indexOf("<h2")));
        }
    }

    // 在 Luogu 官方任务计划后面添加第三方计划
    var problems = GM_getValue('problems')
    $("h2:contains('智能推荐')").before('<h2>任务计划 (' + getDictLength(problems) + ' 题)' + '<button class="am-btn am-btn-sm am-btn-primary lg-right" id="LuoguSuperTodolist-export">编辑</button></h2>');
    for (var i in problems) {
        var state = getState(i);
        var color = { 'Y': 'green', 'N': 'black', '?': 'orange' };
        var content = { 'Y': '<i class="am-icon-check"></i>', 'N': '<i class="am-icon-minus"></i>', '?': '?' };
        $("h2:contains('智能推荐')").before(
            '<div class="tasklist-item LuoguSuperTodolist-tasklist-item" data-pid="'
            + i
            + '"><div><a href="/recordnew/lists?uid='
            + myUid
            + '&amp;pid='
            + i
            + '" target="_blank"><strong class="lg-fg-'
            + color[state]
            + '">' + content[state]
            + '</strong></a>'
            + '<a class="colored" style="padding-left: 3px" href="/problemnew/show/'
            + i
            + '" target="_blank"><b>'
            + i
            + '</b> '
            + problems[i]
            + '</a></div></div>'
        );
    }

    $("#LuoguSuperTodolist-export").click(function () {
        if (LuoguSuperTodolist.exportOpen) { // 响应「完成」按钮
            /*while (!importProblem()) {
                $("#edit-problem")[0].value = generateExportedList(); // 恢复原文本串
            } // 直到成功导入*/
            importProblem();
            $("#LuoguSuperTodolist-export").html("编辑");
            $("#LuoguSuperTodolist-exportRes").remove();
        } else { // 响应「导入 / 导出」按钮
            var listString = generateExportedList();
            $("h2:contains('任务计划')").after(
                "<div id='LuoguSuperTodolist-exportRes'>编辑下方文本进行编辑操作。</br>格式:[题号] + '#'(井号) + [题目标题],一行一题。</br>拖动右下角可以改变编辑框大小。"
                + "<div class='am-form-group am-form'><textarea id='edit-problem'>"
                + listString
                + "</textarea></div>"
            );
            console.log(listString);
            $("#LuoguSuperTodolist-export").html("完成");
        }

        LuoguSuperTodolist.exportOpen ^= 1; // 使用异或运算切换状态,简便快捷

        function importProblem() { // 尚不支持检测题号是否合法
            var input = $("#edit-problem").val()
            input = input.split('\n'); // jQuery 自带 split 有问题,必须用 string 的是 split
            console.log(input);
            // var problems = LuoguSuperTodolist.problems;
            var problems = {}; // for oier sp
            for (var i = 0; i < input.length; i++) {
                if (!checkString(input[i])) {
                    alert('输入数据不合法!')
                    return false;
                }
                input[i] = input[i].split(' # '); // 注意这里不能是单纯的井号
                if (problems[input[i][0]] == undefined) {
                    problems[input[i][0]] = input[i][1];
                    console.log(problems[input[i][0]]);
                }
            }
            LuoguSuperTodolist.problems = problems;
            console.log(LuoguSuperTodolist.problems);
            GM_setValue('problems', LuoguSuperTodolist.problems);
            updateMainPageList(); // 导入成功后需要更新显示

            function checkString(s) { // 计算字符串中 # 号数量,检查格式
                var pos = -1;
                for (var i = 0; i < s.length; i++) {
                    if (s[i] == '#') {
                        if (pos == -1) {
                            pos = i;
                        } else {
                            pos = -2;
                        }
                    }
                }
                return pos > 0 && s[pos - 1] == ' ' && s[pos + 1] == ' ';
            }
        }

        function generateExportedList() {
            var problems = LuoguSuperTodolist.problems;
            var res = "";
            for (var c in problems) {
                res += "\n" + c + " # " + problems[c];
            }
            return res;
        }
    });

    function getState(pid) {
        if (binarySearch(pid, myAc)) return 'Y';
        else if (binarySearch(pid, myAttempt)) return '?';
        else return 'N';
    }

    function binarySearch(target, array) { // 使用二分查找算法进行比较
        var l = 0, r = array.length;
        while (l < r) {
            var mid = parseInt((l + r) / 2); // JavaScript 除法默认不是整数。。
            if (target == array[mid]) return true;
            else if (target > array[mid]) l = mid + 1;
            else r = mid;
        }
        return false;
    }
}


function addButton() {
    $('#remove-tasklist').remove();
    $('#add-tasklist').remove(); // 移除旧的按钮

    var problemId = nowUrl.match(/[A-Z]+[0-9]+/)[0];
    if (nowUrl.match(/[A-Z]+[0-9]+[A-Z]/) != null) {
        problemId = nowUrl.match(/[A-Z]+[0-9]+[A-Z]/)[0]; // CF 题库特判
    }
    console.log(problemId);
    var problemTitle = getTitle();

    if (!isInList()) {
        $(".lg-summary-content")
            .append('<p>'
                + '<a href="javascript: ;" '
                + 'id="update-todolist" '
                + 'class="am-btn am-btn-sm am-btn-primary">'
                + '添加至超级任务计划'
                + '</a>'
                + '</p>');
        $("#update-todolist").click(swapState);
    } else {
        $(".lg-summary-content")
            .append('<p>'
                + '<a href="javascript: ;" '
                + 'id="update-todolist" '
                + 'class="am-btn am-btn-sm am-btn-danger">'
                + '从任务计划移除'
                + '</a>'
                + '</p>');
        $("#update-todolist").click(swapState);
    }

    function getTitle() {
        return document.title.substr((problemId.length + 1), document.title.length - (problemId.length + 1) - 5)
    }

    function isInList() {
        var nowList = GM_getValue('problems');
        if (nowList == undefined) return false;
        return nowList[problemId] != undefined;
    }

    function swapState(ev) { // 是不是应该改成检测现在的属性,然后交换属性
        if (isInList()) { // 已经在任务计划列表,删掉它。变成蓝色按钮
            removeFromList(problemId, problemTitle);
            $("#update-todolist").attr("class", "am-btn am-btn-sm am-btn-primary");
            $("#update-todolist").html("添加至超级任务计划");
        } else { // 不在任务计划当中,加进去,变成红色按钮
            addToList(problemId, problemTitle)
            $("#update-todolist").attr("class", "am-btn am-btn-sm am-btn-danger");
            $("#update-todolist").html("从任务计划移除");
        }

        function addToList(id, title) {
            var nowList = GM_getValue('problems');
            nowList[id] = title;
            GM_setValue('problems', nowList);
            LuoguSuperTodolist.problems = GM_getValue('problems')
            if (getDictLength(getOriginalList()) < originalLimit) { // 原计划长度足够装下新题目,装进去
                $.post("/api/user/tasklistAdd", { pid: id });
            }
        }

        function removeFromList(id, title) {
            var nowList = GM_getValue('problems');
            delete nowList[id];
            GM_setValue('problems', nowList);
            LuoguSuperTodolist.problems = GM_getValue('problems')
            var originalList = getOriginalList();
            if (findInDict(id, originalList)) { // 删除的题目在原计划当中,在原计划也删除
                $.post("/api/user/tasklistRemove", { pid: id })
            }
            checkOther(); // 看剩余空间够不够再同步几道题进去

            function findInDict(target, dict) {
                for (var i in dict) if (i == target) return true;
                return false;
            }

            function checkOther() {
                var diff = originalLimit - (getDictLength(originalList) - 1); // 长度 - 1 是因为刚才删掉了一个
                console.log(diff);
                if (diff > 0) {
                    var cnt = 0;
                    var arr = new Array();
                    for (var i in LuoguSuperTodolist.problems) {
                        if (!findInDict(i, originalList)) { // superList 当中不在 originalList 的题目
                            arr.push(i);
                            cnt += 1;
                            if (cnt == diff) break;
                        }
                    }
                    for (var i = 0; i < arr.length; i++) {
                        $.post("/api/user/tasklistAdd", { pid: arr[i] });
                    }
                }
            }
        }
    }
}


function start() {
    var lastUse = GM_getValue('lastUse');
    var date = Date();
    date = date.split(' ');
    date = date[0] + date[1];
    GM_setValue('lastUse', date);
    if (lastUse == undefined || lastUse != date || LuoguSuperTodolist.settings.debugMode) { // 首次运行脚本,将原任务计划保存
        console.log('更新后首次运行脚本,请耐心等待初始化');
        syncList();
    }
    LuoguSuperTodolist.problems = GM_getValue('problems')
    if (nowUrl == 'https://www.luogu.org/') {
        updateMainPageList(); // 更新主页的 todolist
    } else if (nowUrl.match(/problem/) != null) { // 题目页面运行脚本,添加按钮
        addButton();
    }
}


start();

11.洛谷题目难度显示

在个人空间显示每一道题的难度

代码
// ==UserScript==
// @name         洛谷题目难度显示
// @namespace    http://tampermonkey.net/
// @version      0.7
// @description  在个人空间显示每一道题的难度
// @author       Rainy_Chen
// @match        https://www.luogu.com.cn/user/*
// @grant        none
// ==/UserScript==

var colors = ['rgb(191, 191, 191)', 'rgb(254, 76, 97)', 'rgb(243, 156, 17)', 'rgb(255, 193, 22)', 'rgb(82, 196, 26)', 'rgb(52, 152, 219)', 'rgb(157, 61, 207)', 'rgb(14, 29, 105)'];

(function() {
    'use strict';
    var problems = [];
    for(var passed of window._feInjection.currentData.passedProblems) problems.push({pid: passed.pid, dif: passed.difficulty, rendered: false});
    for(var tryed of window._feInjection.currentData.submittedProblems) problems.push({pid: tryed.pid, dif: tryed.difficulty, rendered: false});

    setInterval(() => {
        if(window.location.href.split("#").length == 2 && window.location.href.split("#")[1] == 'practice'){
            for(var i = 0;i < problems.length;i++) if(!problems[i].rendered) {
                var elements = document.querySelectorAll('a');
                for(var el of elements) if(el.textContent == problems[i].pid) {
                    if (el.classList) el.classList.remove("color-default");
                    else el.className = el.className.replace('color-default',  ' ');
                    problems[i].rendered = true;
                    el.style.color = colors[problems[i].dif];
                    break;
                }
            }
        }else for(var j = 0;j < problems.length;j++) problems[j].rendered = false;
    }, 1000);
})();