Last active
May 18, 2024 16:21
-
-
Save psenough/a9be72741d73ec2686c111a3490b01ee to your computer and use it in GitHub Desktop.
Demozoo pouet groups addon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Demozoo pouet groups addon | |
// @namespace http://tampermonkey.net/ | |
// @version 0.35 | |
// @description taking over the world by facilitating to add missing pouet productions to demozoo | |
// @author You | |
// @match https://demozoo.org/pouet/groups/* | |
// @match https://demozoo.org/productions/new/?* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=demozoo.org | |
// @grant GM_xmlhttpRequest | |
// ==/UserScript== | |
function getNextSiblings(elem, filter) { | |
var sibs = []; | |
while (elem = elem.nextSibling) { | |
if (elem.nodeType === 3) continue; // text node | |
if (!filter || filter(elem)) sibs.push(elem); | |
} | |
return sibs; | |
} | |
(function() { | |
'use strict'; | |
if (location.pathname === "/pouet/groups/") { | |
// exact match, parent page | |
var domt = document.getElementsByClassName("site__content"); | |
var count = domt[0].children[2].childElementCount; | |
domt[0].children[0].innerHTML += " ("+count+")"; | |
} else { | |
// group subpage or productions/new | |
// add links to insert new prod | |
var res = document.getElementsByClassName("pouet_prod"); | |
for (var i = 0; i < res.length; i++) { | |
var value = res[i].value; | |
let pid = document.createElement("a"); | |
pid.setAttribute('target',"_blank"); | |
pid.setAttribute('href',"https://demozoo.org/productions/new/?pouetid="+value); | |
pid.innerHTML="(insert)"; | |
res[i].parentNode.append(pid); | |
} | |
// add href to the proper group page (sometimes it's useful) | |
var res2 = document.getElementsByClassName("sceneorg"); | |
if (res2.length != 0) { | |
var text = res2[0].children[0].innerHTML; | |
var pos = text.indexOf(": ")+2; | |
var url = res2[0].baseURI.replace('pouet/',''); | |
var newtext = text.replace(text.substring(pos),'<a href="'+url+'">'+text.substring(pos)+'</a>'); | |
res2[0].children[0].innerHTML = newtext; | |
} | |
var pouetid = 0; | |
if (res.length === 0) { // should mean we are on new production page and not pouet/groups | |
const queryString = window.location.search; | |
const urlParams = new URLSearchParams(queryString); | |
pouetid = urlParams.get('pouetid'); | |
$.ajax({ | |
url:"https://api.pouet.net/v1/prod/?id="+pouetid, | |
dataType: 'jsonp', // Notice! JSONP <-- P (lowercase) | |
success:function(json){ | |
// do stuff with json (in this case an array) | |
fillOutForm(json); | |
}, | |
error:function(){ | |
alert("Error"); | |
} | |
}); | |
} | |
function fillOutForm(myArr) { | |
var title = document.getElementById("id_title"); | |
title.value = myArr["prod"]["name"]; | |
var by = document.getElementById("id_byline_search"); | |
by.value = myArr["prod"]["groups"][0]["name"]; | |
var date = document.getElementById("id_release_date"); | |
var str = myArr["prod"]["releaseDate"]; | |
if (str) { | |
//console.log(str); | |
var ym = str.substring(0, str.length-3); | |
if (ym.substring(4) == "-00") { | |
date.value = ym.substring(0, ym.length-3); | |
} else { | |
date.value = ym; | |
} | |
//if date.value.substring(-3, "-00") date.value= | |
} | |
var asm0 = document.getElementById("asmSelect0").getElementsByTagName('*'); | |
//console.log(asm0); | |
var dt = myArr["prod"]["types"]; | |
for (var i=0; i<dt.length; i++) { | |
for (var j=0; j<asm0.length; j++) { | |
var search = asm0[j].innerHTML.toLowerCase().search(dt[i]); | |
if (search != -1) { | |
//var attrib = asm0[j].getAttribute('rel'); | |
//console.log(dt[i]); | |
if ((asm0[j].innerHTML != " Intro") && (dt[i] == "intro")) { | |
} else { | |
asm0[j].selected="selected"; | |
var event = new Event('change'); | |
document.getElementById("asmSelect0").dispatchEvent(event); | |
} | |
} | |
if ( | |
((asm0[j].innerHTML === " Tool") && (dt[i] === "demotool")) | |
) | |
{ | |
asm0[j].selected="selected"; | |
var event2 = new Event('change'); | |
document.getElementById("asmSelect0").dispatchEvent(event2); | |
} | |
} | |
} | |
var asm1 = document.getElementById("asmSelect1").getElementsByTagName('*'); | |
var dp = myArr["prod"]; | |
for (const [key, value] of Object.entries(dp["platforms"])) { | |
var pname = value.name; | |
for (j=0; j<asm1.length; j++) { | |
var searchp = asm1[j].innerHTML.toLowerCase().search(pname.toLowerCase()); | |
if (searchp != -1) { | |
if ((asm1[j].innerHTML == "Commodore 64-DTV") && (pname == "Commodore 64")) { | |
} else { | |
asm1[j].selected="selected"; | |
var eventp = new Event('change'); | |
document.getElementById("asmSelect1").dispatchEvent(eventp); | |
} | |
} | |
} | |
} | |
var url = document.getElementById("id_links-0-url"); | |
url.value = myArr["prod"]["download"]; | |
var addUrlBtn = document.getElementsByClassName("add_button"); | |
var clk = new Event('click'); | |
addUrlBtn[0].dispatchEvent(clk); | |
var url1 = document.getElementById("id_links-1-url"); | |
url1.value = "https://www.pouet.net/prod.php?which="+pouetid; | |
var urlcount = 1; | |
if ((myArr["prod"]["csdb"] != null) && (myArr["prod"]["csdb"] != 0)) { | |
addUrlBtn[0].dispatchEvent(clk); | |
urlcount++; | |
var url2 = document.getElementById("id_links-"+urlcount+"-url"); | |
var csdb_url = "https://csdb.dk/release/?id="+myArr["prod"]["csdb"] | |
url2.value = csdb_url; | |
try { | |
GM.xmlHttpRequest({ | |
method: "GET", | |
url: csdb_url, | |
onload: function(response) { | |
var html_dump = response.responseText; | |
var doc = document.implementation.createHTMLDocument(); | |
doc.open(); | |
doc.writeln(html_dump); | |
doc.close(); | |
// get groups | |
var theb0 = doc.evaluate("//b[text()='Released by :']", doc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
if (theb0) { | |
var gps = getNextSiblings(theb0.nextElementSibling, null); | |
var names = ''; | |
//console.log(gps); | |
for (i=0;i<gps.length;i++) { | |
if (gps[i].nodeName.toUpperCase() == 'BR') break; | |
if (gps[i].nodeName.toUpperCase() == 'A') { | |
var thegroupnamefromcsdb = gps[i].innerText; | |
if (names != '') names += ' + '; | |
names += thegroupnamefromcsdb; | |
} | |
} | |
var groupname = document.getElementById("id_byline_search"); | |
groupname.value = names; | |
} | |
// get release date | |
var theb = doc.evaluate("//b[text()='Release Date :']", doc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
//var theb = doc.querySelectorAll("b")[1]; | |
if (theb) { | |
var thedatefromcsdb = theb.nextElementSibling.nextElementSibling.innerText; | |
var date = document.getElementById("id_release_date"); | |
date.value = thedatefromcsdb; | |
} | |
//console.log(theb.nextElementSibling.nextElementSibling.innerText); | |
//console.log(response.responseText); | |
} | |
}); | |
} | |
catch (err) { | |
console.log(err); | |
} | |
} | |
//console.log(myArr); | |
if (myArr["prod"]["downloadLinks"]) { | |
for (var k=0; k<myArr["prod"]["downloadLinks"].length; k++) { | |
var link = myArr["prod"]["downloadLinks"][k]["link"]; | |
if (link) { | |
addUrlBtn[0].dispatchEvent(clk); | |
urlcount++; | |
document.getElementById("id_links-"+urlcount+"-url").value = link; | |
} | |
} | |
} | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment