一个草率的V2EX右边栏签到UI

网站右侧显示签到UI, 无需跳转签到页签到

  1. // ==UserScript==
  2. // @name 一个草率的V2EX右边栏签到UI
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1.1
  5. // @description 网站右侧显示签到UI, 无需跳转签到页签到
  6. // @author echo
  7. // @match *://*.v2ex.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=v2ex.com
  9. // @grant none
  10. // @license Apache License 2.0
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15. var $ = window.jQuery;
  16. $(function () {
  17. let xhr, div;
  18. xhr = new XMLHttpRequest();
  19. xhr.onload = function (e) {
  20. let cnt = new RegExp("<body>.*<\/body>", "is").exec(xhr.response);
  21. div = $('<div></div>');
  22. div.html(cnt);
  23. let signin = div.find('.site-nav .tools a[href="/signin"]');
  24. if (!signin.length == 0) return;
  25. if (window.location.pathname == '/mission/daily') return;
  26. let position = $('#Rightbar .box:eq(0) .cell:eq(2)');
  27. if (position.length == 0) return;
  28. let code = "";
  29. let url = "";
  30. let before = { txt: '签&ensp;&ensp;&ensp;到', c1: '#9EEB80', c2: '#90CC78' };
  31. let after = { txt: '今日已签到', c1: '#EBA380', c2: '#EBA380' };
  32. let bar = $(`<div class="cell" style="">
  33. <div cellpadding="0" cellspacing="0" border="0" width="100%" style="text-shadow:0.5px 0.5px 2px #fff;background-color:#ffffffff;padding: 4px;text-align: center;"><a href="#" style="
  34. color:#666;font-weight:bold;display: block;width: 100%;height: 100%;text-decoration: none;
  35. user-select:none"></a></div></div>`);
  36. let aFather = bar.children();
  37. let a = aFather.children();
  38. position.after(bar);
  39. xhr = new XMLHttpRequest();
  40. xhr.onload = function (e) {
  41. let cnt = new RegExp("<body>.*<\/body>", "is").exec(xhr.response);
  42. div.html(cnt);
  43. let btn = div.find('#Main input');
  44. if (btn.length == 0 || btn.val() == "查看我的账户余额") { refresh(after); stopA(); return; } else { refresh(before); }
  45. let txt = btn.attr('onclick');
  46. code = new RegExp("(?<=once=)\\d{5}").exec(txt)[0];
  47. url = `/mission/daily/redeem?once=${code}`;
  48. a.one('click', function (e) { $.get(url, function (rs) { refresh(after) }); setTimeout(() => { stopA(); }, 10); });
  49. }
  50. xhr.open('get', '/mission/daily');
  51. xhr.send();
  52. //刷新按钮状态
  53. function refresh(stat) {
  54. a.html(stat.txt);
  55. log(stat.txt);
  56. aFather.css('backgroundColor', stat.c1);
  57. aFather.hover(function () { $(this).css('backgroundColor', stat.c2) }, function () { $(this).css('backgroundColor', stat.c1) });
  58. }
  59. //禁用签到链接
  60. function stopA() {
  61. a.attr('href', '/mission/daily');
  62. }
  63. }
  64. xhr.open('get', window.location.origin);
  65. xhr.send();
  66. //日志
  67. function log(message, type) {
  68. const tag = "%cV2EX 签到%c ";
  69. const style = "background: #44605C; color: white; padding: 3px 3px 2px 3px; border-radius: 3px;font-size:11px;font-weight:bold;"
  70. if (type == 'error') console.error(tag + message, style, 'font-size:11px;');
  71. else console.log('' + tag + message, style, 'font-size:11px;');
  72. }
  73. });
  74. })();

QingJ © 2025

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