goodreadsReply

Quote only the selected text on a Goodreads comment reply; allow user to use Markdown

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         goodreadsReply
// @namespace    http://pointerstop.ca/
// @version      0.6.3
// @description  Quote only the selected text on a Goodreads comment reply; allow user to use Markdown
// @author       [email protected]
// @match        https://www.goodreads.com/topic/*
// @match        https://www.goodreads.com/review/show/*
// @grant        none
// @require      https://cdnjs.cloudflare.com/ajax/libs/showdown/1.6.4/showdown.min.js
// ==/UserScript==
function makeHTML(comment){
    var options   = {simplifiedAutoLink: true,
                     excludeTrailingPunctuationFromURLs: true,
                     literalMidWordUnderscores: true,
                     strikethrough: true
                    };
    var converter = new showdown.Converter(options),
        text      = comment.val(),
        html      = converter.makeHtml(text).replace(/<p>/g, '\n').replace(/<\/p>/g, '');
    comment.val(html);
}
jQuery(function($) {
    'use strict';
    var preview = $("input:submit + span + a");
    var commentText = $('textarea');
    var clickHandler = preview.prop("onclick");
    preview.prop("onclick",null);
    $("input:submit").on('click', function(){
        makeHTML(commentText);
    });
    preview.on('click', function(){
        makeHTML(commentText);
        clickHandler();
    });
    $("#box #close").on('click',function(){ commentText.focus(); });
    // turn off all the old click handlers
    $("a[href='#comment_form']").prop("onclick", null);

    // attach the new click handlers
    $("a[href='#comment_form']").on('click', function (e) {
        // disable the default handler
        e.preventDefault();
        // find the parent comment, the author's name, and the comment text
        var comment = $(e.target).parents("div.comment");
        var author = comment.find("span.commentAuthor a").text();
        var text = comment.find("div.reviewText");
        // use the selected text, if it exists, else the first 200 characters of the comment
        var selection = "";
        try {
            // if we're selecting a text node... get the selection
            if (window.getSelection().anchorNode.parentElement==text[0]){
                selection = window.getSelection().toString();
            }
        } catch(e) { // we don't care about errors
        }
        // if nothing has been selected, use GoodRead's normal default of the first 200 chars
        if (!selection) {
            selection = text.text().trim();
            if (selection.length > 200) {
                selection = selection.substring(0, 200) + '...';
            }
        }
        var quoteText = '<i>' + author + ' wrote: "' + selection + '"</i>\n\n';

        // use 'text()' to get the value, but 'val()' to set it, because carriage
        // returns are stripped by val()
        commentText.val(commentText.val() + quoteText);
        commentText.focus();
    });
});