Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name PGN Grabber
- // @namespace http://chess.move.grabber.com
- // @version 0.1
- // @description Copy the chess.com's PGN while playing a game
- // @author You
- // @match https://www.chess.com/game/*
- // @require https://code.jquery.com/jquery-2.1.4.min.js
- // @icon https://www.google.com/s2/favicons?domain=hibbard.eu
- // @grant none
- // ==/UserScript==
- // Note that you need to configure the setting on chess.com to display text instead of figurine for the chess moves
- // Also if you en-passant, you need to manually remove some html tags in the copied moves (you'll see).
- 'use strict';
- var $ = window.$;
- $(document).ready(function() {
- $('body').append('<input type="button" value="Copy PGN" id="CP">')
- $("#CP").css("position", "fixed").css("top", 0).css("right", 0);
- $('#CP').click(function(){
- var moves = $('.move');
- //console.log(moves.length)
- var pg = ""
- for(var i = 0; i < moves.length; i++) {
- //console.log(moves[i].attributes[1].value)
- var moveNum = $(moves[i]).attr('data-whole-move-number')
- var whiteMove = $(moves[i]).find('.white.node').html()
- var blackMove = $(moves[i]).find('.black.node').html()
- blackMove = (blackMove === undefined)? "" : blackMove
- pg += moveNum + ". " + whiteMove + " " + blackMove + " "
- //console.log(pg)
- }
- navigator.clipboard.writeText(pg); // copy to clipboard
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment