// ==UserScript==
// @name Miped reputation shower
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Показывает репутацию на форуме mipped.com
// @author Andronio
// @match https://mipped.com/f/threads/*
// @grant none
// @run-at document-idle
// ==/UserScript==
(function() {
'use strict';
let users = document.querySelectorAll('article .avatar.avatar--l');
let userTable = document.querySelectorAll('article .message-userExtras');
let xfToken = document.querySelector('input[name="_xfToken"]');
if (users.length == 0 || !xfToken) return;
xfToken = xfToken.value;
let links = [];
for (let i = 0; i < users.length; i++) {
links.push(users[i].href);
}
let requests = links.map(link => fetch(`${link}?tooltip=true&_xfRequestUri=${encodeURIComponent(location.pathname)}&_xfWithData=1&_xfToken=${encodeURIComponent(xfToken)}&_xfResponseType=json`,
{
"headers": {
"accept": "application/json, text/javascript, */*; q=0.01",
"accept-language": "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7",
"sec-ch-ua": "\"Chromium\";v=\"90\", \"Opera\";v=\"76\", \";Not A Brand\";v=\"99\"",
"sec-ch-ua-mobile": "?0",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"x-requested-with": "XMLHttpRequest"
},
"referrer": location.href,
"referrerPolicy": "strict-origin-when-cross-origin",
"body": null,
"method": "GET",
"mode": "cors",
"credentials": "include"
}).then(resp => resp.json()).catch(err => {
return {status: "error", message: "fetch catch error"};
}));
Promise.all(requests).then(resp => {
resp.map( (answer, index) => {
if (answer.status != 'ok') {
if (answer.hasOwnProperty('message')) console.log(answer.message);
return;
}
let repa = answer.html.content.match(/dl\sclass="pairs.*?<a.*?>.*?<\/a>/gs);
if (repa.length == 0) return;
repa = repa.find( elem => elem.indexOf('Репутация') >= 0);
if (repa == undefined) return;
repa = repa.match(/(?<=u-concealed">).*?\d{1,4}.*?(?=<\/a>)/gs);
if (repa.length == 0) return;
repa = repa[0].trim();
let dl = document.createElement('dl');
dl.className = 'pairs pairs--justified';
dl.innerHTML = `<dt>Репутация</dt><dd>${repa}</dd>`;
userTable[index].append(dl);
});
});
})();