V2EX Pro+

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

当前为 2022-12-15 提交的版本,查看 最新版本

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

QingJ © 2025

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