// ==UserScript==
// @name 洛谷按难度随机跳题
// @version 0.1.5
// @description 添加可以选择难度的随机跳题功能
// @author C2020陈铭浩
// @match *://www.luogu.com.cn/
// @match *://www.luogu.com.cn/
// @namespace https://greasyfork.org/zh-CN/users/370663-yezhiyi9670
// @downloadURL https://update.greasyfork.icu/scripts/481222/%E6%B4%9B%E8%B0%B7%E6%8C%89%E9%9A%BE%E5%BA%A6%E9%9A%8F%E6%9C%BA%E8%B7%B3%E9%A2%98.user.js
// @updateURL https://update.greasyfork.icu/scripts/481222/%E6%B4%9B%E8%B0%B7%E6%8C%89%E9%9A%BE%E5%BA%A6%E9%9A%8F%E6%9C%BA%E8%B7%B3%E9%A2%98.meta.js
// ==/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 = $(`
按难度随机跳题
`);
$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;
}
);
}
}
);
});
},499)});
})();