V2EX增强插件

1.回复标记楼主ID 2.每天打开V2EX网站任意页面时自动领取签到的登陆奖励

目前為 2015-10-17 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name V2EX增强插件
  3. // @description 1.回复标记楼主ID 2.每天打开V2EX网站任意页面时自动领取签到的登陆奖励
  4. // @namespace yfmx746qpx8vhhmrgzt9s4cijmejj3tn
  5. // @icon http://ww1.sinaimg.cn/large/4ec98f50jw1e85azvlnh9j206y06y3ye.jpg
  6. // @author me
  7. // @include http*://*.v2ex.com/*
  8. // @include http*://v2ex.com/*
  9. // @version 2015.10.16
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. //2015.10.16 新增在回复中标记楼主
  14. //2015.03.22 尝试修正未知原因情况下导致的签到失败。
  15. //2015.02.07 解决JQuery库在某种情况可能会无法载入
  16. //2014.10.07 某种情况下会产生cookie重复赋值,增加清理补丁。
  17. //2014.10.06 cookie信息过期时间改为3天
  18.  
  19. //签到
  20. var load, execute, loadAndExecute;
  21. load = function(a, b, c) {
  22. var d;
  23. d = document.createElement("script"), d.setAttribute("src", a), b != null && d.addEventListener("load", b), c != null && d.addEventListener("error", c), document.body.appendChild(d);
  24. return d
  25. }, execute = function(a) {
  26. var b, c;
  27. typeof a == "function" ? b = "(" + a + ")();" : b = a, c = document.createElement("script"), c.textContent = b, document.body.appendChild(c);
  28. return c
  29. }, loadAndExecute = function(a, b) {
  30. return load(a, function() {
  31. return execute(b)
  32. })
  33. };
  34. loadAndExecute("//lib.sinaapp.com/js/jquery/2.0/jquery.min.js", function() {
  35. if ( document.getElementById("money") && document.getElementById("money").getElementsByTagName("a")[0].href.indexOf("/balance") != -1 && document.body.innerHTML.indexOf(";<\/span> 创建新回复<\/div>") == -1 ) {
  36. var uid=document.getElementById("Rightbar").getElementsByTagName("a")[0].href.split("/member/")[1];//用户名
  37. var dd = new Date(); dd.setDate(dd.getDate()+3);var dateexp = dd.toGMTString(); //cookie过期时间
  38. var dateinfo=new Date().getUTCDate();//获得GMT时间今天几号
  39. var cookiestr="IDINFO=:" + uid + ":" + dateinfo + ":";
  40. var daily = $('input[id="q"]');
  41. if ( document.cookie.split("IDINFO=").length>2 && location.href.split("/").length>4 ) document.cookie = "IDINFO" + "=;expires=" + new Date().toGMTString(); //清理非/的cookie
  42. if (daily.length && document.cookie.indexOf(cookiestr) == -1 ) {
  43. $.ajax({url:"/"})
  44. daily.val("正在检测每日签到状态...");
  45. $.ajax({
  46. url: "/mission/daily",
  47. success: function(data) {
  48. var awards = $(data).find('input[value^="领取"]');
  49. if (awards.length) {
  50. // daily.val("正在" + awards.attr("value") + "...");
  51. daily.val("正在领取今日的登录奖励......");
  52. $.ajax({
  53. url: awards.attr('onclick').match(/(?=\/).+?(?=\')/),
  54. success: function(data) {
  55. daily.val("正在提交...");
  56. var days=data.split("已连续登")[1].split(" ")[1];
  57. if ( $('a[href="/mission/daily"]').length==1 ) {$('a[href="/mission/daily"]').parent().parent().fadeOut(3000)}
  58. $.ajax({
  59. url: "/balance",
  60. success: function(data) {
  61. function p(s) {return s < 10 ? '0' + s: s;} //自动补0
  62. var date2="" + new Date().getUTCFullYear() + p(new Date().getUTCMonth()+1) +p(new Date().getUTCDate())
  63. if (data.indexOf(date2+" 的每日登录奖励")!="-1") {
  64. daily.val( "已连续领取" + days + "天,本次领到" + data.split("每日登录")[2].split(" ")[1] + "铜币" );
  65. document.cookie = cookiestr + ";expires=" + dateexp + ";path=/;";
  66. } else {
  67. daily.val( "自动领取遇到意外,你可以试试手动领。" );
  68. }
  69. }
  70. })
  71. },
  72. error: function() {
  73. daily.val("网络异常 :(");
  74. }
  75. });
  76. }else{
  77. if (data.indexOf("已领取") != -1) {
  78. daily.val("今日奖励领取过了");
  79. document.cookie = cookiestr + ";expires=" + dateexp + ";path=/;";
  80. } else {
  81. daily.val("无法辩识领奖按钮 :(");
  82. }
  83. }
  84. },
  85. error: function() {
  86. daily.val("请手动领取今日的登录奖励!");
  87. }
  88. });
  89. } else {
  90. //console.log("");
  91. }
  92. }
  93. });
  94.  
  95. //标记楼主
  96. if (location.href.indexOf(".com/t/") != -1) {
  97. var lzname=document.getElementById("Main").getElementsByClassName("avatar")[0].parentNode.href.split("/member/")[1]
  98. all_elem = document.getElementsByClassName("dark")
  99. for(var i=0; i<all_elem.length; i++) {
  100. if (all_elem[i].innerHTML == lzname){
  101. all_elem[i].innerHTML += " <font color=green>[楼主]</font>"
  102. }
  103. }
  104. }