facebook.com - Reply button

By Kub4jz Last update Oct 25, 2009 — Installed 4,237 times. Daily Installs: 5, 6, 42, 110, 55, 38, 33, 19, 12, 17, 14, 18, 11, 14, 16, 12, 16, 13, 8, 12, 13, 4, 10, 7, 6, 6, 10, 2, 6, 15, 10, 6

There are 21 previous versions of this script.

// ==UserScript==
// @name           facebook.com - Reply button
// @version        1.5
// @description    Add a reply button to comments
// @namespace      Kub4jz.cz
// @require        http://buzzy.hostoi.com/AutoUpdater.js

// @include        http://www.facebook.com/*home.php*
// @include        http://www.facebook.com/*profile.php*
// @include        http://www.facebook.com/*photo.php*
// @include        http://www.facebook.com/*note.php*
// @include        http://www.facebook.com/*posted.php*
// @include        http://www.facebook.com/*pages/*
// ==/UserScript==

var script_id = 49378;
var script_version = '1.5';

var gm_class = ' gm_reply_button';

var button_text = '';
var last_insert = '';

function getButtonText() {

	i = 0;
	while (!button_text && i < 15) {
		like_link = document.getElementsByClassName("comment_link").item(i);
		if (like_link != null) {

			link = like_link;
			button_text = link.innerHTML.toLowerCase();
			
			// comment -> reply
			button_text = button_text.replace('comment', 'Reply', 'i'); // EN
			button_text = button_text.replace('Přidat komentář', 'Reagovat', 'i'); // CZ
			
			return button_text;

		}
	i++;
	}
}

function insertName() {
	parent = this.parentNode.parentNode;
	
	textarea = parent.parentNode.parentNode.parentNode.parentNode.getElementsByTagName("textarea").item(0);

	link = parent.getElementsByClassName("comment_author").item(0);

	name = link.innerHTML;
	string = name;
	name = string.toString().split(' '.toString());
	first_name = name[0];
	
	insert_text = first_name + ': ';

	textarea.focus();
	
	var value = textarea.value;
	if (value == '') { last_insert = null; }
	
	if (insert_text !== last_insert) {
		textarea.value += insert_text;
		last_insert = insert_text;
	}
}

function addButtons() {

	if (button_text == '') { button_text = getButtonText(); }

	if (button_text == null) { return false; }

	var divs = document.getElementsByClassName("comment_actions");

	for(i = 0; i <= divs.length - 1; i++) {

		var div = divs.item(i);

		if (div.className.indexOf(gm_class) >= 0) {
			continue;
		}else{
			div.className += gm_class;
		}

		// create & add reply button
	  div.innerHTML += ' · ';

	  var button = document.createElement('a');
	  var txt = document.createTextNode(button_text);

	  button.insertBefore(txt, null);
	  div.insertBefore(button, null);
	  button.addEventListener("click", insertName, false);

	}
	setTimeout(addButtons, 1500);
   return false;
}

function starter() {
	addButtons();
}

window.addEventListener("load", starter, false);

autoUpdate (script_id, script_version);