// ==UserScript==
// @name        JV NoPorn
// @namespace   JV NoPorn
// @description Efface le porno de la liste des sujets des forums de JVC.
// @include     http://www.jeuxvideo.com/forums/42-*
// @include     http://www.jeuxvideo.com/forums/0-*
// @version     1.2.1
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @updateURL   http://busterblad.free.fr/jv-noporn/JV%20NoPorn.meta.js
// @downloadURL http://busterblad.free.fr/jv-noporn/JV%20NoPorn.user.js
// @grant       GM_getValue
// @grant       GM_setValue
// @grant       GM_listValues
// @grant       GM_deleteValue
// @grant       GM_addStyle
// @icon        http://image.noelshack.com/fichiers/2017/07/1486987782-icon.png
// @author      Hit
// @noframes
// ==/UserScript==

GM_addStyle('.picto-msg-balance {background:url("http://image.noelshack.com/fichiers/2017/07/1486986675-button-balancer.png") 0 0 no-repeat;display:inline-block;width:16px;height:16px;}.picto-msg-balance span {position:absolute;top:0;left:-999em;}#jvnoporn-box-info {width:400px;height:50%;background-color:#fff;position:absolute;top:0;bottom:0;left:0;right:0;margin:auto;display:none;z-index:9999;padding:15px 10px;box-shadow:0px 0px 15px 0px #ccc;border-radius:7px;}#jvnoporn-close-box {position:absolute;top:0;right:5px;}#jvnoporn-overlay {z-index:9998;background-color:#000;opacity:0.5;position:fixed;top:0;right:0;width:100%;height:100%;display:none;}#list-tags {width:100%;}#jvnoporn-tags {display:none;}');
this.$ = this.jQuery = jQuery.noConflict(true);
$(document).ready(function(){
	var Options = [
		'filterentiretopic',
		'activebalancer'
	];
	// évite de casser le script à la première installation, vous pouvez virer cette partie la ensuite
	$.each(Options, function(index, val){
		if(typeof GM_getValue(val) === 'undefined') {
			GM_setValue(val, '');
		}
	});
	//
	var OptionsOverlay = '<li class="text-center">JV NoPorn</li>'
		+'<li><span class="pull-left">Filtrer les titres entièrement</span><input class="input-on-off" id="filterentiretopic" '+GM_getValue("filterentiretopic")+' type="checkbox"><label for="filterentiretopic" class="btn-on-off"></label></li>'
		+'<li><span class="pull-left">Activer la fonction balancer</span><input class="input-on-off" id="activebalancer" '+GM_getValue("activebalancer")+' type="checkbox"><label for="activebalancer" class="btn-on-off"></label></li>'
		+'<li><span class="pull-left"><a href="#" id="jvnoporn-show-tags">Personnaliser la liste des tags</a></span><label></label></li>'
		+'<li id="jvnoporn-tags"><input type="text" name="list-tags" id="list-tags" value="'+GM_getValue('taglist')+'" /><label for="list-tags"></label></li>'
		+'<li><span class="pull-left"><a href="#" id="jvnoporn-open-box">En savoir plus sur le script</a></span><label></label></li>';
	var DialogTags = '<div id="jvnoporn-box-info"><a href="#" id="jvnoporn-close-box" title="Fermer la fenêtre"><img src="http://i.imgur.com/pFVCnkU.png" alt="Fermer" /></a>'
	+'Pour personnaliser la liste des balises que vous souhaitez filtrer, il suffit de les entrer dans le champ de texte séparées par un espace (le script ne tient pas compte des mots contenant un espace).'
	+'</div>'
	+'<div id="jvnoporn-overlay"></div>';
	$('.menu-user-forum').append(OptionsOverlay);
	$('body').append(DialogTags);
	$("#list-tags").on('focusout',function(){
		GM_setValue('taglist', $(this).val());
	});
	$.each(Options, function(index, val){
		var OptionName = val;
		$('#'+val).on('click', function(){
			if($(this).is(':checked')) GM_setValue(OptionName, 'checked');
			else GM_setValue(OptionName, '');
		});
	});
	$('#jvnoporn-show-tags').on('click',function(e){
		e.preventDefault();
		if($('#jvnoporn-tags').css('display') == 'none') $('#jvnoporn-tags').css('display', 'block');
		else $('#jvnoporn-tags').css('display', 'none');
		return false;
	});
	$('#jvnoporn-open-box').on('click',function(e){
		e.preventDefault();
		$('#jvnoporn-box-info').css('display', 'block');
		$('#jvnoporn-overlay').css('display', 'block');
		return false;
	});
	$('#jvnoporn-close-box').on('click',function(e){
		e.preventDefault();
		$('#jvnoporn-box-info').css('display', 'none');
		$('#jvnoporn-overlay').css('display', 'none');
		return false;
	});
	var tags = ["porn","boobs","cul","milf","beurette","seins","shemale","escort","pute","bbw","blacked"];
	if(typeof GM_getValue('taglist') != 'undefined') {
		if(GM_getValue('taglist').length>0) {
			var Taglist = GM_getValue('taglist').trim();
			var Taglist = Taglist.split(' ');
			$(Taglist).each(function(index,val){
				tags.push(val);
			});
		}
	}
	if(tags.length>0) {
		if(GM_getValue("filterentiretopic")=='checked') {
			$('.topic-list li').each(function(index){
				var Topic = $(this);
				var Title = $(this).children('.topic-subject').children('a').text();
				var Title = Title.toLowerCase();
				$.each(tags, function(i, val){
					if(Title.match(val)) {
						Topic.css('display', 'none');
					}
				});
			});
		}
		else {
			$('.topic-list li').each(function(index){
				var Title = $(this).children('.topic-subject').children('a').text();
				
				if(Title.match(/^\[/)) {
					var Regex = Title.match(/^\[(.*)\]/);
					var Balise = Regex[1];
					var Balise = Balise.toLowerCase();
					
					if(tags.includes(Balise)) {
						$(this).css('display', 'none');
					}
				}
			});
		}
	}
	if(GM_getValue("activebalancer")=='checked') {
		TopicMod = 'http://www.jeuxvideo.com/forums/42-51-45947465-1-0-1-0-mode-36-kheys-des-orfevres.htm#bloc-formulaire-forum';
		$('.picto-msg-quote').before('<span class="picto-msg-balance" title="Balancer ce post"><span>Balancer</span></span>');
		$('.picto-msg-balance').on('click',function(){
			var Url = $(this).parent('.bloc-options-msg').next('.bloc-date-msg').children('a').attr('href');
			GM_setValue('postabalancer', Url);
			window.location.href = TopicMod;
		});
		if(window.location.href === TopicMod && typeof GM_getValue('postabalancer') != 'undefined') {
			$('#message_topic').val('http://www.jeuxvideo.com'+GM_getValue('postabalancer'));
			GM_deleteValue('postabalancer');
		}
	}
});