nwolf / Wall Post Links

// ==UserScript==
// @name        Wall Post Links
// @namespace   http://www.erepublik.com
// @description	Adds a link to each wall post on eRepublik
// @include     http://www.erepublik.com/*
// @exclude     http://www.erepublik.com/*/*
// @version     0.0.6
// @grant		none
// @require		https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
// @updateURL	https://openuserjs.org/install/nwolf/Wall_Post_Links.user.js
// @downloadURL	https://openuserjs.org/install/nwolf/Wall_Post_Links.user.js
// ==/UserScript==

start();

function start() {
	if($('.wall_post') === null) {
		return;
	}
	scan();
	observeNewComments();	
}

function observeNewComments() {
	var target = document.querySelector('#wall_master');
	var observer = new MutationObserver(function(mutations) {
			scan();
		});
	var config = { childList: true, subtree: true };
	observer.observe(target, config);
}

function scan() {
	var postType = $('#show_friends_feed').hasClass('active') ? 'viewPost=' 
					: $('#show_regiment_feed').hasClass('active') ? 'unitPost=' 
					: 'viewPartyPost=';
    $('.wall_post').each(function(index){
        if(!$(this).attr('hasLink') && !$(this).hasClass('mu')) {
			var id = $(this).attr('id').replace('post_', '');
			$(this).find('.post_actions')
				.append(' <span>ยท</span> ')
				.append('<a href="http://www.erepublik.com/en?' + postType + id + '">Link</a>');
            $(this).attr('hasLink', true);
        }
    });
}