lichess.org
Donate

Is it allowed to send POST requests to /import using a userscript?

I want to make it easier for me to import games from other sites to the magnificent analyse tool that lichess has. Hence, I want to create a userscript that sends a POST request to lichess.org/import with the PGN data. Is this considered ok? Is it even possible, or does lichess use some kind of CSFR protection that stops this?
For the slow ones at the back - could you give as a simple sample script?
Peter
Well, say you get the PGN using a function named getPGN(). If you add a link to the website you want to analyze games from like this:

<a href="#" onclick="redirectToLichess()">Analyze at lichess.org</a>

Now you'd only have to create a JS function like this (I'm a pretty crappy at JS, so pardon my ugly code!):

function redirectToLichess() {
var form = document.createElement('form');
form.action = 'lichess.org/import';
form.method = 'post';
form.target = '_blank';
var textArea = document.createElement('textarea');
textArea.name = 'pgn';
textArea.id = 'pgn';
textArea.innerHTML = getPGN();
form.appendChild(textArea);
document.body.appendChild(form);
form.submit();
}

How you retrieve the PGN depends on the site you want to extract it from, someone makes it easy for you I'd guess, while in other cases you'd have to manually extract the meta-data and moves to create your own PGN - but that shouldn't be hard at all.

This topic has been archived and can no longer be replied to.