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