sentero-esp12

Untitled

Oct 25th, 2021
754
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Add time
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  try to take over the world!
  6. // @author       You
  7. // @match        https://lichess.org/*
  8. // @icon         https://www.google.com/s2/favicons?domain=lichess.org
  9. // @grant        none
  10. // ==/UserScript==
  11.  
  12. (function () {
  13.   'use strict';
  14.  
  15.   const div = document.createElement('div');
  16.   const button = document.createElement('button');
  17.   const input = document.createElement('input');
  18.   document.body.appendChild(div);
  19.   div.appendChild(input);
  20.   div.appendChild(button);
  21.  
  22.   div.style.position = 'absolute';
  23.   div.style.top = '50px';
  24.   button.style.color = 'black';
  25.   button.innerText = 'Add time';
  26.   button.style.display = 'block';
  27.   input.style.display = 'block';
  28.   input.name = 'opponent';
  29.   input.placeholder = `number of seconds`;
  30.   input.value = '1';
  31.  
  32.   const clientToken = '';
  33.  
  34.   const getGameId = () => {
  35.     return window.location.href
  36.       .replace('https://lichess.org/', '')
  37.       .replace('lichess.org/', '')
  38.       .replace(/\//g, '')
  39.       .substr(0, 8);
  40.   };
  41.  
  42.   async function postData(url = '') {
  43.     const response = await fetch(url, {
  44.       method: 'POST',
  45.       headers: {
  46.         'Content-Type': 'application/x-www-form-urlencoded',
  47.         Authorization: 'Bearer ' + clientToken,
  48.       },
  49.     });
  50.     return response.json();
  51.   }
  52.  
  53.   button.addEventListener(
  54.     'click',
  55.     (e) => {
  56.       if (!input.value || !clientToken) {
  57.         alert('not all data provided');
  58.         return;
  59.       }
  60.  
  61.       postData(
  62.         `https://lichess.org/api/round/${getGameId()}/add-time/${Number(
  63.           input.value
  64.         )}`
  65.       ).then((response) => {
  66.         console.log(response);
  67.       });
  68.     },
  69.     true
  70.   );
  71. })();
  72.  
RAW Paste Data