V2EX Pro

为V2EX添加自动签到、新标签页打开、替换站内搜索、提醒所有人、楼中楼、自动解析图片链接等功能

  1. // ==UserScript==
  2. // @name V2EX Pro
  3. // @description 为V2EX添加自动签到、新标签页打开、替换站内搜索、提醒所有人、楼中楼、自动解析图片链接等功能
  4. // @icon https://i.loli.net/2020/03/13/DMA2TbVNUwyoFcQ.jpg
  5. // @author yjxjn
  6. // @include https://*.v2ex.com/*
  7. // @include https://v2ex.com/*
  8. // @version 1.2.8
  9. // @grant none
  10. // @namespace https://gf.qytechs.cn/users/457965
  11. // @homepageURL https://gf.qytechs.cn/users/457965
  12. // ==/UserScript==
  13.  
  14. //移动端网页转换为PC版
  15. (function (){
  16. var url = location.href;
  17. if (url.indexOf("/amp/") > 0) {
  18. var url1 = url.replace("/amp/", "/");
  19. var url2 = url1.slice(url1.indexOf("/t/") + 1).split('/')
  20. // console.log(location.protocol+"//www.v2ex.com/t/"+url2[1])
  21. location.replace(location.protocol+"//www.v2ex.com/t/"+url2[1]);
  22. }
  23. var nowurl = location.pathname;
  24. if (nowurl == "/" || nowurl.substr(0, 6) == "/?tab=" || nowurl.substr(0, 4) == "/go/" || nowurl == "/recent") {
  25. $("span.item_title a").attr("target", "_blank");
  26. }
  27. })();
  28.  
  29. //替换为SOV2EX搜索 TODO 没时间,哪天整
  30. (function() {
  31. function exec() {
  32. window.dispatch = function () {
  33. var value = document.getElementById('search').value
  34. if ( value) {
  35. var url = "https://www.sov2ex.com/?q=" + encodeURIComponent(value);
  36. if (window.open) {
  37. window.open(url + '&sort=created', '_blank')
  38. } else{
  39. location.href = url
  40. }
  41. return false
  42. }
  43. return false
  44. }
  45. }
  46. window.addEventListener('load', exec, false)
  47. })();
  48. //自动签到 代码来自caoyue@v2ex
  49. (function(){
  50. var load, execute, loadAndExecute;
  51. load = function(a, b, c) {
  52. var d;
  53. d = document.createElement("script"), d.setAttribute("src", a), b != null && d.addEventListener("load", b), c != null && d.addEventListener("error", c), document.body.appendChild(d);
  54. return d;
  55. }, execute = function(a) {
  56. var b, c;
  57. typeof a == "function" ? b = "(" + a + ")();" : b = a, c = document.createElement("script"), c.textContent = b, document.body.appendChild(c);
  58. return c;
  59. }, loadAndExecute = function(a, b) {
  60. return load(a, function() {
  61. return execute(b);
  62. });
  63. };
  64.  
  65. loadAndExecute("//lib.sinaapp.com/js/jquery/2.0/jquery.min.js", function() {
  66. if ( !$("a[href='/signup']").length && !$("a[href='/signin']").length && document.body.innerHTML.indexOf(";<\/span> 创建新回复<\/div>") == -1 ) {
  67. var uid=$.find('a[href^="/member/"]')[0].innerHTML;//用户名
  68. var dateinfo=new Date().getUTCDate();//获得GMT时间今天几号
  69. var SigninInfo=uid + ":" + dateinfo + "";
  70. var daily = $('input[id="search"]');
  71. if (daily.length && localStorage.SigninInfo != SigninInfo ) {
  72. $.ajax({url:"/"});
  73. daily.val("正在检测每日签到状态...");
  74. $.ajax({
  75. url: "/mission/daily",
  76. success: function(data) {
  77. var awards = $(data).find('input[value^="领取"]');
  78. if (awards.length) {
  79. // daily.val("正在" + awards.attr("value") + "...");
  80. daily.val("正在领取今日的登录(不可用)奖励......");
  81. $.ajax({
  82. url: awards.attr('onclick').match(/(?=\/).+?(?=\')/),
  83. success: function(data) {
  84. daily.val("正在提交...");
  85. var days=data.split("已连续登")[1].split(" ")[1];
  86. if ( $('a[href="/mission/daily"]').length==1 ) {$('a[href="/mission/daily"]').parent().parent().fadeOut(3000);}
  87. $.ajax({
  88. url: "/balance",
  89. success: function(data) {
  90. function p(s) {return s < 10 ? '0' + s: s;} //自动补0
  91. var date2="" + new Date().getUTCFullYear() + p(new Date().getUTCMonth()+1) +p(new Date().getUTCDate());
  92. if (data.indexOf(date2+" 的每日登录(不可用)奖励")!="-1") {
  93. daily.val( "已连续领取" + days + "天,本次领到" + data.split("每日登录(不可用)")[2].split(" ")[1] + "铜币" );
  94. localStorage.SigninInfo = SigninInfo;
  95. } else {
  96. daily.val( "自动领取遇到意外,你可以试试手动领。" );
  97. }
  98. }
  99. });
  100. },
  101. error: function() {
  102. daily.val("网络异常 :(");
  103. }
  104. });
  105. }else{
  106. if (data.indexOf("已领取") != -1) {
  107. daily.val("今日奖励领取过了");
  108. localStorage.SigninInfo = SigninInfo;
  109. } else {
  110. daily.val("无法辩识领奖按钮 :(");
  111. }
  112.  
  113. }
  114. },
  115. error: function() {
  116. daily.val("请手动领取今日的登录(不可用)奖励!");
  117. }
  118. });
  119. } else {
  120. //console.log("");
  121. }
  122. }
  123. });
  124. })();
  125.  
  126. //标记楼主 代码来自ejin
  127. (function (){
  128. var uid=document.getElementById("Rightbar").getElementsByTagName("a")[0].href.split("/member/")[1];//自己用户名
  129. if (location.href.indexOf(".com/t/") != -1) {
  130. var lzname=document.getElementById("Main").getElementsByClassName("avatar")[0].parentNode.href.split("/member/")[1];
  131. var allname='@'+lzname+' ';
  132. var all_elem = document.getElementsByClassName("dark");
  133. for(var i=0; i<all_elem.length; i++) {
  134. if (all_elem[i].innerHTML == lzname){
  135. all_elem[i].innerHTML += " <font color=green>[楼主]</font>";
  136. }
  137. //为回复所有人做准备
  138. 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 ) {
  139. allname+='@'+ all_elem[i].innerHTML+' ';
  140. }
  141. }
  142. }
  143.  
  144. if ( document.getElementById("reply_content") ) {
  145. 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>";
  146. if ( document.body.style.WebkitBoxShadow !== undefined ) {
  147. //允许调整回复框高度
  148. document.getElementById("reply_content").style.resize="vertical";
  149. }
  150. document.getElementById("reply_content").style.overflow="auto";
  151. var magagers="@Livid @Kai @Olivia @GordianZ @sparanoid";
  152. 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>";
  153. }
  154. })();
  155.  
  156. // 图片链接自动转换成图片 代码来自caoyue@v2ex
  157. (function (){
  158. var links = document.links;
  159. for (var i=0;i<links.length;i++){
  160. var link = links[i];
  161. if (/^http.*\.(?:jpg|jpeg|jpe|bmp|png|gif)/i.test(link.href)
  162. && !/<img\s/i.test(link.innerHTML) && link.href.indexOf("v2ex.com/tag")==-1){
  163. link.innerHTML = "<img title='" + link.href + "' src='" + link.href + "' />";
  164. }
  165. }
  166. })();
  167. //
  168.  
  169. //新浪图床的图片反防盗链
  170. (function (){
  171. var images = document.images;
  172. for (var i=0;i<images.length;i++){
  173. var image = images[i];
  174. if ( image.src && image.src.indexOf(".sinaimg.cn")!=-1 &&image.src.indexOf(".sinaimg.cn")<13 ) {
  175. image.setAttribute("referrerPolicy","no-referrer");
  176. image.src=image.src + "?";
  177. }
  178. }
  179. })();
  180.  
  181. //V2EX帖子盖楼显示
  182. (function() {
  183.  
  184.  
  185. //楼层
  186. var a = $('div.cell > table > tbody > tr > td:nth-child(3) > div.fr > span').get().map(i=>i.innerHTML);
  187. //回复内容
  188. var b = $('div.cell > table > tbody > tr > td:nth-child(3) > div.reply_content').get().map(i=>i.innerHTML);
  189. var c = $('div.cell > table > tbody > tr > td:nth-child(3) > strong > a').get().map(i=>i.innerHTML);
  190.  
  191. var d = $('div.cell > table > tbody > tr > td:nth-child(3) > div.reply_content');
  192. var m = $('#Main > div:nth-child(4) > div[id].cell');
  193.  
  194. var e = $('div.cell > table > tbody > tr > td:nth-child(3) > strong > a');
  195. var x = $('#Main > div:nth-child(2) > div.header > small > a')[0].innerHTML;
  196. var loginUser = $('#Rightbar > div:nth-child(2) > div:nth-child(1) > table:nth-child(1) > tbody > tr > td:nth-child(3) > span > a')
  197. loginUser = loginUser.length ? loginUser[0].innerHTML :null ;
  198. let i = 1;
  199. while(i< m.length){
  200.  
  201. if( c[i] == x )
  202. {
  203. e[i].setAttribute('style','color:blue');
  204. }
  205. else if( c[i] == loginUser )
  206. {
  207. e[i].setAttribute('style','color:purple');
  208. }
  209. if(b[i].match("楼上")){
  210. d[i-1].append(m[i]);
  211. }
  212.  
  213. for(var j=i-1;j>=0;j--){
  214. if(b[i].match(c[j])){
  215. d[j].append(m[i]);
  216. break;
  217. }
  218. }
  219. i++;
  220. }
  221. })();

QingJ © 2025

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