复制Tower标题

复制 Tower 任务卡片上的标题到剪贴板

  1. // ==UserScript==
  2. // @name Tower Title Copy
  3. // @name:zh-CN 复制Tower标题
  4. // @namespace https://tower.im/
  5. // @version 0.3
  6. // @description Copy tower task title to clipboard!
  7. // @description:zh-cn 复制 Tower 任务卡片上的标题到剪贴板
  8. // @author Ruter
  9. // @match https://tower.im/projects/*
  10. // @require https://cdn.bootcss.com/clipboard.js/1.7.1/clipboard.min.js
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Toast style
  18. $("style").last().append("#toast{display:none;position:fixed;top:10%;left:50%;margin-top:-20px;margin-left:-75px;width:150px;height:40px;border-radius:10px;background:#353535;text-align:center;font-size:11px;line-height:40px;color:#fff;}");
  19. // Toast node
  20. $('<div/>', {id: 'toast', text: ''}).appendTo($("body"));
  21. // Add copy btn to each card
  22. $("div.todo-actions.actions > .inr").append($('<a/>', {
  23. 'class': 'copy',
  24. title: '复制',
  25. text: '复制',
  26. css: {'background-position': '6px -115px'}
  27. }));
  28. // Add clipboard.js event handler
  29. var clipboard = new Clipboard('a.copy', {
  30. text: function(trigger) {
  31. var node = trigger.parentNode.parentNode.nextElementSibling.getElementsByClassName("todo-rest")[0];
  32. return node.innerText.trim();
  33. }
  34. });
  35. clipboard.on('success', function(e){
  36. $("#toast").text("已复制到剪贴板");
  37. $("#toast").fadeIn().delay(1000).fadeOut();
  38. });
  39. clipboard.on('error', function(e){
  40. $("#toast").text("复制失败");
  41. $("#toast").fadeIn().delay(1000).fadeOut();
  42. });
  43. // Listen the DOM Node
  44. $("ul.todos.todos-uncompleted").bind('DOMNodeInserted', function(e) {
  45. var $todos = $(e.currentTarget).children("li.todo");
  46. $todos.each(function(){
  47. var $todo = $(this);
  48. var $inr = $todo.find("div.inr");
  49. var $a = $inr.children("a.copy");
  50. if (!$a.length) {
  51. $inr.append($('<a/>', {
  52. 'class': 'copy',
  53. title: '复制',
  54. text: '复制',
  55. css: {'background-position': '6px -115px'}
  56. }));
  57. }
  58. });
  59. });
  60. })();

QingJ © 2025

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