RTM copy tasks

Copy current list of tasks

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name        RTM copy tasks
// @namespace   cahrehn.com
// @description Copy current list of tasks
// @include     https://www.rememberthemilk.com/*
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
// @require     http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js
// @grant       GM_addStyle
// @version 0.0.1.20140916215446
// ==/UserScript==

// selection solution from: http://stackoverflow.com/a/987376/1090474
jQuery.fn.selectText = function(){
    var doc = document
        , element = this[0]
        , range
        , selection
    ;
    if (doc.body.createTextRange) {
        range = document.body.createTextRange();
        range.moveToElementText(element);
        range.select();
    } else if (window.getSelection) {
        selection = window.getSelection();
        range = document.createRange();
        range.selectNodeContents(element);
        selection.removeAllRanges();
        selection.addRange(range);
    }
};

jQuery("head").append (
  '<link '
  + 'href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/flick/jquery-ui.css" '
  + 'rel="stylesheet" type="text/css">'
);

GM_addStyle("#copy { position: absolute; right: -11px; top: -41px; height: 26px; width: 28px; }");
GM_addStyle("#copy_dialog { text-align: left; }");

jQuery('<div/>', {
    id: 'copy_dialog'
}).dialog({
    appendTo: 'body',
    autoOpen: false,
    minWidth: 400,
    maxWidth: 650
}).bind('copy', function() {
    // ensure that copy to clipboard happens first
    setTimeout(function() {
        jQuery('#copy_dialog').dialog("close");
    }, 100);
});

// force close-on-escape behavior which seems to be broken by focus stealing
jQuery(document).keyup(function(e) {
  if (e.keyCode == 27) { jQuery('#copy_dialog').dialog('close'); } // esc
});

jQuery('<button/>', {
    id: 'copy'
}).button({
    icons: { primary: 'ui-icon-extlink' }
}).click(function() {
    var content = "";
    jQuery('#tasks span.xtd_task_name').each(function() {
        content = content + jQuery(this).html() + "<br>";
    });
    jQuery('#copy_dialog').html(content).dialog("open");
    // steal focus back from "Add a new task" input
    setTimeout(function() {
        document.activeElement.blur();
        jQuery('#copy_dialog').selectText();
    }, 50);
}).insertAfter('#add-helpicon');