Skip to content

Instantly share code, notes, and snippets.

@1dNDN
Last active August 22, 2024 20:45
Show Gist options
  • Save 1dNDN/15680715cfcc7fd00f50206d19ec24c9 to your computer and use it in GitHub Desktop.
Save 1dNDN/15680715cfcc7fd00f50206d19ec24c9 to your computer and use it in GitHub Desktop.
Rutracker games plugin
// ==UserScript==
// @name Rutracker steamparser
// @namespace http://tampermonkey.net/
// @version 2024-03-09
// @author 1dNDN
// @match https://rutracker.org/forum/posting.php?f=*&mode=new_rel
// @icon https://www.google.com/s2/favicons?sz=64&domain=rutracker.org
// @connect store.steampowered.com
// @connect api.mobygames.com
// @grant GM_xmlhttpRequest
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
async function fill_form_steam() {
let id = document.getElementById('sukablyattextbox').value;
GM_xmlhttpRequest({
method: "GET",
url: 'https://store.steampowered.com/api/appdetails/?appids=' + id + "&l=russian",
headers: {
"Content-Type": "application/json"
},
onload: function(response) {
console.log(response);
var result = JSON.parse(response.response)[id].data;
document.getElementById('83df36fb9503b8bb497892029c6c1187').value = result.name;
document.getElementById('poster').value = result.header_image.split('?')[0];
var dateStr = result.release_date.date;
var monthsMap = new Map([
['янв.', 'января'],
['фев.', 'февраля'],
['мар.', 'марта'],
['апр.', 'апреля'],
['май', 'мая'],
['июн.', 'июня'],
['июл.', 'июля'],
['авг.', 'августа'],
['сен.', 'сентября'],
['окт.', 'октября'],
['ноя.', 'ноября'],
['дек.', 'декабря']
]);
monthsMap.forEach((value, key) => {
dateStr = dateStr.replace(new RegExp(key, 'g'), value);
});
var parts = dateStr.split(' ');
var dayAndMonth = parts[0] + ' ' + parts[1];
var year = parts[2]; // год
document.getElementById('d67cd3c09a5f8a18538e0c76070acfa6').value = year;
document.getElementById('8c8b3a7a50a4fed3ca2af1f772f2919f').value = dayAndMonth;
document.getElementById('e9c49d8613f61882379368b20187b1cb').value = result.developers;
document.getElementById('8633653175aa139fe9e0ecfbb9016cc0').value = result.publishers;
document.getElementById('game_source').value = "Digital";
//document.getElementById('bc5fbc970d3b8cd0e8894ebf9f92052a').value = "Steam";
document.getElementById('game_type_edition').value = "Неофициальный";
var stringWithoutTags = result.supported_languages.replace(/<.*?>/g, "");
var gameLanguages = stringWithoutTags.replace("озвучивание доступно на этих языках", "").split(',').map(function(lang) {
return lang.replace("*", "").trim();
});
var voiceLanguages = stringWithoutTags.replace("озвучивание доступно на этих языках", "").split(',').filter(function(lang) {
return lang.includes("*");
}).map(function(lang) {
return lang.replace("*", "").trim();
});
if (gameLanguages.includes("русский") && gameLanguages.includes("английский"))
{
document.getElementById('game_lang').value = "русский, английский";
document.getElementById('0f96fd7da7077e8fc402c98f872e1b8f').value = gameLanguages.filter(function(lang) {
return lang !== "русский" && lang !== "английский";
}).join(", ");
}
else if (gameLanguages.includes("английский"))
{
document.getElementById('game_lang').value = "английский";
document.getElementById('0f96fd7da7077e8fc402c98f872e1b8f').value = gameLanguages.filter(function(lang) {
return lang !== "английский";
}).join(", ");
} else if (gameLanguages.includes("русский"))
{
document.getElementById('game_lang').value = "русский";
document.getElementById('0f96fd7da7077e8fc402c98f872e1b8f').value = gameLanguages.filter(function(lang) {
return lang !== "русский";
}).join(", ");
} else if (gameLanguages.includes("японский"))
{
document.getElementById('game_lang').value = "японский";
document.getElementById('0f96fd7da7077e8fc402c98f872e1b8f').value = gameLanguages.filter(function(lang) {
return lang !== "японский";
}).join(", ");
} else
{
document.getElementById('game_lang').value = "другой";
document.getElementById('0f96fd7da7077e8fc402c98f872e1b8f').value = gameLanguages.join(", ");
}
//===============================
if (voiceLanguages.includes("русский") && voiceLanguages.includes("английский"))
{
document.getElementById('game_lang_sound').value = "русский, английский";
document.getElementById('37b7c16b89c9d5847492a54547863d44').value = voiceLanguages.filter(function(lang) {
return lang !== "русский" && lang !== "английский";
}).join(", ");
}
else if (voiceLanguages.includes("английский"))
{
document.getElementById('game_lang_sound').value = "английский";
document.getElementById('37b7c16b89c9d5847492a54547863d44').value = voiceLanguages.filter(function(lang) {
return lang !== "английский";
}).join(", ");
} else if (voiceLanguages.includes("русский"))
{
document.getElementById('game_lang_sound').value = "русский";
document.getElementById('37b7c16b89c9d5847492a54547863d44').value = voiceLanguages.filter(function(lang) {
return lang !== "русский";
}).join(", ");
} else if (voiceLanguages.includes("японский"))
{
document.getElementById('game_lang_sound').value = "японский";
document.getElementById('37b7c16b89c9d5847492a54547863d44').value = voiceLanguages.filter(function(lang) {
return lang !== "японский";
}).join(", ");
} else if (voiceLanguages.length == 0)
{
document.getElementById('game_lang_sound').value = "отсутствует";
}else
{
document.getElementById('game_lang_sound').value = "другой";
document.getElementById('37b7c16b89c9d5847492a54547863d44').value = voiceLanguages.join(", ");
}
document.getElementById('52f6b759203df86de6c550bba63d0c83').value = "Portable";
document.getElementById('8baf6af65599d806043e079219e49003').value = result.pc_requirements.minimum
.replace(/<strong>/g, "[b]")
.replace(/<\/strong>/g, "[/b]")
.replace(/<ul class="bb_ul">/g, "\n[list]")
.replace(/<\/ul>/g, "[/list]")
.replace(/<li>/g, "[*]")
.replace(/<[^>]*>/g, "") +
"\n\n" +
result.pc_requirements.recommended
.replace(/<strong>/g, "[b]")
.replace(/<\/strong>/g, "[/b]")
.replace(/<ul class="bb_ul">/g, "\n[list]")
.replace(/<\/ul>/g, "[/list]")
.replace(/<li>/g, "[*]")
.replace(/<[^>]*>/g, "");
var table = document
.getElementById('rel-form')
.getElementsByClassName('forumline')[0]
.getElementsByTagName('tbody')[0];
var textArea = document.getElementById('insertedTextarea');
if (!textArea) {
var row = table.insertRow(1);
var cellwithtext = row.insertCell();
var boldnode = document.createElement('strong');
var textnode = document.createTextNode("Скриншоты для вставки в Fastpic");
boldnode.appendChild(textnode);
cellwithtext.appendChild(boldnode);
var cellwithbutton = row.insertCell();
var textnodeforbox = document.createTextNode(result.screenshots.map(function(screenshot) {
return screenshot.path_full.split('?')[0];
}).slice(0, 30).join("\n"));
textnodeforbox.id = 'insertedTextarea';
cellwithbutton.appendChild(textnodeforbox);
}
else {
textArea.value = result.screenshots.map(function(screenshot) {
return screenshot.path_full.split('?')[0];
}).slice(0, 30).join("\n");
}
document.getElementById('5a043661f971dd53612df13ff90f3686').value = "отсутствует";
document.getElementById('2cb8c5db4fd55b97b76c1abcbf3d98d4').value = result.short_description;
console.log(result[id].success);
}
});
}
async function fill_form_moby() {
let id = document.getElementById('MobyGamestextbox').value;
let token = document.getElementById('mobytoken').value;
GM_setValue("mobytoken", token);
GM_xmlhttpRequest({
method: "GET",
url: "https://api.mobygames.com/v1/games/" + id + "/platforms/3?api_key=" + token,
headers: {
"Content-Type": "application/json"
},
onload: function(response) {
console.log(response);
var result = JSON.parse(response.response);
var dateStr = "2005-08-16";
var parts = dateStr.split('-');
var year = parts[0];
var month = parts[1];
var day = parts[2];
var months = [
"января", "февраля", "марта", "апреля", "мая", "июня",
"июля", "августа", "сентября", "октября", "ноября", "декабря"
];
var monthName = months[parseInt(month, 10) - 1];
var yearString = year;
var dateString = day + " " + monthName;
document.getElementById('d67cd3c09a5f8a18538e0c76070acfa6').value = yearString;
document.getElementById('8c8b3a7a50a4fed3ca2af1f772f2919f').value = dateString;
// Формирование списка для Published by
var publishedByList = result.releases.filter(function(release) {
return release.companies.some(function(company) {
return company.role === "Published by";
});
}).map(function(release) {
var publishedBy = release.companies.find(function(company) {
return company.role === "Published by";
});
return publishedBy.company_name + " | " + release.countries.join(', ') + " | " + release.release_date;
});
// Формирование списка для Developed by
var developedByList = result.releases.filter(function(release) {
return release.companies.some(function(company) {
return company.role === "Developed by";
});
}).map(function(release) {
var developedBy = release.companies.find(function(company) {
return company.role === "Developed by";
});
return developedBy.company_name + " | " + release.countries.join(', ') + " | " + release.release_date;
});
var table = document
.getElementById('rel-form')
.getElementsByClassName('forumline')[0]
.getElementsByTagName('tbody')[0];
var textArea = document.getElementById('publishertext');
var row = table.insertRow(1);
var cellwithtext = row.insertCell();
var boldnode = document.createElement('strong');
var textnode = document.createTextNode("Разработчики и издатели");
boldnode.appendChild(textnode);
cellwithtext.appendChild(boldnode);
var cellwithbutton = row.insertCell();
cellwithbutton.innerHTML = "Разработчики<br>" + developedByList.join("<br>") + "<br><br>Издатели <br>" + publishedByList.join("<br>");
console.log("Published_by:", publishedByList);
console.log("Developed_by:", developedByList);
}
});
}
function add_buttons(text, placeholder, textboxid, buttontext, id, fill_form){
var table = document
.getElementById('rel-form')
.getElementsByClassName('forumline')[0]
.getElementsByTagName('tbody')[0];
var row = table.insertRow(id);
var cellwithtext = row.insertCell();
var boldnode = document.createElement('strong');
var textnode = document.createTextNode(text);
boldnode.appendChild(textnode);
cellwithtext.appendChild(boldnode);
var cellwithbutton = row.insertCell();
var textbox = document.createElement('input');
textbox.id = textboxid;
textbox.type = "text";
textbox.placeholder = placeholder;
cellwithbutton.appendChild(textbox);
cellwithbutton.appendChild(document.createTextNode("\u00A0"));
if(text == "MobyGames"){
var mobytokentextbox = document.createElement('input');
mobytokentextbox.id = "mobytoken";
//mobytokentextbox.autocomplete = "on";
mobytokentextbox.type = "text";
mobytokentextbox.name = "mobytoken";
mobytokentextbox.placeholder = "MobyGames API token";
mobytokentextbox.value = GM_getValue("mobytoken", "");
cellwithbutton.appendChild(mobytokentextbox);
cellwithbutton.appendChild(document.createTextNode("\u00A0"));
}
var button = document.createElement('input');
button.setAttribute("type", "button");
button.onclick = fill_form;
button.setAttribute("value", buttontext);
button.setAttribute("style", "width: 150px;");
cellwithbutton.appendChild(button);
}
(function() {
'use strict';
add_buttons("Steam", "ID игры", "sukablyattextbox", 'ПОЕХАЛИ', 0, fill_form_steam);
add_buttons("MobyGames", "ID игры", "MobyGamestextbox", 'ПОЕХАЛИ', 1, fill_form_moby);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment