Better Luogu!

Luogu Expansion

当前为 2025-01-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Better Luogu!
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.8.7
  5. // @description:zh 洛谷扩展
  6. // @description Luogu Expansion
  7. // @author volatile
  8. // @match *://*.luogu.com.cn/*
  9. // @match *://*.luogu.com/*
  10. // @icon https://fecdn.luogu.com.cn/luogu/logo.png?0fdd294ff62e331d2f70e1a37ba4ee02
  11. // @grant GM_addStyle
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // @grant GM_deleteValue
  15. // @grant GM_listValues
  16. // @grant GM_setClipboard
  17. // @grant GM_xmlhttpRequest
  18. // @grant GM_getResourceText
  19. // @grant unsafeWindow
  20. // @connect baidu.com
  21. // @connect greasyfork.org
  22. // @require https://unpkg.com/sweetalert/dist/sweetalert.min.js
  23. // @require https://code.jquery.com/jquery-3.6.0.min.js
  24. // @license MIT
  25. // ==/UserScript==
  26.  
  27. (function() {
  28. 'use strict'
  29.  
  30. var css = ".swal-overlay {background-color: rgba(0, 0, 0, 0.5);}";
  31. var style = document.createElement("style");
  32. style.innerHTML = css;
  33. document.head.appendChild(style);
  34.  
  35. let br = document.createElement('br');
  36.  
  37. let nowurl = window.location.href;
  38.  
  39. let nowcolor1;
  40. let nowcolor="";
  41. if(nowurl == 'https://www.luogu.com.cn/'){
  42. nowcolor1 = document.querySelector('#app-old > div.lg-index-content.am-center > div:nth-child(1) > div > div > div > div.am-u-md-4.lg-punch.am-text-center > h2 > a').className;
  43. for(let i=0;i<nowcolor1.length;i++){
  44. if(nowcolor1[i]==' ') break;
  45. nowcolor = nowcolor + nowcolor1[i];
  46. }
  47. let uid = document.querySelector('#app-old > div.lg-index-content.am-center > div:nth-child(1) > div > div > div > div.am-u-md-4.lg-punch.am-text-center > h2 > a').href;
  48. let _uid = "";
  49. for(let i=uid.length-1;i>=0;i--){
  50. if(!(uid[i]>='0'&&uid[i]<='9')) break;
  51. _uid = uid[i] + _uid;
  52. }
  53. setcookie('uid',_uid,114514,'/','luogu.com.cn',true);
  54. }
  55.  
  56. function setcookie(name,value,days,path,domain,secure){
  57. let expires = "";
  58. if(days){
  59. let date = new Date();
  60. date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
  61. expires = "; expires=" + date.toUTCString();
  62. }
  63. var cookieString = name + "=" + (value || "") + expires;
  64. if(path) cookieString += "; path=" + path;
  65. if(domain) cookieString += "; domain=" + domain;
  66. if(secure && window.location.protocol === "https:") cookieString += "; secure";
  67. document.cookie = cookieString;
  68. }
  69.  
  70. function getcookie(name){
  71. const cookiestring = document.cookie;
  72. const cookies = cookiestring.split('; ');
  73. for(const cookie of cookies){
  74. const [cookiename, cookievalue] = cookie.split('=');
  75. if(cookiename === name) return cookievalue;
  76. }
  77. if(name == 'color'){
  78. setcookie('color',nowcolor,114514,'/','luogu.com.cn',true);
  79. return nowcolor;
  80. }
  81. else if(name == 'hanger'){
  82. setcookie('hanger','null',114514,'/','luogu.com.cn',true);
  83. return "null";
  84. }
  85. else if(name == 'version'){
  86. setcookie('version','1.8.7',114514,'/','luogu.com.cn',true);
  87. return "1.8.7";
  88. }
  89. else if(name == 'update'){
  90. setcookie('update','true',114514,'/','luogu.com.cn',true);
  91. return "true";
  92. }
  93. else if(name == 'uid'){
  94. setcookie('null','true',114514,'/','luogu.com.cn',true);
  95. return "null";
  96. }
  97. }
  98.  
  99.  
  100. function deletecookie(name){
  101. document.cookie = name+ '=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/';
  102. }
  103.  
  104. async function sendMessage(uid,content){
  105. await fetch("https://www.luogu.com.cn/api/chat/new", {
  106. headers: [
  107. ["content-type", "application/json"],
  108. ["referer", "https://www.luogu.com.cn/"],
  109. ["x-csrf-token", document.querySelector("meta[name=csrf-token]").content],
  110. ],
  111. body: JSON.stringify({
  112. user: uid,
  113. content: content,
  114. }),
  115. method: "POST",
  116. });
  117. }
  118.  
  119. async function sendBenBen(content){
  120. await fetch("https://www.luogu.com.cn/api/feed/postBenben", {
  121. headers: [
  122. ["content-type", "application/json"],
  123. ["referer", "https://www.luogu.com.cn/"],
  124. ["x-csrf-token", document.querySelector("meta[name=csrf-token]").content],
  125. ],
  126. body: JSON.stringify({
  127. content: content
  128. }),
  129. method: "POST",
  130. });
  131. }
  132.  
  133. GM_xmlhttpRequest({
  134. method: "GET",
  135. url: 'https://greasyfork.org/zh-CN/scripts/487511-better-luogu',
  136. onload: function(response){
  137. let parser = new DOMParser();
  138. let doc = parser.parseFromString(response.responseText, "text/html");
  139. let version = doc.querySelector('dd.script-show-version');
  140. if(version.textContent != '1.8.7' && nowurl == 'https://www.luogu.com.cn/'){
  141. if(getcookie('update')=='true'){
  142. swal("Better Luogu!","有新版本",{
  143. buttons: {
  144. no: {
  145. text: "7天内不再提醒",
  146. value: "false",
  147. },
  148. yes: {
  149. text: "更新",
  150. value: "true",
  151. }
  152. },
  153. })
  154. .then((value) => {
  155. if(value == "false"){
  156. deletecookie('update');
  157. setcookie('update','false',7,'/','luogu.com.cn',true);
  158. swal("Better Luogu!","好的,你可以在 BETTER 菜单中点击更新来更新");
  159. }
  160. else window.open('https://greasyfork.org/zh-CN/scripts/487511-better-luogu','_blank');
  161. });
  162. }
  163. }
  164. }
  165. });
  166.  
  167. function colorschange(changecolor){
  168. if(changecolor == 'Gray') return 'rgb(191, 191, 191)';
  169. else if(changecolor == 'Blue') return 'rgb(14, 144, 210)';
  170. else if(changecolor == 'Green') return 'rgb(94, 185, 94)';
  171. else if(changecolor == 'Orange') return 'rgb(230, 126 34)';
  172. else if(changecolor == 'Red') return 'rgb(231, 76, 60)';
  173. else if(changecolor == 'Purple') return 'rgb(142, 68, 173)';
  174. else if(changecolor == 'Brown') return 'rgb(173, 139, 0)';
  175. }
  176.  
  177. function update(){
  178. swal("Better Luogu!","真的真的真的修复了练习情况消失的bug");/*,{
  179. buttons: {
  180. cancel: "取消",
  181. _continue: {
  182. text: "继续",
  183. value: "continue",
  184. },
  185. },
  186. })
  187. .then((value) => {
  188. if(value == "continue"){
  189. swal("Better Luogu!","在个人主页可使用更改的勾子");,{
  190. buttons: {
  191. cancel: "取消",
  192. _continue: {
  193. text: "继续",
  194. value: "continue"
  195. }
  196. }
  197. });
  198. .then((value1) => {
  199. if(value1 == "continue"){
  200. swal("Better Luogu!","");
  201. }
  202. });
  203. }
  204. });*/
  205. }
  206.  
  207. let changecolor = getcookie('color');
  208.  
  209. let tagchange = getcookie('tag');
  210. let tag = document.createElement("span");
  211. let tagcolor;
  212. if(changecolor != 'lg-fg-blue' && changecolor != 'lg-fg-orange'){
  213. tagcolor = changecolor.replace('fg','bg');
  214. tag.className = 'am-badge am-radius ' + tagcolor;
  215. }
  216. else if(changecolor == 'lg-fg-blue'){
  217. tagcolor = 'color-none';
  218. tag.className = 'am-badge am-radius ' + tagcolor;
  219. tag.style.background = 'rgb(52, 152, 219)';
  220. }
  221. else if(changecolor == 'lg-fg-orange'){
  222. tagcolor = 'color-none';
  223. tag.className = 'am-badge am-radius ' + tagcolor;
  224. tag.style.background = 'rgb(243, 156, 17)';
  225. }
  226. if(changecolor != 'lg-fg-brown') tag.textContent = tagchange;
  227. else tag.textContent = '作弊者';
  228.  
  229. if(getcookie('version')!='1.8.7'&&nowurl=='https://www.luogu.com.cn/'){
  230. deletecookie('version');
  231. setcookie('version','1.8.7',114514,'/','luogu.com.cn',true);
  232. update();
  233. }
  234.  
  235. function reallyDeleteChat(id){
  236. let csrf = document.querySelector("meta[name=csrf-token]").content;
  237. $.ajax({
  238. url: 'https://www.luogu.com.cn/api/chat/delete',
  239. type: 'POST',
  240. dataType: 'json',
  241. data: JSON.stringify({id: id}),
  242. cache: false,
  243. headers: {
  244. 'Content-Type': 'application/json',
  245. 'x-csrf-token': csrf
  246. },
  247. xhrFields: {
  248. withCredentials: true
  249. }
  250. });
  251. }
  252.  
  253. function deleteChat(uid){
  254. $.get('https://www.luogu.com.cn/api/chat/record?user='+uid,{},function(res){
  255. for(let i=0;i<res['messages']['result'].length;i++){
  256. reallyDeleteChat(res['messages']['result'][i].id);
  257. }
  258. });
  259. }
  260.  
  261. function reloadmenu(){
  262. swal("Better Luogu!","更改成功","success",{button: "刷新"}).then((value) => {location.reload();});
  263. }
  264.  
  265. function changeusercolor(){
  266. swal({
  267. title: "Better Luogu!",
  268. text: "输入一个词语(规则见油叉插件页)",
  269. content: "input",
  270. button: {
  271. text: "更改",
  272. closeModal: false,
  273. },
  274. })
  275. .then((input) => {
  276. if(input=='灰名'||input=='gray'){
  277. deletecookie('color');
  278. setcookie('color','lg-fg-gray',114514,'/','luogu.com.cn',true);
  279. reloadmenu();
  280. }
  281. else if(input=='蓝名'||input=='blue'){
  282. deletecookie('color');
  283. setcookie('color','lg-fg-blue',114514,'/','luogu.com.cn',true);
  284. reloadmenu();
  285. }
  286. else if(input=='绿名'||input=='green'){
  287. deletecookie('color');
  288. setcookie('color','lg-fg-green',114514,'/','luogu.com.cn',true);
  289. reloadmenu();
  290. }
  291. else if(input=='橙名'||input=='orange'){
  292. deletecookie('color');
  293. setcookie('color','lg-fg-orange',114514,'/','luogu.com.cn',true);
  294. reloadmenu();
  295. }
  296. else if(input=='红名'||input=='red'){
  297. deletecookie('color');
  298. setcookie('color','lg-fg-red',114514,'/','luogu.com.cn',true);
  299. reloadmenu();
  300. }
  301. else if(input=='紫名'||input=='purple'){
  302. deletecookie('color');
  303. setcookie('color','lg-fg-purple',114514,'/','luogu.com.cn',true);
  304. reloadmenu();
  305. }
  306. else if(input=='棕名'||input=='brown'){
  307. deletecookie('color');
  308. setcookie('color','lg-fg-brown',114514,'/','luogu.com.cn',true);
  309. reloadmenu();
  310. }
  311. else if(input=='复原'||input=='recover'){
  312. deletecookie('color');
  313. setcookie('color',nowcolor,114514,'/','luogu.com.cn',true);
  314. reloadmenu();
  315. }
  316. else swal("Better Luogu!","请按规范输入","error");
  317. });
  318. }
  319.  
  320. function changehanger(){
  321. swal("Better Luogu!","选择一个勾子", {
  322. buttons: {
  323. cancel: "取消",
  324. greenhanger: {
  325. text: "绿勾",
  326. value: "greenhanger",
  327. },
  328. bluehanger: {
  329. text: "蓝勾",
  330. value: "bluehanger",
  331. },
  332. goldenhanger: {
  333. text: "金勾",
  334. value: "goldenhanger",
  335. },
  336. nullhanger: {
  337. text: "无勾",
  338. value: "nullhanger",
  339. },
  340. }
  341. })
  342. .then((value) => {
  343. switch (value){
  344. case "greenhanger":
  345. deletecookie('hanger');
  346. setcookie('hanger','green',114514,'/','luogu.com.cn',true);
  347. reloadmenu();
  348. break;
  349. case "bluehanger":
  350. deletecookie('hanger');
  351. setcookie('hanger','blue',114514,'/','luogu.com.cn',true);
  352. reloadmenu();
  353. break;
  354. case "goldenhanger":
  355. deletecookie('hanger');
  356. setcookie('hanger','golden',114514,'/','luogu.com.cn',true);
  357. reloadmenu();
  358. break;
  359. case "nullhanger":
  360. deletecookie('hanger');
  361. setcookie('hanger','null',114514,'/','luogu.com.cn',true);
  362. reloadmenu();
  363. break;
  364. }
  365. });
  366. }
  367.  
  368. function changetag(){
  369. swal({
  370. title: "Better Luogu!",
  371. text: "输入一个tag(无输入以取消)",
  372. content: "input",
  373. button: {
  374. text: "更改",
  375. closeModal: false,
  376. },
  377. })
  378. .then((value) => {
  379. if(getcookie('color') == 'lg-fg-brown') swal("Better Luogu!","当前为棕名","error");
  380. else if(value.length > 10) swal("Better Luogu!","长度应不大于10","error");
  381. else{
  382. deletecookie('tag');
  383. setcookie('tag',value,114514,'/','luogu.com.cn',true);
  384. reloadmenu();
  385. }
  386. });
  387. }
  388.  
  389. function not1(){
  390. let words = ["78;101;118;101;114;32;103;111;110;110;97;32;103;105;118;101;32;121;111;117;32;117;112;","99;110;109;","83;66;","73;65;75;73;79;73;","49;49;52;53;49;52;","49;57;49;57;56;49;48;","115;116;111;","111;114;122;"];
  391. let cishu = Math.floor(Math.random()*10)+1;
  392. for(let i=1;i<=cishu;i++){
  393. let qwq = words[Math.floor(Math.random()*words.length)];
  394. let awa="";
  395. let t=0;
  396. for(let j=0;j<qwq.length;j++){
  397. if(qwq[j]!=';'){
  398. t*=10;
  399. t+=parseInt(qwq[j]);
  400. }
  401. else{
  402. awa+=String.fromCharCode(t);
  403. t=0;
  404. }
  405. }
  406. sendMessage(0xbc970,awa);
  407. }
  408. sendMessage(0xbc970,"孩子们,快下载Better Luogu!吧!");
  409. swal("Better Luogu!","好像有点问题?!","error",{button: "前往私信"}).then((value) => {window.open('https://www.luogu.com.cn/chat','_self');});
  410. }
  411.  
  412. function not2(){
  413. sendBenBen("这个人AKIOI");
  414. sendBenBen("Better Luogu!真好用");
  415. let uid_=getcookie('uid');
  416. if(uid_!='null') swal("Better Luogu!","好像有点问题?!","error",{button: "前往动态"}).then((value) => {window.open('https://www.luogu.com.cn/user/'+uid_+'#activity','_self');});
  417. else swal("Better Luogu!","好像有点问题?!","error",{button: "前往主页犇犇"}).then((value) => {window.open('https://www.luogu.com.cn','_self');});
  418. }
  419.  
  420. function not(){
  421. swal("Better Luogu!","不怕死就选择一个", {
  422. buttons: {
  423. not1: {
  424. text: "1",
  425. value: "not1"
  426. },
  427. not2: {
  428. text: "2",
  429. value: "not2"
  430. }
  431. },
  432. })
  433. .then((value) => {
  434. switch (value){
  435. case "not1":
  436. not1();
  437. break;
  438. case "not2":
  439. not2();
  440. break;
  441. }
  442. });
  443. }
  444.  
  445. function changeSlogan(slogan){
  446. let csrf = document.querySelector("meta[name=csrf-token]").content;
  447. $.ajax({
  448. url: 'https://www.luogu.com.cn/api/user/updateSlogan',
  449. type: 'POST',
  450. dataType: 'json',
  451. data: JSON.stringify({slogan: slogan}),
  452. cache: false,
  453. headers: {
  454. 'Content-Type': 'application/json',
  455. 'x-csrf-token': csrf
  456. },
  457. xhrFields: {
  458. withCredentials: true
  459. }
  460. });
  461. }
  462.  
  463. function zb(){
  464. swal("Better Luogu!","在个签添加“安装Better Luogu!谢谢喵”的文本",{
  465. buttons: {
  466. cancel: "去你的",
  467. agree: {
  468. text: "同意",
  469. value: "agree"
  470. }
  471. }
  472. }).then((value)=>{
  473. if(value=='agree'){
  474. let useruid = getcookie('uid');
  475. $.get('https://www.luogu.com.cn/api/user/search?keyword='+useruid,{},function(res){
  476. let slogan=res['users'][0].slogan;
  477. if(slogan.includes('|安装Better Luogu!谢谢喵')) swal("Better Luogu!","你好像已经宣传过了");
  478. else{
  479. slogan+='|安装Better Luogu!谢谢喵';
  480. changeSlogan(slogan);
  481. }
  482. });
  483. }
  484. });
  485. }
  486.  
  487. if(nowurl == 'https://www.luogu.com.cn/'){
  488. let searchuser = document.createElement('div');
  489. searchuser.className='lg-article';
  490. searchuser.innerHTML='<h2>Better Luogu!</h2><input type="text" class="am-form-field" placeholder="输入用户名跳转主页" name="user"></input>';
  491. document.querySelector('div.lg-right > div:nth-child(1)').insertAdjacentElement('beforebegin', searchuser);
  492. let color = document.querySelector('#app-old > div.lg-index-content.am-center > div:nth-child(1) > div > div > div > div.am-u-md-4.lg-punch.am-text-center > h2 > a');
  493. if(changecolor != 'null') color.className=changecolor;
  494.  
  495. function removeDivWithText(text) {
  496. document.querySelectorAll('div').forEach(div => {
  497. if(div.textContent === text) div.remove();
  498. });
  499. }
  500.  
  501. function findElement(element, text, cclass){
  502. document.querySelectorAll(element).forEach(E => {
  503. if(E.textContent === text) E.className = cclass;
  504. });
  505. }
  506.  
  507. removeDivWithText('暂无推荐');
  508. removeDivWithText('洛谷根据您近期的做题情况,使用机器学习自动为您推荐符合您目前程度的题目。本列表每日更新一次。');
  509.  
  510. GM_xmlhttpRequest({
  511. method: "GET",
  512. url: 'https://top.baidu.com/board?tab=realtime',
  513. onload: function(response){
  514. let rs = new DOMParser();
  515. let doc = rs.parseFromString(response.responseText, "text/html");
  516. for(let i=1;i<=5;i++){
  517. let th = i.toString();
  518. let selector = '#sanRoot > main > div.container.right-container_2EFJr > div > div:nth-child(2) > div:nth-child(' + th + ') > div.content_1YWBm > a > div.c-single-text-ellipsis';
  519. let _rs = doc.querySelector(selector);
  520. let selector2 = '#sanRoot > main > div.container.right-container_2EFJr > div > div:nth-child(2) > div:nth-child(' + th + ') > div.content_1YWBm > a';
  521. let rslink = doc.querySelector(selector2);
  522. let link = document.createElement("a");
  523. link.href = rslink.href;
  524. link.textContent = _rs.textContent;
  525. let RS = document.createElement("p");
  526. RS.appendChild(link);
  527. findElement('h2','智能推荐','zntj');
  528. document.getElementsByClassName('zntj')[0].parentNode.append(RS);
  529. }
  530. }
  531. });
  532.  
  533. let links = document.querySelector('.lg-article.am-hide-sm');
  534. links.insertAdjacentHTML('beforeend','<p><strong>Better Luogu!</strong><br><a href="https://www.volatiles.us.kg/" target="_blank">Better Luogu!</a><br><a href="https://greasyfork.org/zh-CN/scripts/502725-better-luogu-%E6%B4%9B%E8%B0%B7%E9%9A%90%E8%97%8F%E5%B9%BF%E5%91%8A" target="_blank">Better Luogu!-洛谷隐藏广告</a></p>');
  535. }
  536. window.onload=function(){
  537. let _hanger = getcookie('hanger');
  538. let __hanger = document.createElementNS('http://www.w3.org/2000/svg','svg');
  539. __hanger.setAttribute('width','16');
  540. __hanger.setAttribute('height','16');
  541. __hanger.setAttribute('viewBox','0 0 16 16');
  542. __hanger.setAttribute('style','margin-bottom: -3px;');
  543. if(_hanger == 'green')__hanger.setAttribute('fill','#5eb95e');
  544. else if(_hanger == 'blue') __hanger.setAttribute('fill','#3498db');
  545. else if(_hanger == 'golden') __hanger.setAttribute('fill','#f1c40f');
  546. if(_hanger != 'null'&&document.getElementsByClassName('sb_amazeui')[0] != null) document.getElementsByClassName('sb_amazeui')[0].remove();
  547.  
  548. let ___hanger = document.createElementNS('http://www.w3.org/2000/svg','path');
  549. ___hanger.setAttribute('d','M16 8C16 6.84375 15.25 5.84375 14.1875 5.4375C14.6562 4.4375 14.4688 3.1875 13.6562 2.34375C12.8125 1.53125 11.5625 1.34375 10.5625 1.8125C10.1562 0.75 9.15625 0 8 0C6.8125 0 5.8125 0.75 5.40625 1.8125C4.40625 1.34375 3.15625 1.53125 2.34375 2.34375C1.5 3.1875 1.3125 4.4375 1.78125 5.4375C0.71875 5.84375 0 6.84375 0 8C0 9.1875 0.71875 10.1875 1.78125 10.5938C1.3125 11.5938 1.5 12.8438 2.34375 13.6562C3.15625 14.5 4.40625 14.6875 5.40625 14.2188C5.8125 15.2812 6.8125 16 8 16C9.15625 16 10.1562 15.2812 10.5625 14.2188C11.5938 14.6875 12.8125 14.5 13.6562 13.6562C14.4688 12.8438 14.6562 11.5938 14.1875 10.5938C15.25 10.1875 16 9.1875 16 8ZM11.4688 6.625L7.375 10.6875C7.21875 10.8438 7 10.8125 6.875 10.6875L4.5 8.3125C4.375 8.1875 4.375 7.96875 4.5 7.8125L5.3125 7C5.46875 6.875 5.6875 6.875 5.8125 7.03125L7.125 8.34375L10.1562 5.34375C10.3125 5.1875 10.5312 5.1875 10.6562 5.34375L11.4688 6.15625C11.5938 6.28125 11.5938 6.5 11.4688 6.625Z');
  550. __hanger.appendChild(___hanger);
  551. let _hanger_ = document.createElement("a");
  552. _hanger_.href = 'https://www.luogu.com/discuss/142324';
  553. _hanger_.appendChild(__hanger);
  554.  
  555. let button = document.createElement("a");
  556. button.innerHTML = '<button id="NLTB" style=\"background-color: rgb\(94,114,228\);border-radius: 7px;color: white;border: none;padding: 7px 12px;text-align: center;text-decoration: none;display: inline-block;font-size: 16px;margin: 4px 2px;cursor: pointer;border: none;box-shadow: 2px 3px 7px #000;\">BETTER</button>';
  557. if(nowurl == 'https://www.luogu.com.cn/' || nowurl == 'https://www.luogu.com.cn/chat' || nowurl.includes('https://www.luogu.com.cn/user/notification') || (nowurl.includes('https://www.luogu.com.cn/user/') && !nowurl.includes('https://www.luogu.com.cn/user/setting'))) document.querySelector('#app > div.main-container > div.wrapper.wrapped.lfe-body.header-layout.tiny > div.container > nav').insertAdjacentElement('beforebegin', button);
  558. else if(!nowurl.includes('https://www.luogu.com.cn/discuss')&&!nowurl.includes('https://www.luogu.com.cn/article')&&!nowurl.includes('https://www.luogu.com.cn/problem/solution/')){
  559. let user_nav = document.querySelector('div.user-nav[data-v-2dfcfd35]');
  560. let c_usernav = document.querySelector('nav[data-v-2dfcfd35]');
  561. user_nav.style.verticalAlign = 'middle';
  562. c_usernav.insertBefore(button,c_usernav.firstChild);
  563. button.href = 'https://www.volatiles.us.kg/';
  564. }
  565. else{
  566. button.href = 'https://www.volatiles.us.kg/';
  567. let user_nav = document.querySelector('div.user-nav[data-v-c1098b6a]');
  568. user_nav.insertBefore(button,user_nav.firstChild);
  569. }
  570. const tb = document.getElementById("NLTB");
  571.  
  572. tb.addEventListener('click', function(){
  573. if(nowurl == 'https://www.luogu.com.cn/'){
  574. swal("Better Luogu!","选择一个更改", {
  575. buttons: {
  576. username: {
  577. text: "颜色",
  578. value: "color",
  579. },
  580. hanger: {
  581. text: "勾子",
  582. value: "hanger",
  583. },
  584. tag: {
  585. text: "tag",
  586. value: "tag",
  587. },
  588. update: {
  589. text: "更新",
  590. value: "update",
  591. },
  592. content: {
  593. text: "内容",
  594. value: "content"
  595. },
  596. zb: {
  597. text: "宣传",
  598. value: "zb"
  599. },
  600. not: {
  601. text: "千万别点!!!",
  602. value: "not"
  603. }
  604. },
  605. })
  606. .then((value) => {
  607. switch (value){
  608. case "color":
  609. changeusercolor();
  610. break;
  611. case "hanger":
  612. changehanger();
  613. break;
  614. case "tag":
  615. changetag();
  616. break;
  617. case "update":
  618. deletecookie('update');
  619. setcookie('update','true',114514,'/','luogu.com.cn',true);
  620. window.open('https://greasyfork.org/zh-CN/scripts/487511-better-luogu','_self');
  621. break;
  622. case "content":
  623. update();
  624. break;
  625. case "zb":
  626. zb();
  627. break;
  628. case "not": not();
  629. }
  630. });
  631. }
  632. });
  633.  
  634. let nowuid=getcookie('uid');
  635.  
  636. if(nowurl == 'https://www.luogu.com.cn/'){
  637. if(getcookie('hanger')!='null'){
  638. document.querySelector('#app-old > div.lg-index-content.am-center > div:nth-child(1) > div > div > div > div.am-u-md-4.lg-punch.am-text-center > h2 > a').innerHTML += '&nbsp;';
  639. document.querySelector('#app-old > div.lg-index-content.am-center > div:nth-child(1) > div > div > div > div.am-u-md-4.lg-punch.am-text-center > h2 > a').appendChild(_hanger_);
  640. }
  641. if(getcookie('tag')!=''){
  642. document.querySelector('#app-old > div.lg-index-content.am-center > div:nth-child(1) > div > div > div > div.am-u-md-4.lg-punch.am-text-center > h2 > a').innerHTML += '&nbsp;';
  643. document.querySelector('#app-old > div.lg-index-content.am-center > div:nth-child(1) > div > div > div > div.am-u-md-4.lg-punch.am-text-center > h2 > a').appendChild(tag);
  644. }
  645. $('input[name="user"]').keydown(function(e){
  646. if(e.which===13){
  647. let searchusr=$('input[name="user"]').val();
  648. $.get('https://www.luogu.com.cn/api/user/search?keyword=' + searchusr, {}, function (res) {
  649. var users = res['users'];
  650. if(users[0]!=null){
  651. window.open('https://www.luogu.com.cn/user/'+users[0]['uid'].toString(),'_self');
  652. }
  653. });
  654. }
  655. });
  656. }
  657. else if(nowurl.includes('https://www.luogu.com.cn/user/')&&!nowurl.includes('https://www.luogu.com.cn/user/setting')){
  658. let nowurluid='';
  659. for(let i=0;i<nowurl.length;i++){
  660. if(nowurl[i]>='0'&&nowurl[i]<='9') nowurluid+=nowurl[i];
  661. }
  662. if(nowurluid==getcookie('uid')){
  663. if(getcookie('hanger')!='null'){
  664. let reallyHanger = document.getElementsByClassName('ccf-badge')[0];
  665. if(reallyHanger!=null) reallyHanger.remove();
  666. let fakeHanger=document.createElement('span');
  667. fakeHanger.className='ccf-badge';
  668. fakeHanger.setAttribute('data-v-59a020e0','');
  669. fakeHanger.setAttribute('data-v-f9624136','');
  670. let hangerColor;
  671. if(getcookie('hanger')=='green') hangerColor='#52c41a';
  672. else if(getcookie('hanger')=='blue') hangerColor='#3498db';
  673. else if(getcookie('hanger')=='golden') hangerColor='#ffc116';
  674. fakeHanger.innerHTML='<a data-v-0640126c="" href="/discuss/142324" target="_blank" colorscheme="none" class="color-none"><svg data-v-0640126c="" aria-hidden="true" focusable="false" data-prefix="fad" data-icon="badge-check" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-badge-check" style="--fa-primary-color: #fff; --fa-secondary-color: '+hangerColor+'; --fa-secondary-opacity: 1;"><g data-v-0640126c="" class="fa-duotone-group"><path data-v-0640126c="" fill="currentColor" d="M256 0c36.8 0 68.8 20.7 84.9 51.1C373.8 41 411 49 437 75s34 63.3 23.9 96.1C491.3 187.2 512 219.2 512 256s-20.7 68.8-51.1 84.9C471 373.8 463 411 437 437s-63.3 34-96.1 23.9C324.8 491.3 292.8 512 256 512s-68.8-20.7-84.9-51.1C138.2 471 101 463 75 437s-34-63.3-23.9-96.1C20.7 324.8 0 292.8 0 256s20.7-68.8 51.1-84.9C41 138.2 49 101 75 75s63.3-34 96.1-23.9C187.2 20.7 219.2 0 256 0zM369 209c9.4-9.4 9.4-24.6 0-33.9s-24.6-9.4-33.9 0l-111 111-47-47c-9.4-9.4-24.6-9.4-33.9 0s-9.4 24.6 0 33.9l64 64c9.4 9.4 24.6 9.4 33.9 0L369 209z" class="fa-secondary"></path><path data-v-0640126c="" fill="currentColor" d="M369 175c9.4 9.4 9.4 24.6 0 33.9L241 337c-9.4 9.4-24.6 9.4-33.9 0l-64-64c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l47 47L335 175c9.4-9.4 24.6-9.4 33.9 0z" class="fa-primary"></path></g></svg></a>';
  675. document.querySelector('#app > div.main-container > main > div > div.card.user-header-container.padding-0 > div.user-header-top > div.user-info > div.user-name').appendChild(fakeHanger);
  676. if(nowurl.includes('#activity')){
  677. for(let i=1;;i++){
  678. let dtuser=document.querySelector('#app > div.main-container > main > div > div.full-container > section.main > div > div > div:nth-child('+i.toString()+') > div.main > div.meta > span:nth-child(1)');
  679. if(dtuser==null) break;
  680. let reallyHanger2=document.querySelector('#app > div.main-container > main > div > div.full-container > section.main > div > div > div:nth-child('+i.toString()+') > div.main > div.meta > span:nth-child(1) > span:nth-child(2)')
  681. if(reallyHanger2!=null) reallyHanger2.remove();
  682. let fakeHanger2=document.createElement('span');
  683. fakeHanger2.setAttribute('data-v-79952194','');
  684. let hangerColor2;
  685. if(getcookie('hanger')=='green') hangerColor2='#52c41a';
  686. else if(getcookie('hanger')=='blue') hangerColor2='#3498db';
  687. else if(getcookie('hanger')=='golden') hangerColor2='#ffc116';
  688. fakeHanger2.innerHTML='<a data-v-0640126c="" href="/discuss/142324" target="_blank" colorscheme="none" class="color-none"><svg data-v-0640126c="" aria-hidden="true" focusable="false" data-prefix="fad" data-icon="badge-check" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-badge-check" style="--fa-primary-color: #fff; --fa-secondary-color: '+hangerColor2+'; --fa-secondary-opacity: 1;"><g data-v-0640126c="" class="fa-duotone-group"><path data-v-0640126c="" fill="currentColor" d="M256 0c36.8 0 68.8 20.7 84.9 51.1C373.8 41 411 49 437 75s34 63.3 23.9 96.1C491.3 187.2 512 219.2 512 256s-20.7 68.8-51.1 84.9C471 373.8 463 411 437 437s-63.3 34-96.1 23.9C324.8 491.3 292.8 512 256 512s-68.8-20.7-84.9-51.1C138.2 471 101 463 75 437s-34-63.3-23.9-96.1C20.7 324.8 0 292.8 0 256s20.7-68.8 51.1-84.9C41 138.2 49 101 75 75s63.3-34 96.1-23.9C187.2 20.7 219.2 0 256 0zM369 209c9.4-9.4 9.4-24.6 0-33.9s-24.6-9.4-33.9 0l-111 111-47-47c-9.4-9.4-24.6-9.4-33.9 0s-9.4 24.6 0 33.9l64 64c9.4 9.4 24.6 9.4 33.9 0L369 209z" class="fa-secondary"></path><path data-v-0640126c="" fill="currentColor" d="M369 175c9.4 9.4 9.4 24.6 0 33.9L241 337c-9.4 9.4-24.6 9.4-33.9 0l-64-64c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l47 47L335 175c9.4-9.4 24.6-9.4 33.9 0z" class="fa-primary"></path></g></svg></a>';
  689. dtuser.appendChild(fakeHanger2);
  690. }
  691. let index=document;
  692. const observer = new MutationObserver((mutations) => {
  693. mutations.forEach((mutation) => {
  694. if (mutation.type === 'attributes'){
  695. for(let i=1;;i++){
  696. let dtuser=document.querySelector('#app > div.main-container > main > div > div.full-container > section.main > div > div > div:nth-child('+i.toString()+') > div.main > div.meta > span:nth-child(1)');
  697. if(dtuser==null) break;
  698. let reallyHanger2=document.querySelector('#app > div.main-container > main > div > div.full-container > section.main > div > div > div:nth-child('+i.toString()+') > div.main > div.meta > span:nth-child(1) > span:nth-child(2)')
  699. if(reallyHanger2!=null) reallyHanger2.remove();
  700. let fakeHanger2=document.createElement('span');
  701. fakeHanger2.setAttribute('data-v-79952194','');
  702. fakeHanger2.innerHTML='<a data-v-0640126c="" href="/discuss/142324" target="_blank" colorscheme="none" class="color-none"><svg data-v-0640126c="" aria-hidden="true" focusable="false" data-prefix="fad" data-icon="badge-check" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-badge-check" style="--fa-primary-color: #fff; --fa-secondary-color: ';
  703. let hangerColor3;
  704. if(getcookie('hanger')=='green') hangerColor3='#52c41a';
  705. else if(getcookie('hanger')=='blue') hangerColor3='#3498db';
  706. else if(getcookie('hanger')=='golden') hangerColor3='#ffc116';
  707. fakeHanger2.innerHTML='<a data-v-0640126c="" href="/discuss/142324" target="_blank" colorscheme="none" class="color-none"><svg data-v-0640126c="" aria-hidden="true" focusable="false" data-prefix="fad" data-icon="badge-check" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-badge-check" style="--fa-primary-color: #fff; --fa-secondary-color: '+hangerColor3+'; --fa-secondary-opacity: 1;"><g data-v-0640126c="" class="fa-duotone-group"><path data-v-0640126c="" fill="currentColor" d="M256 0c36.8 0 68.8 20.7 84.9 51.1C373.8 41 411 49 437 75s34 63.3 23.9 96.1C491.3 187.2 512 219.2 512 256s-20.7 68.8-51.1 84.9C471 373.8 463 411 437 437s-63.3 34-96.1 23.9C324.8 491.3 292.8 512 256 512s-68.8-20.7-84.9-51.1C138.2 471 101 463 75 437s-34-63.3-23.9-96.1C20.7 324.8 0 292.8 0 256s20.7-68.8 51.1-84.9C41 138.2 49 101 75 75s63.3-34 96.1-23.9C187.2 20.7 219.2 0 256 0zM369 209c9.4-9.4 9.4-24.6 0-33.9s-24.6-9.4-33.9 0l-111 111-47-47c-9.4-9.4-24.6-9.4-33.9 0s-9.4 24.6 0 33.9l64 64c9.4 9.4 24.6 9.4 33.9 0L369 209z" class="fa-secondary"></path><path data-v-0640126c="" fill="currentColor" d="M369 175c9.4 9.4 9.4 24.6 0 33.9L241 337c-9.4 9.4-24.6 9.4-33.9 0l-64-64c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l47 47L335 175c9.4-9.4 24.6-9.4 33.9 0z" class="fa-primary"></path></g></svg></a>';
  708. dtuser.appendChild(fakeHanger2);
  709. }
  710. }
  711. });
  712. });
  713. const config = {
  714. attributes: true,
  715. characterData: true,
  716. childList: true,
  717. subtree: true,
  718. attributeOldValue: true,
  719. characterDataOldValue: true
  720. };
  721. observer.observe(index,config);
  722. }
  723. }
  724. /*if(getcookie('tag')!=''){
  725. let tagColor;
  726. $.get('https://www.luogu.com.cn/api/user/search?keyword=' + nowurluid, {}, function (res) {
  727. tagColor=res['users'][0]['color'];
  728. });
  729. console.log(tagColor);
  730. GM_addStyle('span[data-v-71731098]{display:inline-block;padding:0 8px;box-sizing:border-box;font-weight:400;line-height:1.5;border-radius:2px;background-color:'+tagColor+'!important;}');
  731. let fakeTag=document.createElement('span');
  732. fakeTag.setAttribute('data-v-71731098','');
  733. fakeTag.setAttribute('data-v-59a020e0','');
  734. fakeTag.style.color='rbg(255,255,255)';
  735. fakeTag.style.fontSize='0.875rem';
  736. fakeTag.style.verticalAlign='middle';
  737. fakeTag.innerHTML=getcookie('tag');
  738. if(getcookie('hanger')=='null'){
  739. if(document.getElementsByClassName('ccf-badge')[0]==null){
  740. document.querySelector('#app > div.main-container > main > div > div.card.user-header-container.padding-0 > div.user-header-top > div.user-info > div.user-name').appendChild(fakeTag);
  741. }
  742. else{
  743. let reallyHanger=document.getElementsByClassName('ccf-badge')[0];
  744. document.querySelector('#app > div.main-container > main > div > div.card.user-header-container.padding-0 > div.user-header-top > div.user-info > div.user-name').insertBefore(fakeTag,reallyHanger);
  745. }
  746. }
  747. else{
  748. let fakeHanger=document.getElementsByClassName('ccf-badge')[0];
  749. document.querySelector('#app > div.main-container > main > div > div.card.user-header-container.padding-0 > div.user-header-top > div.user-info > div.user-name').insertBefore(fakeTag,fakeHanger);
  750. }
  751. }*/
  752. }
  753. let sm=document.querySelector('#app > div.main-container > main > div > div.full-container > section.main > div > div:nth-child(2)');
  754. if(sm!=null){
  755. if(sm.innerHTML.includes('系统维护,该内容暂不可见。')) sm.remove();
  756. }
  757. let jieshao = document.querySelector('#app > div.main-container > main > div > div.full-container > section.main > div > div.introduction.marked');
  758. if(jieshao!=null){
  759. if(jieshao.style.display == 'none') jieshao.removeAttribute('style');
  760. }
  761. let index=document;
  762. const observer = new MutationObserver((mutations) => {
  763. mutations.forEach((mutation) => {
  764. if (mutation.type === 'attributes'){
  765. let sm=document.querySelector('#app > div.main-container > main > div > div.full-container > section.main > div > div:nth-child(2)');
  766. if(sm!=null){
  767. if(sm.innerHTML.includes('系统维护,该内容暂不可见。')) sm.remove();
  768. }
  769. let jieshao = document.querySelector('#app > div.main-container > main > div > div.full-container > section.main > div > div.introduction.marked');
  770. if(jieshao!=null){
  771. if(jieshao.style.display == 'none') jieshao.removeAttribute('style');
  772. }
  773. }
  774. });
  775. });
  776. const config = {
  777. attributes: true,
  778. characterData: true,
  779. childList: true,
  780. subtree: true,
  781. attributeOldValue: true,
  782. characterDataOldValue: true
  783. };
  784. observer.observe(index,config);
  785. }
  786. else if(nowurl.includes('?contestId=')){
  787. let contestID = "";
  788. let contest = nowurl.toString();
  789. for(let i=contest.length-1;i>=0;i--){
  790. if(!(contest[i]>='0'&&contest[i]<='9')) break;
  791. contestID = contest[i] + contestID;
  792. }
  793. let backlist = 'https://www.luogu.com.cn/contest/'+contestID+'#problems';
  794. let backbtn = document.createElement('a');
  795. backbtn.href = backlist;
  796. backbtn.className = 'color-default';
  797. backbtn.innerHTML = '<svg data-v-5a5fcbaa="" data-v-0640126c="" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="right-from-bracket" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-right-from-bracket"><path data-v-5a5fcbaa="" data-v-0640126c="" fill="currentColor" d="M377.9 105.9L500.7 228.7c7.2 7.2 11.3 17.1 11.3 27.3s-4.1 20.1-11.3 27.3L377.9 406.1c-6.4 6.4-15 9.9-24 9.9c-18.7 0-33.9-15.2-33.9-33.9l0-62.1-128 0c-17.7 0-32-14.3-32-32l0-64c0-17.7 14.3-32 32-32l128 0 0-62.1c0-18.7 15.2-33.9 33.9-33.9c9 0 17.6 3.6 24 9.9zM160 96L96 96c-17.7 0-32 14.3-32 32l0 256c0 17.7 14.3 32 32 32l64 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-64 0c-53 0-96-43-96-96L0 128C0 75 43 32 96 32l64 0c17.7 0 32 14.3 32 32s-14.3 32-32 32z" class=""></path></svg>返回题目列表';
  798. document.querySelector('#app > div.main-container > main > div > section.side > div:nth-child(2)').appendChild(br);
  799. document.querySelector('#app > div.main-container > main > div > section.side > div:nth-child(2)').appendChild(backbtn);
  800. }
  801. else if(nowurl.includes('https://www.luogu.com.cn/discuss/')||nowurl.includes('https://www.luogu.com/discuss/')){
  802. let discussID = "";
  803. let discuss = nowurl.toString();
  804. for(let i=discuss.length-1;i>=0;i--){
  805. if(!(discuss[i]>='0'&&discuss[i]<='9')) break;
  806. discussID = discuss[i] + discussID;
  807. }
  808. if(discussID != ""){
  809. let dis = document.createElement('a');
  810. dis.href = 'https://lglg.top/'+discussID;
  811. dis.innerHTML = '<button data-v-f21de448="" data-v-710aa612="" class="solid lform-size-middle" type="button">在保存站打开</button>';
  812. document.querySelector('#app > div.main-container.lside-bar > main > div > div > div.side > div.l-card > div.btn-actions').appendChild(dis);
  813. }
  814. }
  815. else if(nowurl.includes('https://www.luogu.com.cn/chat')){
  816. let index=document;
  817. let once = true;
  818. let menu = document.createElement('button');
  819. menu.className = 'menu';
  820. menu.style.backgroundColor = 'transparent';
  821. menu.style.border = 'none';
  822. menu.style.float = 'right';
  823. menu.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" style="fill: rgba(0, 0, 0, 1);transform: ;msFilter:;"><path d="M4 6h16v2H4zm0 5h16v2H4zm0 5h16v2H4z"></path></svg>';
  824. const observer = new MutationObserver((mutations) => {
  825. mutations.forEach((mutation) => {
  826. if (mutation.type === 'attributes'){
  827. if(once && document.querySelector('#app > div.main-container > main > div > div.card.wrapper.padding-none > div.main > div > div.top-container > div.title')!=null){
  828. once=false;
  829. document.querySelector('#app > div.main-container > main > div > div.card.wrapper.padding-none > div.main > div > div.top-container > div.title').appendChild(menu);
  830. }
  831. }
  832. });
  833. });
  834. const config = {
  835. attributes: true,
  836. characterData: true,
  837. childList: true,
  838. subtree: true,
  839. attributeOldValue: true,
  840. characterDataOldValue: true
  841. };
  842. observer.observe(index,config);
  843. menu.addEventListener('click', function(){
  844. let chatuser = document.querySelector('#app > div.main-container > main > div > div.card.wrapper.padding-none > div.main > div > div.top-container > div.title > span > span > a > span').textContent;
  845. let chatuid=document.querySelector('#app > div.main-container > main > div > div.card.wrapper.padding-none > div.main > div > div.top-container > div.title > span > span > a').href;
  846. let uid='';
  847. for(let i=chatuid.length-1;i>=0;i--){
  848. if(chatuid[i]>='0'&&chatuid[i]<='9') uid=chatuid[i]+uid;
  849. else break;
  850. }
  851. swal("Better Luogu!",chatuser,{
  852. buttons: {
  853. delete: {
  854. text: "清空私信",
  855. value: "delete"
  856. },
  857. quxiao: {
  858. text: "取消",
  859. value: "cancel"
  860. }
  861. }
  862. })
  863. .then((value)=>{
  864. switch(value){
  865. case 'delete':
  866. deleteChat(uid);
  867. break;
  868. }
  869. });
  870. });
  871. }
  872. /*else if(nowurl.includes('https://www.luogu.com.cn/problem/')&&nowurl.includes('#submit')){
  873. let io = document.createElement('div');
  874. let submit = document.querySelector('#app > div.main-container > main > div > section.main > section > div > div:nth-child(2) > button');
  875. io.className='inout';
  876. io.innerHTML='<p>输入</p><textarea id="in" rows="3" col=auto; style="display:block;width:100%;padding:.5em;font-size:1.6rem;line-height:1.2;color:#555;vertical-align:middle;background-color:#fff;background-image:none;border:1px solid #ccc;border-radius:0;-webkit-appearance:none;-webkit-transition:border-color .15s ease-in-out,-webkit-box-shadow .15s ease-in-out;transition:border-color .15s ease-in-out,box-shadow .15s ease-in-out"></textarea>';
  877. document.querySelector('#app > div.main-container > main > div > section.main > section > div > div:nth-child(2)').insertBefore(io,submit);
  878. let run = document.createElement('button');
  879. run.innerHTML='运行';
  880. run.type='button';
  881. run.style.borderColor='rgb(82,196,26)';
  882. run.style.backgroundColor='rgb(82,196,26)';
  883. run.style.marginTop='1em';
  884. run.style.fontFamily='inherit';
  885. run.className='lfe-form-sz-middle';
  886. run.display='inline-block';
  887. run.style.cursor='pointer';
  888. run.style.color='#fff';
  889. run.style.borderRadius='3px';
  890. run.style.border='1px solid';
  891. run.setAttribute('data-v-7ade990c','');
  892. document.querySelector('#app > div.main-container > main > div > section.main > section > div > div:nth-child(2)').appendChild(run);
  893. run.addEventListener('click',function(){
  894. let code='';
  895. });
  896. }*/
  897. }
  898. })();