Guest User

chess pgn grabber

a guest
Apr 13th, 2022
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         PGN Grabber
  3. // @namespace    http://chess.move.grabber.com
  4. // @version      0.1
  5. // @description  Copy the chess.com's PGN while playing a game
  6. // @author       You
  7. // @match        https://www.chess.com/game/*
  8. // @require      https://code.jquery.com/jquery-2.1.4.min.js
  9. // @icon         https://www.google.com/s2/favicons?domain=hibbard.eu
  10. // @grant        none
  11. // ==/UserScript==
  12.  
  13. // Note that you need to configure the setting on chess.com to display text instead of figurine for the chess moves
  14. // Also if you en-passant, you need to manually remove some html tags in the copied moves (you'll see).
  15.  
  16. 'use strict';
  17. var $ = window.$;
  18.  
  19. $(document).ready(function() {
  20.     $('body').append('<input type="button" value="Copy PGN" id="CP">')
  21.     $("#CP").css("position", "fixed").css("top", 0).css("right", 0);
  22.     $('#CP').click(function(){
  23.         var moves = $('.move');
  24.         //console.log(moves.length)
  25.         var pg = ""
  26.         for(var i = 0; i < moves.length; i++) {
  27.             //console.log(moves[i].attributes[1].value)
  28.             var moveNum = $(moves[i]).attr('data-whole-move-number')
  29.             var whiteMove = $(moves[i]).find('.white.node').html()
  30.             var blackMove = $(moves[i]).find('.black.node').html()
  31.             blackMove = (blackMove === undefined)? "" : blackMove
  32.             pg += moveNum + ". " + whiteMove + " " + blackMove + " "
  33.             //console.log(pg)
  34.         }
  35.         navigator.clipboard.writeText(pg); // copy to clipboard
  36.     });
  37. });
  38.  
  39.  
  40.  
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment