[Erepublik] Extract BBCode of articles

Extracts BBCode of articles

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         [Erepublik] Extract BBCode of articles
// @match        *://www.erepublik.com/en/article/*
// @version      0.1
// @description  Extracts BBCode of articles
// @author       Mike Ontry
// @grant        none
// @namespace https://greasyfork.org/users/3941
// ==/UserScript==

var main = jQuery(document).find('div[class="post_content"]').get(0);

jQuery(main).find('h2').before('<a class="std_global_btn smallSize blueColor" style="float:right;" id="extractBB"><span>Extract BBCode</span></a>');

jQuery(document).find('a[id="extractBB"]').on("click", function() {
    var content = jQuery(main).find('div[class="full_content"]').html();
    jQuery(document).find('div[class="holder"]').after('<textarea id="bbCodeCont" rows="20" cols="115">'+ HtmltoBB(content) +'</textarea>');
    location.hash = "bbCodeCont";
});

function HtmltoBB(html) {

	html = html.replace(/<br\s*[\/]?>/gi, "\n\r");
	html = html.replace(/<b>/gi, "[b]");
	html = html.replace(/<i>/gi, "[i]");
	html = html.replace(/<u>/gi, "[u]");
	html = html.replace(/<\/b>/gi, "[/b]");
	html = html.replace(/<\/i>/gi, "[/i]");
	html = html.replace(/<\/u>/gi, "[/u]");
	html = html.replace(/<em>/gi, "[b]");
	html = html.replace(/<\/em>/gi, "[/b]");
	html = html.replace(/<strong>/gi, "[b]");
	html = html.replace(/<\/strong>/gi, "[/b]");
    html = html.replace(/<strike>/gi, "[s]");
	html = html.replace(/<\/strike>/gi, "[/s]");
    html = html.replace(/<sub>/gi, "[sub]");
	html = html.replace(/<\/sub>/gi, "[/sub]");
    html = html.replace(/<sup>/gi, "[sup]");
	html = html.replace(/<\/sup>/gi, "[/sup]");
    html = html.replace(/<hr>/gi, "-----");
    //html = html.replace(/<div(.*?)style="text-align:(.*?)"(.*?)>([\s\S]*?)<\/div>?=*$/gmi, "[$2]$4[/$2]");
	html = html.replace(/<div(.*?)style="(.*?)"(.*?)>/gi, "[center]");
	html = html.replace(/<\/div>/gi, "[/center]");

	html = html.replace(/<img(.*?)src="(.*?)"(.*?)>/gi, "[img]$2[/img]");
	html = html.replace(/<a(.*?)href="(.*?)"(.*?)>(.*?)<\/a>/gi, "[url=$2]$4[/url]");

	html = html.replace(/\/\//gi, "/");
	html = html.replace(/http:\//gi, "http://");

	html = html.replace(/<(?:[^>'"]*|(['"]).*?\1)*>/gmi, "");
	html = html.replace(/\r\r/gi, ""); 
	html = html.replace(/\[img]\//gi, "[img]");
	html = html.replace(/\[url=\//gi, "[url=");

	html = html.replace(/(\S)\n/gi, "$1 ");

	return html;
}