V2EX_Good

一些增强功能

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