new luogu

Luogu Expansion

当前为 2024-04-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name new luogu
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1.0
  5. // @description Luogu Expansion
  6. // @description:zh 洛谷扩展
  7. // @author volatile
  8. // @match https://www.luogu.com.cn/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=luogu.com.cn
  10. // @grant GM_addStyle
  11. // @grant GM_getValue
  12. // @grant GM_setValue
  13. // @grant GM_deleteValue
  14. // @grant GM_listValues
  15. // @grant GM_setClipboard
  16. // @grant GM_xmlhttpRequest
  17. // @grant GM_getResourceText
  18. // @grant unsafeWindow
  19. // @connect https://top.baidu.com/board?tab=realtime
  20. // @license MIT
  21. // ==/UserScript==
  22.  
  23. (function() {
  24. 'use strict';
  25. //进入插件
  26. console.log("This is new luogu");
  27. console.log("\n _____ _____ _____ _____ _____ \n /\\ \\ /\\ \\ /\\ \\ /\\ \\ /\\ \\ \n /::\\____\\ /::\\ \\ /::\\____\\ /::\\____\\ /::\\ \\ \n /::::| | /::::\\ \\ /:::/ / /:::/ / /::::\\ \\ \n /:::::| | /::::::\\ \\ /:::/ _/___ /:::/ / /::::::\\ \\ \n /::::::| | /:::/\\:::\\ \\ /:::/ /\\ \\ /:::/ / /:::/\\:::\\ \\ \n /:::/|::| | /:::/__\\:::\\ \\ /:::/ /::\\____\\ /:::/ / /:::/ \\:::\\ \\ \n /:::/ |::| | /::::\\ \\:::\\ \\ /:::/ /:::/ / /:::/ / /:::/ \\:::\\ \\ \n /:::/ |::| | _____ /::::::\\ \\:::\\ \\ /:::/ /:::/ _/___ /:::/ / /:::/ / \\:::\\ \\ \n /:::/ |::| |/\\ \\ /:::/\\:::\\ \\:::\\ \\ /:::/___/:::/ /\\ \\ /:::/ / /:::/ / \\:::\\ ___\\ \n/:: / |::| /::\\____\\/:::/__\\:::\\ \\:::\\____\\|:::| /:::/ /::\\____\\/:::/____/ /:::/____/ ___\\:::| |\n\\::/ /|::| /:::/ /\\:::\\ \\:::\\ \\::/ /|:::|__/:::/ /:::/ /\\:::\\ \\ \\:::\\ \\ /\\ /:::|____|\n \\/____/ |::| /:::/ / \\:::\\ \\:::\\ \\/____/ \\:::\\/:::/ /:::/ / \\:::\\ \\ \\:::\\ /::\\ \\::/ / \n |::|/:::/ / \\:::\\ \\:::\\ \\ \\::::::/ /:::/ / \\:::\\ \\ \\:::\\ \\:::\\ \\/____/ \n |::::::/ / \\:::\\ \\:::\\____\\ \\::::/___/:::/ / \\:::\\ \\ \\:::\\ \\:::\\____\\ \n |:::::/ / \\:::\\ \\::/ / \\:::\\__/:::/ / \\:::\\ \\ \\:::\\ /:::/ / \n |::::/ / \\:::\\ \\/____/ \\::::::::/ / \\:::\\ \\ \\:::\\/:::/ / \n /:::/ / \\:::\\ \\ \\::::::/ / \\:::\\ \\ \\::::::/ / \n /:::/ / \\:::\\____\\ \\::::/ / \\:::\\____\\ \\::::/ / \n \\::/ / \\::/ / \\::/____/ \\::/ / \\::/____/ \n \\/____/ \\/____/ ~~ \\/____/ \n ");
  28.  
  29. var css = ".newlgmenu{width: 100vw; height: 100vh; display: none; align-items: center; justify-content: center; } .NEWLG-menu{width: 600px; height: 400px; display: flex; flex-direction: column; padding: 40px; position: relative; z-index: 100; background: inherit; border-radius: 18px; overflow: hidden; } .NEWLG-menu::before{ content: \"\"; width: calc\(100% + 20px\); height: calc\(100% + 20px\); position: absolute; top: -10px; left: -10px; overflow:hidden; background: inherit; box-shadow: inset 0 0 0 200px rgba\(255, 255, 255, 0.75\); filter: blur\(5px\); z-index: -1; } .NEWLG-menu input { margin: 6px 0; height: 36px; border: none; background-color: rgba\(255, 255, 255, 0.75\); border-radius: 4px; padding: 0 14px; color: #3d5245; }";
  30. var style = document.createElement("style");
  31. style.innerHTML = css;
  32. document.head.appendChild(style);
  33.  
  34. let nowurl = window.location.href;
  35. console.log(nowurl);
  36.  
  37. function getcookie(name){
  38. const cookiestring = document.cookie;
  39. const cookies = cookiestring.split('; ');
  40. for(const cookie of cookies){
  41. const [cookiename, cookievalue] = cookie.split('=');
  42. if(cookiename === name) return cookievalue;
  43. }
  44. const time = new Date();
  45. time.setDate(time.getDate() + 365);
  46. document.cookie = "color=lg-fg-purple" + ";expires=" + time.toUTCString();
  47. return "lg-fg-purple";
  48. }
  49.  
  50. let _username;
  51.  
  52. GM_xmlhttpRequest({
  53. method: "GET",
  54. url: 'https://www.luogu.com.cn/',
  55. onload: function(response){
  56. let username = new DOMParser();
  57. let doc1 = username.parseFromString(response.responseText, "text/html");
  58. _username = doc1.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').textContent;
  59. }
  60. });
  61.  
  62. //首页
  63. if(nowurl == 'https://www.luogu.com.cn/'){
  64. //日历
  65. const today=new Date();
  66. const year=today.getFullYear();
  67. const month=String(today.getMonth()+1);
  68. const day=String(today.getDate());
  69. console.log(year);
  70. console.log(month);
  71. console.log(day);
  72. let date_html='<h2>今天是 '+year+'-'+month+'-'+day+'</h2>';
  73. if(month==1&&day==1){
  74. date_html+='<h2>今天是元旦,新的一年,新的开始</h2>';
  75. }
  76. else if(month==2&&day==29){
  77. date_html+='<h2>今年是闰年</h2>';
  78. }
  79. else if(month==4&&day==1){
  80. date_html+='<h2>今天是愚人节</h2>';
  81. }
  82. else if(month==5&&day==1){
  83. date_html+='<h2>今天是劳动节</h2>';
  84. }
  85. else if(month==6&&day==1){
  86. date_html+='<h2>今天是儿童节</h2>';
  87. }
  88. else if(month==9&&day==10){
  89. date_html+='<h2>今天是教师节</h2>';
  90. }
  91. else if(month==10&&day==1){
  92. date_html+='<h2>今天是国庆节,七天小长假,启动!</h2>'
  93. }
  94. else if(month==12&&day==31){
  95. date_html+='<h2>明年见</h2>';
  96. }
  97. else if(month==4&&day==28){
  98. let years=year-2012;
  99. date_html+='<h2>今天是作者生日的后 '+years+' 年</h2>';
  100. }
  101. else{
  102. date_html+='<h2>欢迎!</h2>';
  103. }
  104. let date = document.createElement('div');
  105. date.className = 'lg-article';
  106. date.innerHTML = date_html;
  107. document.querySelector('div.lg-right > div:nth-child(1)').insertAdjacentElement('beforebegin', date);
  108.  
  109. //更改用户名颜色
  110. 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');
  111. let changecolor = getcookie('color');
  112. console.log(color);
  113. if(changecolor != 'null') color.className=changecolor;
  114.  
  115. document.querySelector('#app-old > div.lg-index-content.am-center > div:nth-child(3) > div.am-u-lg-3.am-u-md-4.lg-right > div:nth-child(3) > div:nth-child(5)').remove();
  116. document.querySelector('#app-old > div.lg-index-content.am-center > div:nth-child(3) > div.am-u-lg-3.am-u-md-4.lg-right > div:nth-child(3) > div').remove();
  117.  
  118. GM_xmlhttpRequest({
  119. method: "GET",
  120. url: 'https://top.baidu.com/board?tab=realtime',
  121. onload: function(response){
  122. let rs = new DOMParser();
  123. let doc = rs.parseFromString(response.responseText, "text/html");
  124. for(let i=1;i<=5;i++){
  125. let th = i.toString();
  126. 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';
  127. let _rs = doc.querySelector(selector);
  128. console.log(_rs.textContent);
  129. let selector2 = '#sanRoot > main > div.container.right-container_2EFJr > div > div:nth-child(2) > div:nth-child(' + th + ') > div.content_1YWBm > a';
  130. let rslink = doc.querySelector(selector2);
  131. console.log(rslink);
  132. let link = document.createElement("a");
  133. link.href = rslink.href;
  134. link.textContent = _rs.textContent;
  135. let RS = document.createElement("p");
  136. RS.appendChild(link);
  137. document.querySelector('#app-old > div.lg-index-content.am-center > div:nth-child(3) > div.am-u-lg-3.am-u-md-4.lg-right > div:nth-child(3) > h2:nth-child(4)').parentNode.append(RS);
  138. }
  139. }
  140. });
  141. }
  142.  
  143. window.onload = function(){
  144. let button = document.createElement("div");
  145. button.innerHTML = '<button 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;\">NEWLG</button>';
  146. 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);
  147. let menu = document.createElement("div");
  148. menu.innerHTML = '<div class=\"newlgmenu\"><from class=\"NEWLG-menu\"><h2>v1.0.1</h2><h3>用户名颜色</h3><input type="text" value="更改名字颜色为(如“紫名”“复原”)" id="nlcolor"><button>提交</button></from></div>';
  149. document.querySelector("#app > div.main-container > div.wrapper.wrapped.lfe-body.header-layout.tiny > div.container").parentNode.append(menu);
  150. const tb = document.querySelector('#app > div.main-container > div.wrapper.wrapped.lfe-body.header-layout.tiny > div.container > div:nth-child(3) > button');
  151. tb.addEventListener('click', function(){
  152. let menudisplay = document.querySelector('#app > div.main-container > div.wrapper.wrapped.lfe-body.header-layout.tiny > div:nth-child(3) > div');
  153. if(menudisplay.style.display == 'none') menudisplay.style.display = 'flex';
  154. else menudisplay.style.display = 'none';
  155.  
  156. const submitcolor = document.querySelector('#app > div.main-container > div.wrapper.wrapped.lfe-body.header-layout.tiny > div:nth-child(3) > div > from > button');
  157. submitcolor.addEventListener('click', function(){
  158. let colorchange = document.getElementById('nlcolor').value;
  159. console.log(colorchange);
  160. if(colorchange=='灰名'){
  161. const time = new Date();
  162. time.setDate(time.getDate() + 365);
  163. document.cookie = "color=lg-fg-gray" + ";expires=" + time.toUTCString();
  164. location.reload();
  165. }
  166. else if(colorchange=='蓝名'){
  167. const time = new Date();
  168. time.setDate(time.getDate() + 365);
  169. document.cookie = "color=lg-fg-blue" + ";expires=" + time.toUTCString();
  170. location.reload();
  171. }
  172. else if(colorchange=='绿名'){
  173. const time = new Date();
  174. time.setDate(time.getDate() + 365);
  175. document.cookie = "color=lg-fg-green" + ";expires=" + time.toUTCString();
  176. location.reload();
  177. }
  178. else if(colorchange=='橙名'){
  179. const time = new Date();
  180. time.setDate(time.getDate() + 365);
  181. document.cookie = "color=lg-fg-orange" + ";expires=" + time.toUTCString();
  182. location.reload();
  183. }
  184. else if(colorchange=='红名'){
  185. const time = new Date();
  186. time.setDate(time.getDate() + 365);
  187. document.cookie = "color=lg-fg-red" + ";expires=" + time.toUTCString();
  188. location.reload();
  189. }
  190. else if(colorchange=='紫名'){
  191. const time = new Date();
  192. time.setDate(time.getDate() + 365);
  193. document.cookie = "color=lg-fg-purple" + ";expires=" + time.toUTCString();
  194. location.reload();
  195. }
  196. else if(colorchange=='复原'){
  197. const time = new Date();
  198. time.setDate(time.getDate() + 365);
  199. document.cookie = "color=null" + ";expires=" + time.toUTCString();
  200. location.reload();
  201. }
  202. });
  203. });
  204. if(nowurl.includes('https://www.luogu.com.cn/user/')&&!nowurl.includes('https://www.luogu.com.cn/user/setting')){
  205. if(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 > span').textContent != _username) document.querySelector('#app > div.main-container > main > div > div.full-container > section.main > div > div:nth-child(2)').remove();
  206. let jieshao = document.querySelector('#app > div.main-container > main > div > div.full-container > section.main > div > div.introduction.marked');
  207. if(jieshao.style.display == 'none') jieshao.removeAttribute('style');
  208. }
  209. };
  210. // Your code here...
  211. })();