Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Add time
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description try to take over the world!
- // @author You
- // @match https://lichess.org/*
- // @icon https://www.google.com/s2/favicons?domain=lichess.org
- // @grant none
- // ==/UserScript==
- (function () {
- 'use strict';
- const div = document.createElement('div');
- const button = document.createElement('button');
- const input = document.createElement('input');
- document.body.appendChild(div);
- div.appendChild(input);
- div.appendChild(button);
- div.style.position = 'absolute';
- div.style.top = '50px';
- button.style.color = 'black';
- button.innerText = 'Add time';
- button.style.display = 'block';
- input.style.display = 'block';
- input.name = 'opponent';
- input.placeholder = `number of seconds`;
- input.value = '1';
- const clientToken = '';
- const getGameId = () => {
- return window.location.href
- .replace('https://lichess.org/', '')
- .replace('lichess.org/', '')
- .replace(/\//g, '')
- .substr(0, 8);
- };
- async function postData(url = '') {
- const response = await fetch(url, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded',
- Authorization: 'Bearer ' + clientToken,
- },
- });
- return response.json();
- }
- button.addEventListener(
- 'click',
- (e) => {
- if (!input.value || !clientToken) {
- alert('not all data provided');
- return;
- }
- postData(
- `https://lichess.org/api/round/${getGameId()}/add-time/${Number(
- input.value
- )}`
- ).then((response) => {
- console.log(response);
- });
- },
- true
- );
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement