V2EX增强插件

1.回复标记楼主ID 2.每天打开V2EX网站任意页面时自动领取签到的登陆奖励 3.回复时可@所有人 4.召唤/呼叫管理员 5.链接自动转图片

目前为 2023-12-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name V2EX增强插件
  3. // @description 1.回复标记楼主ID 2.每天打开V2EX网站任意页面时自动领取签到的登陆奖励 3.回复时可@所有人 4.召唤/呼叫管理员 5.链接自动转图片
  4. // @namespace yfmx746qpx8vhhmrgzt9s4cijmejj3tn
  5. // @icon http://ww1.sinaimg.cn/large/4ec98f50jw1e85azvlnh9j206y06y3ye.jpg
  6. // @author me
  7. // @include https://*.v2ex.com/*
  8. // @include https://v2ex.com/*
  9. // @version 2023.12.27
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. // 2023.12.27 避免链接转图片的大小超出布局
  14. // 2021.11.26 账户余额页面增加签到页面链接
  15. // 2020.10.19 首页增加全文搜索链接
  16. // 2020.10.10 解决由于改版导致的定位错误导致无法签到问题
  17. // 2019.10.25 解决Safari不能重加载新浪图片
  18. // 2019.08.01 修正帖子tag区域的链接转图片误判
  19. // 2019.05.12 新浪的图片反防盗链
  20. // 2017.05.16 由于存储数据出错,改变存储数据的方式
  21. // 2016.09.21 修复发帖页面判断用户名出错的情况
  22. // 2016.09.14 修正判断登录状态逻辑
  23. // 2016.05.25 链接自动转图片
  24. // 2016.05.21 新增召唤/呼叫管理员
  25. // 2016.05.09 Webkit内核允许修改回复框高度
  26. // 2016.04.12 在回复时可@所有人
  27. // 2015.10.16 新增在回复中标记楼主
  28. // 2015.03.22 尝试修正未知原因情况下导致的签到失败。
  29. // 2015.02.07 解决JQuery库在某种情况可能会无法载入
  30. // 2014.10.07 某种情况下会产生cookie重复赋值,增加清理补丁。
  31. // 2014.10.06 cookie信息过期时间改为3天
  32.  
  33.  
  34. //签到
  35. (function(){
  36. var load, execute, loadAndExecute;
  37. load = function(a, b, c) {
  38. var d;
  39. d = document.createElement("script"), d.setAttribute("src", a), b != null && d.addEventListener("load", b), c != null && d.addEventListener("error", c), document.body.appendChild(d);
  40. return d;
  41. }, execute = function(a) {
  42. var b, c;
  43. typeof a == "function" ? b = "(" + a + ")();" : b = a, c = document.createElement("script"), c.textContent = b, document.body.appendChild(c);
  44. return c;
  45. }, loadAndExecute = function(a, b) {
  46. return load(a, function() {
  47. return execute(b);
  48. });
  49. };
  50.  
  51. loadAndExecute("//lib.sinaapp.com/js/jquery/2.0/jquery.min.js", function() {
  52. if ( $("a[class='balance_area']").length > 0 && $("a[href='/settings']").length > 0 ) {
  53. var uid=$.find('a[href^="/member/"]')[0].innerHTML;//用户名
  54. var dateinfo=new Date().getUTCDate();//获得GMT时间今天几号
  55. var SigninInfo=uid + ":" + dateinfo + "";
  56. var daily = $('input[id="search"]');
  57. if (daily.length && localStorage.SigninInfo != SigninInfo ) {
  58. $.ajax({url:"/"});
  59. daily.val("正在检测每日签到状态...");
  60. $.ajax({
  61. url: "/mission/daily",
  62. success: function(data) {
  63. var awards = $(data).find('input[value^="领取"]');
  64. if (awards.length) {
  65. // daily.val("正在" + awards.attr("value") + "...");
  66. daily.val("正在领取今日的登录奖励......");
  67. $.ajax({
  68. url: awards.attr('onclick').match(/(?=\/).+?(?=\')/),
  69. success: function(data) {
  70. daily.val("正在提交...");
  71. var days=data.split("已连续登")[1].split(" ")[1];
  72. if ( $('a[href="/mission/daily"]').length==1 ) {$('a[href="/mission/daily"]').parent().parent().fadeOut(3000);}
  73. $.ajax({
  74. url: "/balance",
  75. success: function(data) {
  76. function p(s) {return s < 10 ? '0' + s: s;} //自动补0
  77. var date2="" + new Date().getUTCFullYear() + p(new Date().getUTCMonth()+1) +p(new Date().getUTCDate());
  78. if (data.indexOf(date2+" 的每日登录奖励")!="-1") {
  79. daily.val( "已连续领取" + days + "天,本次领到" + data.split("每日登录")[2].split(" ")[1] + "铜币" );
  80. localStorage.SigninInfo = SigninInfo;
  81. } else {
  82. daily.val( "自动领取遇到意外,你可以试试手动领。" );
  83. }
  84. }
  85. });
  86. },
  87. error: function() {
  88. daily.val("网络异常 :(");
  89. }
  90. });
  91. }else{
  92. if (data.indexOf("已领取") != -1) {
  93. daily.val("今日奖励领取过了");
  94. localStorage.SigninInfo = SigninInfo;
  95. } else {
  96. daily.val("无法辩识领奖按钮 :(");
  97. }
  98.  
  99. }
  100. },
  101. error: function() {
  102. daily.val("请手动领取今日的登录奖励!");
  103. }
  104. });
  105. } else {
  106. //console.log("");
  107. }
  108. }
  109. });
  110. })();
  111.  
  112. //标记楼主
  113. (function (){
  114. var uid=document.getElementById("Rightbar").getElementsByTagName("a")[0].href.split("/member/")[1];//自己用户名
  115. if (location.href.indexOf(".com/t/") != -1) {
  116. var lzname=document.getElementById("Main").getElementsByClassName("avatar")[0].parentNode.href.split("/member/")[1];
  117. var allname='@'+lzname+' ';
  118. var all_elem = document.getElementsByClassName("dark");
  119. for(var i=0; i<all_elem.length; i++) {
  120. if (all_elem[i].innerHTML == lzname){
  121. all_elem[i].innerHTML += " <font color=green>[楼主]</font>";
  122. }
  123. //为回复所有人做准备
  124. if ( uid != all_elem[i].innerHTML && all_elem[i].href.indexOf("/member/") != -1 && all_elem[i].innerText == all_elem[i].innerHTML && allname.indexOf('@'+all_elem[i].innerHTML+' ') == -1 ) {
  125. allname+='@'+ all_elem[i].innerHTML+' ';
  126. }
  127. }
  128. }
  129.  
  130. if ( document.getElementById("reply_content") ) {
  131. document.getElementById("reply_content").parentNode.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:;' onclick='if ( document.getElementById(\"reply_content\").value.indexOf(\""+allname+"\") == -1 ) {document.getElementById(\"reply_content\").value+=\"\\r\\n"+allname+"\"}'>@所有人</a>";
  132. if ( document.body.style.WebkitBoxShadow !== undefined ) {
  133. //允许调整回复框高度
  134. document.getElementById("reply_content").style.resize="vertical";
  135. }
  136. document.getElementById("reply_content").style.overflow="auto";
  137. var magagers="@Livid @Kai @Olivia @GordianZ @sparanoid @Girlphobia";
  138. document.getElementById("reply_content").parentNode.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:;' onclick='if ( document.getElementById(\"reply_content\").value.indexOf(\""+magagers+"\") == -1 ) {document.getElementById(\"reply_content\").value+=\"\\r\\n"+magagers+"\"}'>@管理员</a>";
  139. }
  140. })();
  141.  
  142. // 图片链接自动转换成图片 代码来自caoyue@v2ex
  143. (function (){
  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)/i.test(link.href)
  148. && !/<img\s/i.test(link.innerHTML) && link.href.indexOf("v2ex.com/tag")==-1){
  149. link.innerHTML = "<img title='" + link.href + "' src='" + link.href + "' style='max-width:98%' />";
  150. }
  151. }
  152. })();
  153. //
  154.  
  155. //新浪图床的图片反防盗链
  156. (function (){
  157. var images = document.images;
  158. for (var i=0;i<images.length;i++){
  159. var image = images[i];
  160. if ( image.src && image.src.indexOf(".sinaimg.cn")!=-1 &&image.src.indexOf(".sinaimg.cn")<13 ) {
  161. image.setAttribute("referrerPolicy","no-referrer");
  162. image.src=image.src + "?";
  163. }
  164. }
  165. })();
  166. //
  167.  
  168. // 增加全文搜索链接
  169. if ( $('div[id="SecondaryTabs"]').length > 0 ) {
  170. document.getElementById("SecondaryTabs").innerHTML+='&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://www.sov2ex.com/" >全文搜索</a>'
  171. }
  172. //
  173.  
  174. // 在账户余额界面/明细界面的上方增加签到页面链接
  175. if ( location.href.indexOf("/balance") != -1 && document.getElementsByClassName("tab").length > 0) {
  176. document.getElementsByClassName("tab")[0].parentNode.innerHTML+='<a class="tab" href="/mission/daily" >签到</a>'
  177. }
  178. //