Skip to content

Instantly share code, notes, and snippets.

@mitzamitz
Created May 13, 2023 09:42
Show Gist options
  • Save mitzamitz/4038687c42ca63f5ff4e3708196fe164 to your computer and use it in GitHub Desktop.
Save mitzamitz/4038687c42ca63f5ff4e3708196fe164 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name dog tags fetcher
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author mitza
// @match https://www.torn.com/friendlist.php*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant GM_xmlhttpRequest
// @run-at document-end
// ==/UserScript==
function shortenNumber(num) {
let prefix = '';
if(num < 0) prefix = '-';
num = num.toString().replace(/[^0-9.]/g, '');
if (num < 1000) {
return num;
}
let si = [
{v: 1E3, s: "K"},
{v: 1E6, s: "M"},
{v: 1E9, s: "B"},
{v: 1E12, s: "T"},
{v: 1E15, s: "P"},
{v: 1E18, s: "E"}
];
let index;
for (index = si.length - 1; index > 0; index--) {
if (num >= si[index].v) {
break;
}
}
return prefix+(num / si[index].v).toFixed(2).replace(/\.0+$|(\.[0-9]*[1-9])0+$/, "$1") + si[index].s;
}
async function getUsers(){
let res;
await GM.xmlHttpRequest({
method: "GET",
url: `https://tsc.diicot.cc/dog`,
headers: {
'Authorization': 'uwuthedogissussy',
'x-requested-with': 'XMLHttpRequest',
'Content-Type': 'application/json'
},
onload: function(response) {
res = response.responseText;
}
});
return res;
}
(async function() {
$("div.content-wrapper").empty();
let userList = JSON.parse(await getUsers());
console.log(userList);
let html = `<div style="background-color: #111; color: #ccc; text-align: center;display: inline-block;min-width: 750px; margin:10px;">
<div>
<div style="background-color: #111; min-height: 50px; font-size: 24px;">Tag list</div>
<div>
<table border="1px" width="100%" style="font-size: 24px;">
<tr>
<th>Name</th>
<th>Faction</th>
<th>Tags</th>
<th>Stats</th>
<th>Status</th>
</tr>`;
for (let i of userList)
{
if(i.status!=="Okay") continue;
let nD = `<tr height=25px>
<td style="color:#f22; border:2px #ccc solid;"><a href=${i.link} style="color:#f22;">${i.name}</a></td>
<td style="color:#ccc; border:2px #ccc solid;">${i.faction}</td>
<td style="color:#ccc; border:2px #ccc solid;">${i.tags}</td>
<td style="color:#ccc; border:2px #ccc solid;">${shortenNumber(i.stats)}</td>
<td style="color:#ccc; border:2px #ccc solid;">${i.status}</td>
</tr>`;
html = html + nD;
}
let eD= `</table>
</div>
</div>`;
html = html + eD;
$("div.content-wrapper").append(html);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment