// ==UserScript== // @name TurboForum // @namespace JV Flux // @description Naviguez plus rapidement sur les forums de jeuxvideo.com // @version 1.4 // @include http://www.jeuxvideo.com/* // @include http://*.forumjv.com/* // @include http://jvflux.com/turboforum/* // ==/UserScript== function geid(id) { return document.getElementById(id) } if (location.href.indexOf('http://www.jeuxvideo.com/forums/') == 0) { var TurboForum = function() { "use strict" function geid(id) { return document.getElementById(id) } function getag(tag) { return document.getElementsByTagName(tag) } function geclass(className) { return document.getElementsByClassName(className) } var turboforum_version = '1.4' function mode_from_url(url) { if (url.indexOf('http://www.jeuxvideo.com/forums/') != 0) { return -1 } return parseInt(url.substr('http://www.jeuxvideo.com/forums/'.length)) } function no_hash(url) { if (url.indexOf('#') == -1) { return url } return url.substr(0, url.indexOf('#')) } function remove_element(elem) { if (typeof elem == 'string') { elem = geid(elem) } if (elem) { elem.parentNode.removeChild(elem) } } function storage(item, data) { if (data == undefined) { return localStorage['turboforum_' + item] } localStorage['turboforum_' + item] = data } var col1 = geid('col1'), current_pathname, yscroll = 0, // 211 pour sauter le header t_count = 0, update_img, update_img_src = 'http://jvflux.com/turboforum/version.gif', p_id = 0, opacity = '.85', p_history = {html: {}, title: {}}, jvchat_on = -2, blacklist = [] var p = [{}, {}] for (var i = 0; i < 2; i++) { p[i].xhr = new XMLHttpRequest() p[i].xhr.id = i p[i].xhr.addEventListener('readystatechange', readystatechange) p[i].url = false p[i].url_alias = false p[i].html = false p[i].title = false p[i].state = '' p[i].timing_start = false p[i].timing = false } function readystatechange(e) { var id = e.target.id if (p[id].xhr.readyState < 4) { return } /* Arrive quand une requête est complétée */ if (p[id].xhr.status != 200) { if (p[id].xhr.status != 404) { window.console && console.log('p[' + id + '].xhr.status ≠ 200 (' + p[id].xhr.status + ') ' + p[id].url) } if (p[id].xhr.status == 0) { /* Arrive aléatoirement, quand ça arrive l’inspecteur réseau de Chrome ne montre pas de requête */ /* Quand ça arrive, les requêtes futures vers cette page donneront la même erreur */ /* Sauf si on crée une image avec comme src l’url du lien, les requêtes futures marchent (sous Chrome du moins) */ new Image().src = p[id].url } } p[id].timing = new Date().getTime() - p[id].timing_start p[id].html = p[id].xhr.responseText.substring(p[id].xhr.responseText.indexOf('
'), p[id].html.indexOf('http://image.jeuxvideo.com/pics/forums/bt_forum_rafraichir.gif')).split('"')[3] } p_history.html[no_hash(p[id].url_alias)] = p[id].html p_history.title[no_hash(p[id].url_alias)] = p[id].title } function preload(url) { /* Arrive quand on passe la souris sur un lien en liste blanche Ou après que p[p_id].state == 'displayed' dans display (quand on clique une deuxième fois sur un forum préféré) */ var id = p_id if (p[p_id].state == 'waiting') { /* Arrive quand on survole un lien alors qu’un autre (ou le même) est déjà en train de charger */ id ^= 1 } p[id].state = 'preloading' p[id].url = url p[id].url_alias = url p[id].html = false p[id].timing_start = new Date().getTime() p[id].timing = false p[id].xhr.open('GET', url, true) p[id].xhr.send() } function display(url, t) { /* Arrive quand on clique sur un lien en liste blanche Ou 50ms après que !p[p_id].html Ou 50ms après que p[p_id].state == 'displayed' */ if (p[p_id].state == 'preloading') { /* Première fois */ if (t < 1000) { /* On ne vient pas d’hover un autre lien */ t += 1000 } } else { /* On est plus en preloading, il y a eu au moins un setTimeout depuis */ if (p[p_id].state == 'waiting' && t < 1000) { /* Il n’y a pas eu de preloading préalable, ça arrive quand on clique sur le même lien avant que celui-ci ai été displayed, p[p_id].state est directement en waiting et cette instance de display tourne en parralèle de la première */ /* Ou alors on a cliqué sur un autre lien pendant qu’on en charge un */ if (p[p_id].url != url && p[p_id ^ 1].url == url) { p_id ^= 1 setTimeout("display('" + url + "', " + t + ")", 50) } return } } if (p[p_id].url != url) { /* Arrive quand on a swappé p_id, `url` est l’url précédente */ return } if (!p[p_id].html) { /* La réponse du serveur n’a pas encore était reçu, ou il y a eu un problème avec la requête */ p[p_id].state = 'waiting' if (!col1.style.opacity) { col1.style.opacity = opacity } setTimeout("display('" + url + "', " + t + ")", 50) return } if (p[p_id].state == 'displayed') { /* Ça arrive quand on clique à la suite sur les forums préférés */ if (!col1.style.opacity) { col1.style.opacity = opacity } preload(url) // display(url) setTimeout("display('" + url + "', " + t + ")", 50) return } p[p_id].state = 'displayed' col1.style.opacity = '' col1.innerHTML = p[p_id].html document.title = p[p_id].title Utilisateur() // fonction de JVC pour mettre à jour les MP if (p[p_id].url == no_hash(location.href)) { /* Bouton rafraîchir, on rajoute de l’opacité un court moment pour montrer que le rafraîchissement a bien eu lieu. */ col1.style.opacity = opacity setTimeout('col1.style.opacity = ""', 50) } if (p[p_id].url != location.href) { if (no_hash(p[p_id].url) != no_hash(location.href)) { if (p[p_id].url.indexOf('#') == -1) { scrollTo(0, yscroll) } else { var elem = p[p_id].url.substr(p[p_id].url.indexOf('#') + 1) if (geid(elem) || document.getElementsByName(elem).length > 0) { elem = geid(elem) || document.getElementsByName(elem)[0] var offset = 0 for (; elem.offsetParent; elem = elem.offsetParent) { offset += elem.offsetTop } scrollTo(0, offset) } else { scrollTo(0, yscroll) } } } history.pushState(null, null, p[p_id].url_alias) } current_pathname = location.pathname speed_up_all() // À faire après history.pushState pour faire des conditions sur location.href dans speed_up_all } function speed_up_all(forums_prefs) { var links = getag('a'), a, mode for (var i = 0; i < links.length; i++) { a = links[i] if (a.href.indexOf('http://www.jeuxvideo.com/forums/') != 0) { /* On ne précharge pas en dehors des forums */ continue } if (a.className == 'citer') { a.addEventListener('click', function(e) { store_quote(e.target.getAttribute('message')) }) } if (a.className == 'add_blacklist') { a.addEventListener('click', blacklist_add_from_button) } mode = mode_from_url(a.href) if ([0, 1, 3, 26].indexOf(mode) == -1) { /* On précharge seulement liste des sujets, page d’un topic, formulaire de réponse, retour liste des sujets */ continue } if (a.target) { continue } if (a.className == 'sup_pref') { /* Bouton pour supprimer un forum préféré */ continue } if (a.parentNode.id && a.parentNode.id.indexOf('coeur_suppr_') == 0) { /* Forums préférés */ if (!forums_prefs) { continue } } if (no_hash(a.href) == no_hash(location.href)) { if (a.href.indexOf('#') != -1) { /* Liens magiques (uploader noelshack, forum 1280px, etc.) et permanents */ continue } /* Boutons Rafraîchir */ } /* Le reste */ speed_up(a) } /* Lien permanent en surbrillance */ if (location.hash.indexOf('#message_') != -1) { if (geclass('msg_ancre').length) { geclass('msg_ancre')[0].classList.remove('msg_ancre') } geid(location.hash.substr(1)).classList.add('msg_ancre') } /* Autofocus sur le champ de réponse + affichage citation */ if (location.hash == '#form_post') { mode = mode_from_url(location.href) if (mode == 3) { geid('newmessage').focus() } else if (mode == 0) { geid('newsujet').focus() } if (storage('quote')) { geid('newmessage').value = storage('quote') storage('quote', '') } } /* Bouton pour ajouter forum aux favoris */ if (geid('coeur_ajouter')) { geid('coeur_ajouter').addEventListener('click', function(e) { e.preventDefault() coeur_ajouter() // Fonction de JVC }) } } function speed_up(e) { e.addEventListener('mouseover', function() { preload(this.href) }) e.addEventListener('click', function(e) { if (e.which > 1 || e.metaKey || e.ctrlKey) { return } e.preventDefault() display(this.href, ++t_count) if (t_count >= 1000) { t_count -= 1000 } }) } function store_quote(id) { if (!geid('message_' + id)) { window.console && console.log('can’t quote ' + id) return } var text if (geid('message_' + id).children[0].children[3].children.length == 2) { text = textToQuote(geid('message_' + id).innerHTML, geid('message_' + id).children[0].children[3].children[1].href) } else { text = textToQuote(geid('message_' + id).innerHTML) } if (geid('newmessage')) { if (geid('newmessage').value) { geid('newmessage').value += "\r\n\r\n" + text } else { geid('newmessage').value = text } geid('newmessage').focus() geid('newmessage').scrollTop = geid('newmessage').scrollHeight geid('newmessage').selectionStart = geid('newmessage').selectionEnd = geid('newmessage').value.length } else { storage('quote', text) } } function textToQuote(citation_html, lien_citation) { var pseudo = str_between(citation_html, 'title="Voir le profil de ', '"'); // var de = 'aeiou'.indexOf(pseudo[0].toLowerCase()) == -1 ? 'de ' : 'd’'; var de = 'de ' var date = str_between(citation_html, '

