Skip to content

Instantly share code, notes, and snippets.

@psenough
Last active March 6, 2024 15:59
Show Gist options
  • Save psenough/d9b0a2cd791b44b6e8d0d7a8d38611c6 to your computer and use it in GitHub Desktop.
Save psenough/d9b0a2cd791b44b6e8d0d7a8d38611c6 to your computer and use it in GitHub Desktop.
Demozoo pouet groups addon
// ==UserScript==
// @name Demozoo pouet groups addon
// @namespace http://tampermonkey.net/
// @version 0.34
// @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() {
'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);
}
}
}
}
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();
var theb = doc.querySelectorAll("b")[1];
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