Greasy Fork 支持简体中文。

V2EX增强插件

一些增强功能

目前為 2025-05-02 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name V2EX增强插件
  3. // @description 一些增强功能
  4. // @homepage https://greasyfork.org/zh-CN/scripts/3452
  5. // @namespace yfmx746qpx8vhhmrgzt9s4cijmejj3tn
  6. // @icon https://favicon.yandex.net/favicon/www.v2ex.com
  7. // @author me
  8. // @match https://*.v2ex.com/*
  9. // @match https://v2ex.com/*
  10. // @version 2025.05.03.1
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. // 2025.05.03 按关键词屏蔽帖子中的垃圾回复。
  15. // 2025.04.03 签到页显示上次签到铜币数,余额页面显示签到页链接
  16. // 2025.04.03 各功能均改为异步执行,缩短脚本运行时间。
  17. // 2025.03.30 原生代码实现签到功能,去除对jQuery库的依赖
  18. // 2024.03.08 新消息界面,回复提醒对比感谢提醒更加醒目
  19. // 2024.01.16 新消息界面,显示消息序号,页码链接显示序号范围
  20. // 2023.12.27 避免链接转图片的大小超出布局
  21. // 2019.05.12 新浪的图片反防盗链
  22. // 2017.05.16 由于存储数据出错,改变存储数据的方式
  23. // 2016.05.25 链接自动转图片
  24. // 2016.05.21 新增召唤/呼叫管理员
  25. // 2016.04.12 在回复时可@所有人
  26. // 2015.10.16 新增在回复中标记楼主
  27. // 2014.01.24 初版修改版
  28.  
  29.  
  30. setTimeout(function(){
  31.  
  32. // 签到
  33. setTimeout(() => {
  34. if (document.querySelector('a.balance_area') && document.querySelector('a[href="/settings"]')) {//已登陆
  35. var username = document.querySelector('a[href^="/member/"]').innerHTML;
  36. var today=new Date().toISOString().split("T")[0];
  37. var infobar = document.querySelector('#search');
  38. if(localStorage.signdate==today && localStorage.signuser==username && infobar){
  39. return;//已签到就结束
  40. }
  41. var days=0;//连续登陆天数
  42. //开始签到流程
  43. fetch("/").then(()=>{
  44. //document.querySelector("#search").style.fontSize="14px";
  45. infobar.value = "正在检测每日签到状态...";
  46. return fetch("/mission/daily");//继续继续,前往领取页面
  47. })
  48. .then(rsp => rsp.text()).then(data=>{
  49. var parser = new DOMParser();
  50. var doc = parser.parseFromString(data, "text/html");
  51. if(doc.querySelector('input[value^="领取"]')){//领取按钮存在,尝试领取
  52. infobar.value = "正在领取签到奖励..."
  53. var url=doc.querySelector('input[value^="领取"]').getAttribute('onclick').split("'")[1];
  54. //<input type="button" class="xxx" value="领取 X 铜币" onclick="location.href = '/mission/daily/redeem?once=12345';">
  55. return fetch(url)//继续继续,提交领取动作
  56. } else {//按钮不存在
  57. if (data.indexOf("已领取") != -1) {
  58. localStorage.signdate=today;
  59. localStorage.signuser=username;
  60. throw new Error(infobar.value = "今天已经签到了。");
  61. } else {
  62. throw new Error(infobar.value = "无法识别领取奖励按钮 :( ");
  63. }
  64. }
  65. })
  66. .then(rsp => rsp.text()).then(data=>{
  67. days=data.split("已连续登")[1].split(" ")[1];//连续登陆天数
  68. localStorage.signdate=today;
  69. localStorage.signuser=username;
  70. //若是首页,签到入口隐藏
  71. if(document.querySelector('a[href="/mission/daily"]')){
  72. document.querySelector('a[href="/mission/daily"]').parentElement.parentElement.style.display="none";
  73. }
  74. return fetch("/balance");//继续继续,查看领取数量
  75. })
  76. .then(rsp => rsp.text()).then(data=>{
  77. if (data.indexOf("每日登录奖励")!== -1){
  78. var money=data.match(/每日登录奖励 \d+ 铜币/)[0].match(/\d+/)[0];
  79. localStorage.signmoney=money;
  80. console.log(infobar.value = "连续签到" + days + "天,本次" + money + "铜币");
  81. } else {
  82. console.log(infobar.value = "未能识别到领取");
  83. }
  84. })
  85. .catch(error => {
  86. console.error("Sign info:", error);
  87. if(typeof error=="string" && error.indexOf("已经签到") == -1) {
  88. infobar.value = "请手动领取今日的登录奖励!";
  89. }
  90. });//end fetch
  91. }//end 判断登陆状态
  92. }, 0);// end 签到
  93.  
  94. // 按关键词屏蔽帖子中的垃圾回复
  95. setTimeout(() => {
  96. var lowkeys = ["已 block", "已经 block"];
  97. var check = false;
  98. if (document.querySelector('div[id^=r_]')) {
  99. var replys_html = document.querySelector('div[id^=r_]').parentElement.innerHTML;
  100. check = lowkeys.some(key => replys_html.indexOf(key) != -1)
  101. }
  102. if (check) {
  103. var lowcount = 0;
  104. document.querySelectorAll('div[id^=r_]').forEach(ele => {
  105. var reply_html = ele.innerHTML;
  106. lowkeys.some(key => {
  107. if (reply_html.indexOf(key) != -1) {
  108. ele.style.display = "none";
  109. lowcount++;
  110. return true;
  111. }
  112. });
  113. })
  114. if (lowcount > 0) {
  115. document.querySelector('div[class="fr topic_stats"]').innerHTML += "隐藏回复 " + lowcount + "&nbsp;";
  116. }
  117. }
  118. }, 0);//end 按关键词屏蔽帖子中的垃圾回复
  119. //帖子标记个别没有自动标记的管理员,回复所有人
  120. if (location.href.indexOf("/t/") != -1) {
  121. setTimeout(() => {
  122. var modarr=["Livid","Kai","Olivia","GordianZ","sparanoid","Tink","ano"];
  123. var modlist="@"+modarr.join(" @");//生成@所有管理员的列表
  124. var uname=document.getElementById("Rightbar").getElementsByTagName("a")[0].href.split("/member/")[1];//自己用户名
  125. //标记管理员,预存回复用户名列表
  126. var lzname=document.getElementById("Main").getElementsByClassName("avatar")[0].parentNode.href.split("/member/")[1];
  127. var allname='@'+lzname+' ';
  128. var all_elem = document.querySelectorAll('a[href^="/member"].dark');
  129. for(var i=0; i<all_elem.length; i++) {
  130. if (modlist.indexOf(all_elem[i].innerHTML)!= -1){
  131. if (document.getElementsByClassName("badges")[i].innerHTML.indexOf("mod") == -1){
  132. document.getElementsByClassName("badges")[i].innerHTML+='<div class="badge mod">MOD</div>';
  133. }
  134. }
  135. //为回复所有人做准备
  136. if ( uname != all_elem[i].innerHTML && all_elem[i].href.indexOf("/member/") != -1
  137. && all_elem[i].innerText == all_elem[i].innerHTML && allname.indexOf('@'+all_elem[i].innerHTML+' ') == -1 ) {
  138. allname+='@'+ all_elem[i].innerHTML+' ';
  139. }
  140. }
  141. if ( document.getElementById("reply_content") ) {
  142. document.getElementById("reply_content").parentNode.innerHTML
  143. +="&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:;' onclick='if ( document.getElementById(\"reply_content\").value.indexOf(\""
  144. +allname+"\") == -1 ) {document.getElementById(\"reply_content\").value+=\"\\r\\n"+allname+"\"}'>@所有人</a>";
  145. if ( document.body.style.WebkitBoxShadow !== undefined ) {
  146. //允许调整回复框高度
  147. document.getElementById("reply_content").style.resize="vertical";
  148. }
  149. document.getElementById("reply_content").style.overflow="auto";
  150. document.getElementById("reply_content").parentNode.innerHTML
  151. +="&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:;' onclick='if ( document.getElementById(\"reply_content\").value.indexOf(\""
  152. +modlist+"\") == -1 ) {document.getElementById(\"reply_content\").value+=\"\\r\\n"+modlist+"\"}'>@管理员</a>";
  153. }
  154. }, 0);// end setTimeout
  155. }// end 回复所有人,@管理员
  156.  
  157. // 帖子回复框增加快捷回复,提示广告贴应发在推广节点
  158. if (location.href.indexOf("/t/") != -1) {
  159. (function(){
  160. document.getElementById("reply_content").parentNode.innerHTML
  161. +="&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:;' onclick='document.getElementById(\"reply_content\").value+=\"\\r\\n"+"@Livid 这贴明显是推广贴,却没有发在推广节点。"+"\"'>报告广告贴</a>";
  162. })()
  163. }// end 举报广告贴链接
  164.  
  165. // 图片链接自动转换成图片 参考caoyue@v2ex
  166. setTimeout(() => {
  167. var links = document.links;
  168. for (var i=0;i<links.length;i++){
  169. var link = links[i];
  170. if (/^http.*\.(?:jpg|jpeg|jpe|bmp|png|gif|webp)/i.test(link.href)
  171. && !/<img\s/i.test(link.innerHTML)
  172. && link.href.indexOf("v2ex.com/tag")==-1
  173. && link.href.indexOf("v2ex.com/i/")==-1){
  174. link.innerHTML = "<img title='" + link.href + "' src='" + link.href + "' style='max-width:98%' decoding='async' loading='lazy' />";
  175. // decoding='async'异步解析图像,加快显示其他内容。loading='lazy'懒加载。
  176. // 排除v2ex赞助者图床网页误判 例子 https://v2ex.com/i/Ve5X51qb.png
  177. }
  178. }
  179. }, 0);// end 图片链接自动转换成图片
  180.  
  181. //新浪图床的图片反防盗链
  182. setTimeout(() => {
  183. Array.from(document.images).forEach(ele=>{
  184. if (ele.src.indexOf(".sinaimg.cn")!=-1) {
  185. ele.setAttribute("referrerPolicy","no-referrer");
  186. ele.src="https://image.baidu.com/search/down?thumburl=https://baidu.com&url="+ele.src;
  187. }
  188. })
  189. }, 0);// end 新浪图床的图片反防盗链
  190.  
  191. // 在账户余额界面/明细界面的上方增加签到页面链接
  192. if ( location.pathname == '/balance') {
  193. setTimeout(() => {
  194. document.querySelectorAll('span[class="gray"]').forEach(ele=>{
  195. if(ele.parentElement.innerHTML.indexOf("当前账户余额") != -1){
  196. ele.parentElement.innerHTML+='<div><li class="fa fa-question-circle gray"><a href="/mission/daily" > 查看签到页面</a></li></div>'
  197. }
  198. });
  199. }, 0);// end setTimeout
  200. }
  201. //余额页面显示签到页面链接
  202.  
  203. //在签到页面显示了上次领取铜币数量
  204. if(location.pathname == "/mission/daily" && typeof localStorage.getItem("Signmoney") == 'string'){
  205. setTimeout(() => {
  206. if(localStorage.signuser == document.querySelector('a[href^="/member/"]').innerHTML)
  207. document.querySelectorAll('div[class="cell"]').forEach(ele=>{
  208. if(ele.innerHTML.indexOf("已连续登录") == 0 ){
  209. ele.innerHTML += ",最近一次领取了 "+localStorage.signmoney+" 铜币。";
  210. }
  211. })
  212. }, 0);// end setTimeout
  213. }//end 签到页上次领取铜币数量
  214.  
  215. // 新消息界面,显示消息序号,页码链接显示序号范围
  216. if (location.href.indexOf("/notifications") != -1){
  217. setTimeout(() => {
  218. var page_index=new URL(window.location.href).searchParams.get('p');
  219. var before_index=0;
  220. if(page_index!=null){
  221. before_index=(page_index-1)*50;
  222. }
  223. document.querySelectorAll("a[onclick^=delete]").forEach((ele,i)=>{
  224. var index_ele=document.createElement("span");
  225. index_ele.innerText=(i+1+before_index)+". ";
  226. ele.parentElement.insertBefore(index_ele,ele.parentElement.firstElementChild)
  227. })
  228. var allmsgcount=document.querySelectorAll(".header .gray")[0].innerText;//消息总数
  229. document.querySelectorAll(".page_current,.page_normal").forEach((ele)=>{
  230. var index_a=(ele.innerText-1)*50+1;
  231. var index_b=(ele.innerText-1)*50+50;
  232. var title_str=index_a+"-"+index_b;
  233. if(allmsgcount-index_a<50){
  234. title_str=index_a+"-"+allmsgcount;
  235. }
  236. ele.setAttribute("title",title_str)
  237. })
  238. }, 0);
  239. }// end 新消息界面,序号和翻页按钮优化
  240.  
  241. // 新消息界面,回复提醒对比感谢提醒更加醒目
  242. if (location.href.indexOf("/notifications") != -1){
  243. setTimeout(() => {
  244. if(document.querySelectorAll(".payload").length > 0){
  245. document.querySelectorAll(".payload").forEach((ele) => {
  246. if(ele.parentElement.innerText.indexOf("时提到了你") != -1
  247. || ele.parentElement.innerText.indexOf("里回复了你") != -1 ){
  248. //1、被人@提醒。2、回复我的主题提醒。
  249. ele.style.backgroundColor="#F9EA9A";
  250. }
  251. })
  252. }
  253. }, 0);// end setTimeout
  254. }// end 新消息界面优化
  255.  
  256. //清理一些这样那样的东西
  257. if(new Date().toISOString().split("T")[0] != localStorage.cleardate){
  258. setTimeout(() => {
  259. for (var i = localStorage.length-1; i >= 0 ; i--) {
  260. if(localStorage.key(i).indexOf("lscache") == 0){
  261. localStorage.removeItem(localStorage.key(i));
  262. }
  263. }
  264. if(typeof localStorage.getItem("SigninInfo") == 'string'){
  265. localStorage.removeItem("SigninInfo");
  266. }
  267. }, 0);// end setTimeout
  268. }// end 清理东西
  269.  
  270. },0);// end