for (var i = 1; i < topics.length; i++) {
if (dossiers[i]) {
topics[i] = 'messages_prives/ico_black_on.png)

}
}
return html
}
function blacklist_dom() {
/* Utilisé quand on ignore quelqu’un sur le formulaire de réponse, on ne peut recharger col1 sans perdre le message */
var msgs = geclass('msg'), msg, childs, pseudo, has, button
for (var i = 0; i < msgs.length; i++) {
button = undefined
msg = msgs[i]
childs = msg.children[0].children[0].children
for (var j = 0; j < childs.length; j++) {
if (childs[j].tagName.toUpperCase() == 'STRONG') {
pseudo = childs[j].innerHTML
}
}
has = blacklist_has(pseudo)
childs = msg.children[0].children[1].children
for (var j = 0; j < childs.length; j++) {
if (childs[j].className == 'add_blacklist' && childs[j].getAttribute('message') == msg.id.substring('message_'.length)) {
button = childs[j]
}
}
if (has) {
msg.classList.add('msg_blacklisted')
button.title = 'Ne plus définir ' + pseudo + ' comme indésirable'
}
else {
msg.classList.remove('msg_blacklisted')
button.title = 'Définir ' + pseudo + ' comme indésirable'
}
}
}
/** Action **/
addEventListener('popstate', function() {
/* Arrive quand on utilise les boutons précédent/suivant du navigateur */
if (current_pathname == location.pathname) {
/* Lien permanent */
return
}
if (!p_history.html[no_hash(location.href)]) {
/* Arrive quand on a rafraîchit la page au préalable et que TurboForum n’a plus ce lien en mémoire */
location.href = location.href
return
}
current_pathname = location.pathname
col1.innerHTML = p_history.html[no_hash(location.href)]
document.title = p_history.title[no_hash(location.href)]
speed_up_all()
})
if (geid('fiche_infos2')) {
/* On retire la pub pour Amazon/Fnac sur les forums de jeux, elle est dans col2 alors qu’on update uniquement col1 */
remove_element('fiche_infos2')
}
if (geid('sponso_forum')) {
/* Présent sur certains forums de jeux comme LoL */
remove_element('sponso_forum')
}
blacklist_load()
current_pathname = location.pathname
col1.innerHTML = add_goodies(col1.innerHTML)
p_history.html[no_hash(location.href)] = col1.innerHTML
p_history.title[no_hash(location.href)] = document.title
speed_up_all(true)
if ((new Date().getTime() - storage('lastupdatecheck')) > 1000 * 60 * 60 * 12) {
check_update()
}
var style = document.createElement('style')
style.innerHTML = '.tf_update_bar { padding: 6px 0 8px; background: #ddd; box-shadow: 0 1px 3px rgba(0, 0, 0, .5); }\
.tf_update_bar_close { float: right; border: 1px solid rgba(0, 0, 0, .5); border-radius: 2px; background: white; font-size: 120%; padding: 0 4px; margin-right: 5px; cursor: pointer; }\
.msg .ancre { color: #666; }\
.add_blacklist { display: none; background: url(http://image.jeuxvideo.com/pics/messages_prives/ico_black_on.png) no-repeat; margin-right: 3px; cursor: pointer; opacity: .9; }\
.date:hover .add_blacklist { display: inline-block; height: 12px; width: 13px; }\
.msg_blacklisted .post, .msg_blacklisted .ancre { display: none; }\
.msg_blacklisted .pseudo { margin-bottom: 0; }\
.msg_blacklisted .add_blacklist { display: inline-block; height: 12px; width: 13px; background-image: url(http://image.jeuxvideo.com/pics/messages_prives/ico_black_off.png); opacity: 1; }\
.dossier_blacklisted { margin-left: 1px; }'
document.head.appendChild(style)
}
var script = document.createElement('script')
script.innerHTML = TurboForum.toString().substring()