// ==UserScript==
// @name cpasbien
// @namespace cpasbien
// @include http://www.cpasbien.*/*
// @include http://www.t411.*/*
// @description enhance cpasbien / t411
// @version 1.2
// @grant none
// ==/UserScript==
$('.gauche').hide();
$('html > head').append($([
'<style>',
' .ligne0,.ligne1 {',
' width:378px; ',
'}',
'.titre {',
' width:240px;',
' background:transparent;',
' text-indent:0px;',
' padding:3px;',
' font-size:medium;',
'}',
'.dwnThumb {',
' float:left;',
' height:70px;',
'}',
'.dwnThumb img {',
' border:1px solid #9F9F9F;',
' -moz-border-radius:5px;',
' -webkit-border-radius:5px;',
' border-radius:5px;',
'}',
'.datas {',
' width:75px;',
' float:right;',
'}',
'.txtQuality {',
' color:orange;',
' font-size:10px;',
'}',
'.txtYear {',
' color:red;',
' font-size:10px;',
'}',
'.txtLanguage {',
' color:blue;',
' font-size:10px;',
'}',
'.txtSAEP {',
' color:brown;',
'}',
'.downloaded .poid{',
' text-decoration:line-through;',
'}',
'.downloaded img{',
' border:1px solid #9F9F9F;',
' -webkit-clip-path: polygon(52% 50%, 78% 11%, 86% 19%, 51% 71%, 28% 30%, 39% 24%);',
' clip-path: polygon(52% 50%, 78% 11%, 86% 19%, 51% 71%, 28% 30%, 39% 24%);',
'}',
'a.downloaded:active img{',
' -webkit-clip-path: polygon(100% 0, 100% 100%, 0 100%, 0 0);',
' clip-path: polygon(100% 0, 100% 100%, 0 100%, 0 0);',
'}',
'a.downloaded:hover img{',
' -webkit-clip-path: polygon(95% 5%, 95% 95%, 5% 95%, 5% 5%);',
' clip-path: polygon(95% 5%, 95% 95%, 5% 95%, 5% 5%);',
'}',
'</style>'].join("\n")+'</style>'));
var idx=0;
var addTag = function (text,tag,keywords){
for(var k in keywords){
text = text.replace(' '+keywords[k]+' ', function myFunction(x){
return ' <span class="'+tag+'">'+x+'</span> ';
});
}
return text;
};
$('table.results tr').each(function(k,tr){
var tds=$('td',tr);
if(tds && tds.length>0){
var atitles=$('a',tds[1]);
var anfos=$('a',tds[2]);
if(atitles && atitles.length>0){
var m = anfos[0].href.match(/torrents\/nfo\/\?id\=([0-9]*)/)
$(anfos[0]).replaceWith('<a href="/torrents/download/?id='+m[1]+'&file=.torrent">dwn</a>')
//console.log(atitles[0].href);
//console.log(m[1],atitles[0].innerHTML);
}
}
});
$('a.titre').each(function(k,v){
idx=++idx%4;
var that = $(v);
var poid = $('.poid',that.parent()).html();
var up = $('.up',that.parent()).html();
var down = $('.down',that.parent()).html();
var match = that.attr('href').match(/(.*)\/dl-torrent\/(.*)\/(.*)\.html/);
var torrent = match[1]+'/telechargement/'+match[3]+'.torrent';
var hash = 'dwn_'+match[3];
var inner = "";
var title = ' '+that.text()+' ';
title = addTag(title,'txtQuality',['DVDRIP','HDRIP','BRRIP','WEBRIP','x264','HDTV']);
title = addTag(title,'txtLanguage',['VOSTFR','FRENCH']);
title = addTag(title,'txtYear',(function(){var t=[];for(var i=1990;i<=2040;i++){t.push(''+i);}return t;})());
var saep = title.match(/S([0-9]+)E([0-9]+)/);
if(saep){
title = title.replace(saep[0],' <span class="txtSAEP">['+saep[1]+'x'+saep[2]+']</span> ');
}
var downloaded=(window.localStorage.getItem(hash)!=null);
title = title.replace(/ /g,' ');
inner = inner + '<div class="ligne'+(idx>=2?1:0)+'">';
inner = inner + ' <a class="dwnThumb torrentdwn '+(downloaded?'downloaded':'')+'" data-dhash="'+hash+'" href="'+torrent+'" alt="download torrent" title="download torrent"><img width="50 "src="/_pictures/'+match[3]+'.jpg"></a>';
inner = inner + ' <a class="titre" href="'+that.attr('href')+'">'+title+'</a>';
inner = inner + ' <div class="datas">';
inner = inner + ' <a class="torrentdwn '+(downloaded?'downloaded':'')+'" alt="download torrent" title="download torrent" data-dhash="'+hash+'" href="'+torrent+'">';
inner = inner + ' <div class="poid">'+poid+'</div>';
inner = inner + ' </a>';
inner = inner + ' <div class="up">'+up+'</div>';
inner = inner + ' <div class="down">'+down+'</div>';
inner = inner + ' </div>';
inner = inner + '</div>';
that.parent().replaceWith(inner);
});
$('a.torrentdwn').bind('click',function(v){
var hash = $(v.target).parent().attr('data-dhash');
$('[data-dhash='+hash+']').addClass('downloaded')
window.localStorage.setItem(hash,1);
//console.log($(v.target)[0]);
//console.log(hash);
return true;
});
$('.gauche').show();