// ==UserScript== // @name [HFR] Informations rapides sur le profil // @version 0.2.5c.2 // @namespace http://toyonos.info // @description Rajoute un accès rapide à certaines infos du profil d'un membre au passage de la souris sur le pseudo // @include https://forum.hardware.fr/* // @exclude https://forum.hardware.fr/message.php* // @grant GM_info // @grant GM_deleteValue // @grant GM_getValue // @grant GM_listValues // @grant GM_setValue // @grant GM_getResourceText // @grant GM_getResourceURL // @grant GM_addStyle // @grant GM_log // @grant GM_openInTab // @grant GM_registerMenuCommand // @grant GM_setClipboard // @grant GM_xmlhttpRequest // ==/UserScript== // historique modifs r21 : // 0.2.5c.2 (10/12/2017) : // - commentage des alert XML // 0.2.5c.1 (03/12/2017) : // - passage au https function getElementByXpath(path, element) { var arr = Array(), xpr = document.evaluate(path, element, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null); for (;item = xpr.iterateNext();) arr.push(item); return arr; } function di(a,b) { return ((a - (a%b)) / b); } function getRealPseudo(pseudoValue) { // Suppression du caractère spécial dans les pseudos longs return pseudoValue.split(String.fromCharCode(8203)).join(''); } var root = document.getElementById('mesdiscussions'); var profilUrl = 'https://forum.hardware.fr/profilebdd.php?config=hfr.inc&pseudo='; var cancel = false; var pseudos = getElementByXpath('.//table//td[@class="messCase1"]//b[@class="s2"]', root); pseudos.filter(function(pseudo) { return pseudo.innerHTML.match(/Profil su.*prim.*/) == null; } ).forEach(function(pseudo) { pseudo.style.cursor = 'help'; pseudo.addEventListener('click', function(){ window.open(profilUrl + getRealPseudo(this.innerHTML)); }, false); enhancePseudo(pseudo); } ); var pseudosCitation = getElementByXpath('.//table[@class="oldcitation" or @class="citation"]//td//b[@class="s1"]//a', root); pseudosCitation.forEach(function(pseudo) { var pseudoValue = pseudo.innerHTML.substr(0, (pseudo.innerHTML.length - ' a écrit :'.length)); enhancePseudo(pseudo, pseudoValue); } ); function enhancePseudo(pseudo) { var pseudoValue = enhancePseudo.arguments.length > 1 ? enhancePseudo.arguments[1] : getRealPseudo(pseudo.innerHTML); pseudo.addEventListener('mouseover', function(event) { cancel = false; toyoAjaxLib.loadDoc(profilUrl + pseudoValue, 'get', null, function(profilContent) { if (profilContent == null) return; var tmp; var nbPosts = profilContent.match(/Nombre de messages .* : <\/td>\s*([0-9]+)<\/td>/).pop(); var dateInscription = profilContent.match(/Date .* sur le forum : <\/td>\s*([0-9]{2}\/[0-9]{2}\/[0-9]{4})<\/td>/).pop(); var smileyPerso = (tmp = profilContent.match(/\"smilie/)) != null ? tmp.pop() : null; var smileyPerso1 = (tmp = profilContent.match(//)) != null ? tmp.pop() : null; var smileyPerso2 = (tmp = profilContent.match(//)) != null ? tmp.pop() : null; var smileyPerso3 = (tmp = profilContent.match(//)) != null ? tmp.pop() : null; var smileyPerso4 = (tmp = profilContent.match(//)) != null ? tmp.pop() : null; var smileyPerso5 = (tmp = profilContent.match(//)) != null ? tmp.pop() : null; var dateNaissance = (tmp = profilContent.match(/Date de naissance : <\/td>\s*([0-9]{2}\/[0-9]{2}\/[0-9]{4})<\/td>/)) != null ? tmp.pop() : null; var sexe = (tmp = profilContent.match(/[s|S]exe : <\/td>\s*(homme|femme)<\/td>/)) != null ? tmp.pop() : null; var ville = (tmp = profilContent.match(/[v|V]ille : <\/td>\s*(.*?)<\/td>/)) != null ? tmp.pop() : null; var dateMessage = profilContent.match(/Date du dernier message : <\/td>\s*\s*([0-9]{2})-([0-9]{2})-([0-9]{4}) . ([0-9]{2})\:([0-9]{2})\s*<\/td>/); dateMessage.shift(); var region = ''; var match = true, splitRegion = Array(); var r = new RegExp('(.*?)<\/a>', 'g'); while (match != null) { match = r.exec(profilContent); splitRegion.push(match != null ? match.pop() : null); } splitRegion.reverse().shift(); for (var i = 0; i < (splitRegion.length < 2 ? splitRegion.length : 2); i++) region += i != 0 ? ', ' + splitRegion[i] : splitRegion[i]; var age; if (dateNaissance != null) { var secondes = new Date().getTime() - new Date(dateNaissance.substring(6,10), dateNaissance.substring(3,5)-1, dateNaissance.substring(0,2)).getTime(); age = (secondes - (secondes % 31557600000)) / 31557600000 + " ans"; if (dateNaissance.substring(3,5)-1 == new Date().getMonth() && dateNaissance.substring(0,2) == new Date().getDate()) { age = '' + age + ' gateau'; } } else age = ' âge non précisé'; switch (sexe) { case "homme" : dateInscription = "Inscrit le " + dateInscription; sexe = "Homme"; break; case "femme" : dateInscription = "Inscrite le " + dateInscription; sexe = "Femme"; break; default : dateInscription = "Inscrit(e) le " + dateInscription; sexe = "Ange"; } ville = ville != "" && ville != null ? ville : 'Ville non précisée'; // Durée d'inactivité, suppose que l'heure locale de l'ordi est synchro avec le fuseau horaire utilisé par le forum var timeInac = di(new Date().getTime() - (new Date (dateMessage[2], dateMessage[1]-1, dateMessage[0], dateMessage[3], dateMessage[4]).getTime() ), 1000); if (timeInac <= 360) timeInac = "<5 min"; else if (timeInac < 3600) timeInac = di(timeInac,60) + " min"; else if (timeInac < 86400) timeInac = di(timeInac,3600) + " h"; else timeInac = di(timeInac,86400) + " jours"; var container = document.getElementById('infos_membre'); container.innerHTML = sexe + ", " + age + '
' + ville + ' (' + region + ')
' +dateInscription + '
' + nbPosts + ' posts'; container.innerHTML += '
Dernier post il y a ' + timeInac; if (smileyPerso != null) container.innerHTML += '
' + pseudoValue + ''; if (smileyPerso1 != null) container.innerHTML += '' + pseudoValue + ':1'; if (smileyPerso2 != null) container.innerHTML += '' + pseudoValue + ':2'; if (smileyPerso3 != null) container.innerHTML += '
' + pseudoValue + ':3'; if (smileyPerso4 != null) container.innerHTML += '' + pseudoValue + ':4'; if (smileyPerso5 != null) container.innerHTML += '' + pseudoValue + ':5'; setTimeout(function() { if (cancel) return; document.getElementById('infos_membre').style.display = 'block'; } , 500); }); var newDiv; if (document.getElementById('infos_membre')) { newDiv = document.getElementById('infos_membre'); } else { newDiv = document.createElement('div'); newDiv.setAttribute('id', 'infos_membre'); newDiv.style.position = 'absolute'; newDiv.style.border = '1px solid black'; newDiv.style.background = "white"; newDiv.style.padding = '3px'; newDiv.style.zIndex = '1001'; newDiv.style.display = 'none'; newDiv.className = 'signature'; root.appendChild(newDiv); } newDiv.style.left = (event.clientX + 8) + 'px'; newDiv.style.top = (window.scrollY + event.clientY + 8) + 'px'; } , false); pseudo.addEventListener('mouseout', function(event) { cancel = true; if (document.getElementById('infos_membre')) document.getElementById('infos_membre').style.display = 'none'; } , false); } /******************************************************************/ var toyoAjaxLib = (function() { // Private members function loadPage(url, method, arguments, responseHandler) { var req; method = method.toUpperCase(); if (method == 'GET' && arguments != null) url += '?' + arguments; // branch for native XMLHttpRequest object if (window.XMLHttpRequest) { req = new XMLHttpRequest(); req.onreadystatechange = processReqChange(req, responseHandler); req.open(method, url, true); if (method == 'POST') req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); arguments = method == 'POST' ? arguments : null; req.send(arguments); } else if (window.ActiveXObject) { // branch for IE/Windows ActiveX version req = new ActiveXObject("Microsoft.XMLHTTP"); if (req) { req.onreadystatechange = processReqChange(req, responseHandler); req.open(method, url, true); if (method == 'POST') req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); if (method == 'POST') req.send(arguments); else req.send(); } } } function processReqChange(req, responseHandler) { return function () { try { // only if req shows "loaded" if (req.readyState == 4) { // only if "OK" if (req.status == 200) { var content = req.responseXML != null && req.responseXML.documentElement != null ? req.responseXML.documentElement : req.responseText; if (responseHandler != null) responseHandler(content); } else if (req.status == 404) { if (responseHandler != null) responseHandler(null); } else { //alert("There was a problem retrieving the XML data:\n" + //req.statusText); } } } catch(e){} } } // Public members return { "loadDoc" : function(url, method, arguments, responseHandler) { try { loadPage(url, method, arguments, responseHandler); } catch(e) { var msg = (typeof e == "string") ? e : ((e.message) ? e.message : "Unknown Error"); alert("Unable to get data:\n" + msg); return; } } }; })(); // ============ Module d'auto update du script ============ ({ check4Update : function() { var autoUpdate = this; var mirrorUrl = GM_getValue('mirrorUrl', 'null'); if (mirrorUrl == 'null') autoUpdate.retrieveMirrorUrl(); var currentVersion = GM_getValue('currentVersion', '0.2.5c'); // On met éventuellement la version stockée à jour avec la version courante, si la version courante est plus récente if (autoUpdate.isLater('0.2.5c', currentVersion)) { GM_setValue('currentVersion', '0.2.5c'); currentVersion = '0.2.5c'; } // Par contre, si la version stockée est plus récente que la version courante -> création un menu d'update pour la dernière version else if (autoUpdate.isLater(currentVersion, '0.2.5c')) { GM_registerMenuCommand("[HFR] Informations rapides sur le profil -> Installer la version " + currentVersion, function() { GM_openInTab(mirrorUrl + 'infos_profil_hfr_v3.user.js'); } ); } // Si la version courante et la version stockée sont identiques, on ne fait rien if (GM_getValue('lastVersionCheck') == undefined || GM_getValue('lastVersionCheck') == '') GM_setValue('lastVersionCheck', new Date().getTime() + ''); // Pas eu de check depuis 24h, on vérifie... if ((new Date().getTime() - GM_getValue('lastVersionCheck')) > 86400000 && mirrorUrl != 'null') { var checkUrl = mirrorUrl + 'getLastVersion.php5?name=' + encodeURIComponent('[HFR] Informations rapides sur le profil'); if (isNaN(currentVersion.substring(currentVersion.length - 1))) checkUrl += '&sversion=' + currentVersion.substring(currentVersion.length - 1); GM_xmlhttpRequest({ method: "GET", url: checkUrl, onload: function(response) { var regExpVersion = new RegExp('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}[a-zA-Z]?$'); var lastVersion = response.responseText; // Pas d'erreur et nouvelle version plus récente if (lastVersion != '-1' && regExpVersion.test(lastVersion) && autoUpdate.isLater(lastVersion, currentVersion)) { if (confirm('Une nouvelle version de [HFR] Informations rapides sur le profil est disponible : ' + lastVersion + '\nVoulez-vous l\'installer ?')) { GM_openInTab(mirrorUrl + 'infos_profil_hfr_v3.user.js'); } else { // Mémorisation de la version refusée : elle servira de version de référence GM_setValue('currentVersion', lastVersion); } } GM_setValue('lastVersionCheck', new Date().getTime() + ''); } }); } }, max : function(v1, v2) { var tabV1 = v1.split('.'); var tabV2 = v2.split('.'); if (isNaN(tabV1[2].substring(tabV1[2].length - 1))) tabV1[2] = tabV1[2].substring(0, tabV1[2].length - 1); if (isNaN(tabV2[2].substring(tabV2[2].length - 1))) tabV2[2] = tabV2[2].substring(0, tabV2[2].length - 1); if ((tabV1[0] > tabV2[0]) || (tabV1[0] == tabV2[0] && tabV1[1] > tabV2[1]) || (tabV1[0] == tabV2[0] && tabV1[1] == tabV2[1] && tabV1[2] > tabV2[2])) { return v1; } else { return v2; } }, isLater : function(v1, v2) { return v1 != v2 && this.max(v1, v2) == v1; }, retrieveMirrorUrl : function() { var mirrors = 'http://hfr.toyonos.info/gm/;http://hfr-mirror.toyonos.info/gm/'.split(';'); var checkMirror = function (i) { var mirror = mirrors[i]; GM_xmlhttpRequest({ url: mirror + 'getLastVersion.php5', method: "HEAD", onload: function(response) { // Dès qu'un miroir répond, on le mémorise. if (response.status == 200) { GM_setValue('mirrorUrl', mirror); } else { // Sinon on test le prochain if ((i + 1) < mirrors.length) { checkMirror(i + 1); } else { GM_setValue('mirrorUrl', 'null'); } } } }); }; checkMirror(0); }, }).check4Update();