// ==UserScript== // @name GGn vndb uploady new // @namespace none // @version 1 // @description gazellegames vndb uploady. input game title in game title field or vndb id (anything with v(digits)) to fill // @author ingts // @match https://gazellegames.net/upload.php* // @connect api.vndb.org // @icon none // @grant GM_xmlhttpRequest // @downloadURL none // ==/UserScript== 'use strict'; const autoPTPimg = true const tagsDictionary = { 'romance': ["Romance", "Interest", "Love", "Polyamory", "Polygamy", "Swinging"], 'horror': ["Horror", "Graphic Violence"], 'science.fiction': ["Science Fiction", "AI"], 'drama': ["Drama", "Suicide", "Suicidal", "Desperation"], 'crime': ["Crime", "Slave"], 'mystery': ["Mystery"], 'comedy': ["Comedy", "Slapstick"], 'fantasy': ["Fantasy", "Magic", "Mahou", "Superpowers"] } const gameTitleInput = document.getElementById('title'); gameTitleInput.insertAdjacentHTML("afterend", 'vndb'); const fill_vndb = document.getElementById('fill_vndb') function removeLastBracket(str) { if (!str.endsWith(']')) return str let i = str.length - 1 let bracketCounter = 0; for (; i >= 0; i--) { if (str[i] === ']') { bracketCounter++; } else if (str[i] === '[') { bracketCounter--; if (bracketCounter === 0) { break; } } } return str.substring(0, i).trim(); } function fill(results) { document.getElementById('platform').value = 'Windows' results.languages.includes("en") ? gameTitleInput.value = results.titles[0].title : gameTitleInput.value = results.title document.getElementById('aliases').value = [results.alttitle, results.aliases.join(", ")].filter(Boolean).join(', ') const tagsInput = document.getElementById('tags') let foundTags = [] Object.keys(tagsDictionary).forEach(ggnTag => { const vndbTags = tagsDictionary[ggnTag]; results.tags.map(tag => { vndbTags.forEach(word => { if (tag.name.includes(word) && !foundTags.includes(ggnTag)) { foundTags.push(ggnTag); } }); }); }); foundTags.length === 0 ? tagsInput.value = 'visual.novel' : tagsInput.value = `visual.novel, ${foundTags.join(', ')}` document.getElementById('year').value = results.released.split('-')[0] GM_xmlhttpRequest({ method: 'POST', url: 'https://api.vndb.org/kana/release', headers: {'Content-Type': 'application/json'}, data: JSON.stringify({ "filters": ["vn", "=", ["id", "=", results.id]], "fields": "minage, has_ero", "results": 100 }), responseType: "json", onload: function (response) { let ratingSelectValue const highestMinAge = Math.max(...response.response.results.map(result => result.minage)); if (highestMinAge === 12 || highestMinAge === 13) ratingSelectValue = 5 else if (highestMinAge === 16 || highestMinAge === 17) ratingSelectValue = 7 else if (highestMinAge >= 18) ratingSelectValue = 9 else ratingSelectValue = 13 document.getElementById('Rating').value = ratingSelectValue if (response.response.results.some(r => r.has_ero)) tagsInput.value += ', adult' } }) document.getElementById('image').value = results.image.url if (autoPTPimg) document.getElementById('image').nextElementSibling.click() const systemRequirements = ` [quote][align=center][b][u]System Requirements[/u][/b][/align] [*][b]OS[/b]: [*][b]Processor[/b]: [*][b]Memory[/b]: [*][b]Graphics[/b]: [*][b]DirectX[/b]: [*][b]Storage[/b]: [/quote]` document.getElementById('album_desc').value = `[align=center][b][u]About the game[/u][/b][/align] ${removeLastBracket(results.description)} ${systemRequirements} ` if(results.platforms.some(p => !['win', 'lin', 'mac'].includes(p))){ fill_vndb.removeEventListener('click', firstClick) fill_vndb.textContent = 'console version found. remove system requirements?' fill_vndb.addEventListener('click', ()=>{ document.getElementById('album_desc').value = document.getElementById('album_desc').value.replace(systemRequirements, '') fill_vndb.outerHTML = 'removed' }) } const screens = document.getElementsByName("screens[]"); const add_screen = document.querySelector("#image_block a[href='#']"); results.screenshots.forEach(function (screen, index) { if (index >= 20) return; if (index >= 4) add_screen.click(); screens[index].value = screen.url; if (autoPTPimg) screens[index].nextElementSibling.click() }); } function firstClick (){ if (gameTitleInput.value !== "") { let vndbFilter; const linkmatch = gameTitleInput.value.match(/v(\d+)/) linkmatch ? vndbFilter = ["id", "=", `${linkmatch[1]}`] : vndbFilter = ["search", "=", `${gameTitleInput.value}`] GM_xmlhttpRequest({ method: 'POST', url: 'https://api.vndb.org/kana/vn', headers: {'Content-Type': 'application/json'}, data: JSON.stringify({ "filters": vndbFilter, "fields": "alttitle, titles.title, title, aliases, description, image.url, screenshots.url, released, languages, tags.name, platforms", "results": 1 }), responseType: "json", onload: function (response) { fill(response.response.results[0]) } }) } } fill_vndb.addEventListener('click', firstClick)