tower

方便的把任务指给参与讨论的某个人

  1. // ==UserScript==
  2. // @name tower
  3. // @namespace sbw@sbw.so
  4. // @description 方便的把任务指给参与讨论的某个人
  5. // @include https://tower.im/*
  6. // @version 1.1
  7. // @grant unsafeWindow
  8. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js
  9. // ==/UserScript==
  10.  
  11. // var $ = unsafeWindow.$;
  12. var members = unsafeWindow.members = {};
  13. var assignee = unsafeWindow.assignee = "";
  14.  
  15. (function() {
  16. function contains(name)
  17. {
  18. return members[name] !== undefined;
  19. }
  20. function listUsers()
  21. {
  22. $("a[class='author']").each(function() {
  23. var name = $(this).html();
  24. if (!contains(name)) {
  25. var url = $(this).attr("href");
  26. var uid = url.match(/members\/(\w+)/)[1];
  27. members[name] = uid;
  28. }
  29. });
  30. for (v in members) {
  31. console.log(v);
  32. if (v !== assignee)
  33. createButton(v, members[v]);
  34. }
  35. }
  36. function createButton(name, uid)
  37. {
  38. var button = document.createElement("button");
  39. button.innerText = name;
  40. button.onclick = assignUser;
  41. $(button).attr("uid", uid);
  42. $(button).css({
  43. "padding" : "0 10px",
  44. "margin" : "0 5px 0 5px",
  45. "color" : "#666",
  46. "background-color" : "#eee",
  47. "border" : "none",
  48. "border-radius" : "20px",
  49. "height" : "20px",
  50. "line-height" : "1.6",
  51. "vertical-align" : "baseline",
  52. "cursor" : "pointer",
  53. "font-size" : "100%"
  54. });
  55. $(".todo-wrap").append(button);
  56. }
  57. function csrfToken()
  58. {
  59. return $("meta[name='csrf-token']").attr("content");
  60. }
  61. function connGuid()
  62. {
  63. return $("input[id='conn-guid']").val();
  64. }
  65. function test()
  66. {
  67. console.log("aaa", connGuid());
  68. }
  69. function assignUser()
  70. {
  71. var uid = $(this).attr("uid");
  72. $.ajax({
  73. url : location.href + "edit",
  74. type : "post",
  75. headers : {
  76. "X-Requested-With" : "XMLHttpRequest",
  77. "X-CSRF-Token" : csrfToken()
  78. },
  79. data :
  80. {
  81. "conn_guid" : connGuid(),
  82. "assignee_guid" : uid
  83. },
  84. dataType : "json",
  85. success : function(data) {
  86. // console.log(data);
  87. location.reload();
  88. }
  89. });
  90. }
  91. function findAssignee()
  92. {
  93. assignee = $.trim($(".assignee").html());
  94. }
  95. function init()
  96. {
  97. var button = document.createElement("button");
  98. button.innerText = "✓";
  99. button.onclick = test;
  100. $(button).css({
  101. "height" : "30px",
  102. "color" : "black",
  103. "padding" : "0"
  104. });
  105. $(".todo-wrap").append(button);
  106. }
  107. // document.addEventListener('hashchange', function() {
  108. // }, false);
  109. // unsafeWindow.history.pushState = function() {
  110. // alert(/x/);
  111. // }
  112. // unsafeWindow.$(document).on("pjax:end", exportFunction(function() {
  113. // console.log('test @grant GM_* 1');
  114. // }, unsafeWindow));
  115. // unsafeWindow.$(window).on('pushstate', function() {
  116. // console.log('test @grant none 2');
  117. // });
  118. // (function (old) {
  119. // unsafeWindow.history.pushState = function () {
  120. // old.apply(unsafeWindow.history, arguments);
  121. // alert(unsafeWindow.location.href);
  122. // }
  123. // })(unsafeWindow.history.pushState);
  124. // function hackPushState(a, b, c) {
  125. // alert(a + b + c);
  126. // alert(unsafeWindow.history.pushStateHacked);
  127. // unsafeWindow.history.pushStateHacked(a, b, c);
  128. // }
  129. // unsafeWindow.history.pushStateHacked = unsafeWindow.history.pushState;
  130. // unsafeWindow.history.pushState = exportFunction(hackPushState, unsafeWindow);
  131. // waitForKeyElements('div#page-todo', function() {alert(/cc/);});
  132. // document.addEventListener('DOMContentLoaded', function() {
  133. // init();
  134. $(document).on('DOMNodeInserted', function(e) {
  135. // alert($(e.target).hasClass('assignee'));
  136. // console.log(e.toSource());
  137. if (!$(".todo-wrap > button").length)
  138. {
  139. //alert(/x/);
  140. members = {};
  141. findAssignee();
  142. listUsers();
  143. }
  144. });
  145. // unsafeWindow.onpopstate = function(e) {
  146. // alert(e.state);
  147. // alert(location.href);
  148. // }
  149. // $(unsafeWindow).on('popstate', function() {
  150. // console.log(document.href);
  151. // alert(/x/);
  152. // });
  153. // alert(/a/);
  154. // }, false);
  155. // alert(location.href);
  156. })();

QingJ © 2025

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