V2EX增强插件

一些增强功能

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址