RTM copy tasks

Copy current list of tasks

  1. // ==UserScript==
  2. // @name RTM copy tasks
  3. // @namespace cahrehn.com
  4. // @description Copy current list of tasks
  5. // @include https://www.rememberthemilk.com/*
  6. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
  7. // @require http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js
  8. // @grant GM_addStyle
  9. // @version 0.0.1.20140916215446
  10. // ==/UserScript==
  11.  
  12. // selection solution from: http://stackoverflow.com/a/987376/1090474
  13. jQuery.fn.selectText = function(){
  14. var doc = document
  15. , element = this[0]
  16. , range
  17. , selection
  18. ;
  19. if (doc.body.createTextRange) {
  20. range = document.body.createTextRange();
  21. range.moveToElementText(element);
  22. range.select();
  23. } else if (window.getSelection) {
  24. selection = window.getSelection();
  25. range = document.createRange();
  26. range.selectNodeContents(element);
  27. selection.removeAllRanges();
  28. selection.addRange(range);
  29. }
  30. };
  31.  
  32. jQuery("head").append (
  33. '<link '
  34. + 'href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/flick/jquery-ui.css" '
  35. + 'rel="stylesheet" type="text/css">'
  36. );
  37.  
  38. GM_addStyle("#copy { position: absolute; right: -11px; top: -41px; height: 26px; width: 28px; }");
  39. GM_addStyle("#copy_dialog { text-align: left; }");
  40.  
  41. jQuery('<div/>', {
  42. id: 'copy_dialog'
  43. }).dialog({
  44. appendTo: 'body',
  45. autoOpen: false,
  46. minWidth: 400,
  47. maxWidth: 650
  48. }).bind('copy', function() {
  49. // ensure that copy to clipboard happens first
  50. setTimeout(function() {
  51. jQuery('#copy_dialog').dialog("close");
  52. }, 100);
  53. });
  54.  
  55. // force close-on-escape behavior which seems to be broken by focus stealing
  56. jQuery(document).keyup(function(e) {
  57. if (e.keyCode == 27) { jQuery('#copy_dialog').dialog('close'); } // esc
  58. });
  59.  
  60. jQuery('<button/>', {
  61. id: 'copy'
  62. }).button({
  63. icons: { primary: 'ui-icon-extlink' }
  64. }).click(function() {
  65. var content = "";
  66. jQuery('#tasks span.xtd_task_name').each(function() {
  67. content = content + jQuery(this).html() + "<br>";
  68. });
  69. jQuery('#copy_dialog').html(content).dialog("open");
  70. // steal focus back from "Add a new task" input
  71. setTimeout(function() {
  72. document.activeElement.blur();
  73. jQuery('#copy_dialog').selectText();
  74. }, 50);
  75. }).insertAfter('#add-helpicon');