SimpleQuotes

Provides ability for original 'oldschool' quotation

08.12.2014 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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.17
// @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 = 120;
  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();