SimpleQuotes

Provides ability for original 'oldschool' quotation

Stan na 08-12-2014. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        SimpleQuotes
// @namespace   forum.pravda.com.ua
// @description Provides ability for original 'oldschool' quotation
// @include     http://forum.pravda.com.ua/index.php?topic=*
// @version     1.08
// @grant       none
// ==/UserScript==
function replaceQuotes() {
  var textarea = document.getElementById('body');
  var links = document
    .getElementById('phorum')
    .getElementsByTagName('a');

  for (var i = 0; i < links.length; i++) {
    var target = links[i];
    var onClick = target.getAttribute('onclick');

    if (onClick && onClick.indexOf('doQuote') == 0) {
      var quoteLink = target;

      while (target && target.className != 'message') {
        target = target.parentNode;
      }

      if (target) {
        quoteLink.href = '#quickreply';
        quoteLink.onclick = function (message, editor) {
          return function () {
            quoteMessage(message, editor);
            return true;
          }
        }(target, textarea);
      }
    }
  }
}

function quoteMessage(message, editor) {
  var who = '';
  var what = '';
  var nodes = message.getElementsByTagName('div');
  for (var i = 0; i < nodes.length; i++) {
    if (nodes[i].className == 'message-author icon-user') {
      who = nodes[i].firstElementChild.innerHTML;
    }
    else if (nodes[i].className == 'msg') {
      var body = nodes[i].cloneNode(true);
      var node = body.firstChild;
      while (node) {
        var next = node.nextSibling;
        if (node.nodeType == 1) {
          if (node.className == 'quoteheader'
            || node.className == 'bbc_standard_quote'
            || node.className == 'quotefooter'
            || node.className == 'signature') {
            body.removeChild(node);
          }
        }
        node = next;
      }
      what = body.innerHTML;
    }
  }

  editor.value = who + ' Написав:\n-------------------------------------------------------\n' + quoteHtml(what) + '\n';
  setTimeout(function (editor) {
    return function () {
      editor.focus();
    }
  }(editor), 200);
}

function quoteHtml(htmlText) {
  var limit = 115;
  var text = '> ' + htmlText.trim()
    .replace(/&gt;/g, '>')
    .replace(/\s{2,}/g, ' ')
    .replace(/\r?\n|\r/g, '')
    .replace(/<br\s*[\/]?>\s*/gi, '\n> ')
    .replace(/(<([^>]+)>)/ig, '')
    .replace(/&nbsp;/ig, String.fromCharCode(160));

  var lines = text.split(/\r\n|\n|\r/);
  if (lines.length > 0 && lines[0] == '> ') {
    lines.splice(0, 1);
  }

  for (i = 0; i < lines.length; i++) {
    var j;
    var line = lines[i];
    lines[i] = '';
    while (line.length > limit) {
      j = (j = line.slice(0, limit + 1)
        .match(/\S*(\s)?$/))[1] ? limit : j.input.length - j[0].length || limit || j.input.length + (j = line.slice(limit)
        .match(/^\S*/))[0].length;
      lines[i] += line.slice(0, j) + ((line = line.slice(j)).length ? '\n> ' : '');
    }
    lines[i] += line;
  }
  return lines.join('\n');
}

replaceQuotes();