├── .gitignore ├── CHANGELOG.md ├── LICENCE.md ├── README.md ├── ext.crx ├── ext.pem ├── ext ├── _locales │ └── en │ │ └── messages.json ├── css │ └── getpgn.css ├── icons │ ├── generatePgnsFromSvg.sh │ ├── knight.svg │ ├── knight128.png │ ├── knight16.png │ ├── knight256.png │ ├── knight32.png │ ├── knight48.png │ ├── knight512.png │ └── knight64.png ├── js │ └── jquery-3.5.1.min.js ├── manifest.json └── src │ └── bg │ ├── analysis.js │ ├── background.js │ ├── getpgn.js │ ├── package-lock.json │ └── package.json └── screenshots ├── chessCom.png └── lichessOrg.png /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | temp 3 | .tmp 4 | dist 5 | *.sublime-project 6 | *.sublime-workspace 7 | .DSStore -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## Version 4.0.5 - 2025-03-20 4 | * Fixed for changed URL for live games. (Thanks stupidJoon!) 5 | 6 | ## Version 4.0.4 - 2024-12-04 7 | * Fixed for recent changes to chess.com stylesheets. 8 | * Fixed for world championship games. 9 | 10 | ## Version 4.0.3 - 2023-05-24 11 | * Fixed support for archived games against computers. 12 | 13 | ## Version 4.0.2 - 2022-04-17 14 | * Fixed for change to chess.com download button. 15 | 16 | ## Version 4.0.1 - 2022-03-28 17 | * Fixed for change to chess.com download button. 18 | * Chrome manifest v3 does not support jQuery calls from background. Refactored. 19 | * Fixed chessgames.com support which now requires https. 20 | 21 | ## Version 4.0.0 - 2022-03-27 22 | * Migrated to Chrome manifest v3. (Thanks russelldavis!) 23 | * Improved support for chesstempo.com. 24 | 25 | ## Version 3.8.1 - 2022-03-04 26 | * Prevented chess.com analysis from being sent to lichess. (Thanks russelldavis!) 27 | 28 | ## Version 3.8.0 - 2021-12-20 29 | * Fixed for chess.com with download button (Thanks guidezpl!) 30 | 31 | ## Version 3.7.0 - 2021-07-29 32 | * Fixed for chess.com daily games 33 | * Now works from chess.com event pages 34 | 35 | ## Version 3.6.0 - 2021-02-06 36 | * Fixed for chess.com analysis pages. (Thanks Johannes!) 37 | * Upgraded to jQuery 3.5.1. 38 | 39 | ## Version 3.5.0 - 2020-11-17 40 | * Now works from the chess.com analysis pages. 41 | * Updated for recent changes to chess.com. (Thanks danickfort!) 42 | 43 | ## Version 3.4.0 - 2020-09-19 44 | * Fixed problems related to url changes in chess.com and chesstempo.com. 45 | 46 | ## Version 3.3.0 - 2020-09-03 47 | * Support for the new url format on chess.com. (Thanks mhssmnn!) 48 | 49 | ## Version 3.2.0 - 2019-12-20 50 | * Updated for recent changes to chess.com. 51 | 52 | ## Version 3.1.0 53 | * Updated for recent changes to chess.com. 54 | 55 | ## Version 3.0.1 56 | * Workaround for chess.com bug where the 'result' field in the pgn is not updated after a player times out. 57 | 58 | ## Version 3.0.0 59 | * Support for games from chessgames.com, chess-db.com and chesstempo.com. 60 | * Improved manifest to limit permissions as much as possible. 61 | * Icon now becomes enabled only when there is a valid game to analyse. 62 | * Improved colour of icon so that it is clear when it is available. 63 | 64 | ## Version 2.6.1 65 | * Fixed for immediately finished live games. 66 | 67 | ## Version 2.6.0 68 | * Updated for recent changes to chess.com. Calls are now async. (Thanks 0ddFell0w!) 69 | * Added support for analysis of daily games. 70 | 71 | ## Version 2.5.6 72 | * Updated for recent changes to Lichess import page. 73 | 74 | ## Version 2.5.5 75 | 76 | * Link was not working immediately from live games. 77 | * Upgraded to jQuery 3.3.1. 78 | 79 | ## Version 2.5.4 80 | 81 | * Fixed broken link when analysing after game has finished. 82 | * Now works from live analysis board (urls with 'live#a=1234567'). 83 | 84 | ## Version 2.5.3 85 | 86 | * Print-friendly PDF has been removed to a separate extension (Lichess Print-friendly PDF)[https://chrome.google.com/webstore/detail/lichess-print-friendly-pd/goijhimgdjppmhmjkaglhggoapkgobfg]. 87 | 88 | ## Version 2.5.2 89 | 90 | * Print-friendly PDF export now uses AWS lambda. 91 | 92 | ## Version 2.5.1 93 | 94 | * Games lost on time were not being detected as such during lichess import. 95 | 96 | ## Version 2.5.0 97 | 98 | * Added support for 'Print-friendly PDF export' which was removed from lichess in November 2016. 99 | 100 | ## Version 2.4.4 101 | 102 | * Fixed support for analysing live games. 103 | 104 | ## Version 2.4.2 105 | 106 | * 'Export to PDF' from lichess was not correctly determining the winner owing to an anomaly in the chess.com pgn. 107 | 108 | ## Version 2.4.1 109 | 110 | * Fixed css name clash. 111 | 112 | ## Version 2.4.0 113 | 114 | * Analyse any live game! (in v3). 115 | * Fixes to support chess.com changes in v3. 116 | * Improved method of pgn retrieval in v3. Much smoother transition. 117 | * Warning message is displayed when the game is still in progress. 118 | 119 | ## Version 2.3.0 120 | 121 | * Fixed to support https changes on lichess.org. 122 | 123 | ## Version 2.2.1 124 | 125 | * Improved reliability of toggling 'computer analysis' before submitting pgn to lichess. 126 | 127 | ## Version 2.2.0 128 | 129 | * Fixed since chess.com change to 'switch to old chess.com' which now requires POST. 130 | -------------------------------------------------------------------------------- /LICENCE.md: -------------------------------------------------------------------------------- 1 | Licensed under the [MIT license](http://www.opensource.org/licenses/MIT): 2 | 3 |
 4 | Copyright (c) 2016-2022 Robert Anderson
 5 | 
 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files 
 7 | (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, 
 8 | merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
 9 | furnished to do so, subject to the following conditions:
10 | 
11 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12 | 
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
14 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
15 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
16 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | 
-------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## A Chrome extension to open a chess.com game in lichess.org's analysis. ## 2 | 3 | This extension has the following features: 4 | 5 | * Uploads any finished game on chess.com, chess-db.com, chesstempo.com or chessgames.com for lichess analysis. 6 | * Works from the game archive as well as from finished live games. 7 | * Automatically toggles the 'computer analysis' check box on the lichess.org import page. 8 | 9 | The extension can be downloaded here: https://chrome.google.com/webstore/detail/bhjlkimpkkgkmfjlcfngmakenalgleap 10 | 11 | Thanks to Allan Rempel who created a similar plugin for chess.com v2. 12 | 13 | Icon CC-BY-SA 3.0, CBurnett (https://en.wikipedia.org/wiki/User:Cburnett) 14 | with adjustments by AntonSusi (https://commons.wikimedia.org/wiki/User:Antonsusi). 15 | -------------------------------------------------------------------------------- /ext.crx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeroSharp/Chess.com_Analysis_Chrome_extension/b3e9fbc6efffaacbb3b3d8a7fa12adc6e93717ff/ext.crx -------------------------------------------------------------------------------- /ext.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDdrE3Yh9R+amY3 3 | AHhGPAXmVt6hQf/AOi+v8rEXG7w3Qvjy++w2XcOj4GLhWkFKyXwrBUNWC0eL3E57 4 | S+knCcp+x3nA+8DoMbzbvsw4sKXqBXvVO9uKaHrtQV3O0c5kb4LmXMpRJYzauSNR 5 | PgSrEJUShP72Ysi4v4LzmcVJ1H2Dy/gHTpBlpvkpmiWFrw8w1CNpSkxVsWgiW0D5 6 | ewxtykTu5mKNMOKNwu8H8QNFwgJc6iyb8/OsqAWWILhfC7IDVy8tN0S7FjYNp85K 7 | AXqAuSaogOHdn3ylCEVRXqL99KtMBowxMScBJX8KZA35CXH8uNUvSEn/sSZXkCCY 8 | i5YcFDG3AgMBAAECggEAE5X6SNPzh/nhryFo/xelk80AHbJlpPffJ8YjNH38Wsud 9 | kGaG3+TX+N5GDlA5raBwyqJL6UnU1/wuqQEziAH69MmuLclwqXNfkvDgPXAKMMus 10 | PdJsmuWRWu4oGjJ6cHBT2gO/0nylXdv2zWJT6kNsUHcUyfM/dedh7CEdh+Dw+Bh+ 11 | 1h4ekuNTDn3Moaeztys3gmJmORHuiMpYdKmeaXUHP0tIDOego5dim/tnhhFBHhho 12 | EVDnI6Ddr0WYthuOdPuf/MrKeTxDtHaVPgzr/rv8/icEf568s6yAFRPhvrJ4RsIZ 13 | 7Gg7Yv+F/0Mb9z51wEdqn38rohGRrxcXqyKbAXAD5QKBgQD8k4+6w7Qe8+t+MuOE 14 | hYKo2pCo91WIy6rU7iX1s9COAZRw6FA+sFaPWUa4gFt2iA4LK0oDde8sSpEzztlK 15 | M1geYxcRAGBqLAhttqtrz5QTSLC65eRQRc0Edr4+COJPQnGO1+1LCTXr80CeQyz5 16 | 9QuW+MDhptarivdb7nw4KMYWZQKBgQDgrYIaZscQghWGkMkMrOmv5JBGTqKgX48C 17 | n9TlyEIORb1QzHAZyU56i8KyKIIDx+IR2JqIc2Dg5Kuz4aSCco3dxkRmCh+d04G5 18 | oaGFvlekbBS85qfRK4S94J5eWCjix81qhpiNo8NonRz4uYiww24/Y28FFZQV7R+T 19 | g7IIYR9n6wKBgC4W4zhqc9jeG8/oi1noXwJe99zNXV9cAu1eE7E1Qc5X/XVo/xOh 20 | a/o2iVArpAUKKL3jBVuCTsWfScXRbhc7LU5GOLRShEV7iYIzvi4rL9MhBZblUndP 21 | dWzmGisJxfo+nqg5QMTbhmpq9hSrH27xR08iT1gd8LhW4HJ3H1XEIvl9AoGBAN6Q 22 | AglVNmxL8DbUxdQglXz/1UtQKhjjkC7xVVwp/AVXYCnh2kow9+S8/aiuJ9zG7FLx 23 | VmNEp/sfilcudmAiShYeiTLrZFZbZm4UhoSOAROHXSOi+SpjCaNuFnMusZG0iu+z 24 | VPs59iBzQnfAkn9HmLaCMT/AGGl/83+VPY6/ZvTxAoGAf0wQ+kb6n1zlEbp/6wSQ 25 | yEYLSnsBI3C+tNFXhoZRdvZnlOiECqiJQUCM07bseVAK4M4Mah0exAaLxz3EGJhF 26 | TMjpZx8Ntj61hRvTpoePfWscCEtTBff57mTVCgr8uYCLjLm/tLKGWsrDMFjjJ/qm 27 | r4ilncxs09C4K4gJhxZnARU= 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /ext/_locales/en/messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": { 3 | "description": "A short description of the extension", 4 | "message": "Opens PGN of a Chess.com (v3) game in lichess.org analysis" 5 | }, 6 | "locale": { 7 | "description": "2-letter language code (excluding subvariant)", 8 | "message": "en" 9 | }, 10 | "name": { 11 | "description": "Extension name", 12 | "message": "Chess.com (v3) Analysis" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ext/css/getpgn.css: -------------------------------------------------------------------------------- 1 | .popuptoast { 2 | width:200px; 3 | height:20px; 4 | height:auto; 5 | position:absolute; 6 | left:50%; 7 | margin-left:-100px; 8 | top:40px; 9 | background-color: #C66666; 10 | color: #F0F0F0; 11 | font-family: Calibri; 12 | font-size: 20px; 13 | padding:10px; 14 | text-align:center; 15 | border-radius: 2px; 16 | -webkit-box-shadow: 0px 0px 24px -1px rgba(56, 56, 56, 1); 17 | -moz-box-shadow: 0px 0px 24px -1px rgba(56, 56, 56, 1); 18 | box-shadow: 0px 0px 24px -1px rgba(56, 56, 56, 1); 19 | } -------------------------------------------------------------------------------- /ext/icons/generatePgnsFromSvg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # To regenerate the icons. The CLI for Inkspace needs full paths. 4 | 5 | for x in 16 32 48 64 128 256 512 6 | do 7 | inkscape --export-png /Users/ra/Projects/github/chessChrome/ext/icons/knight${x}.png -w ${x} /Users/ra/Projects/github/chessChrome/ext/icons/knight.svg 8 | done 9 | -------------------------------------------------------------------------------- /ext/icons/knight.svg: -------------------------------------------------------------------------------- 1 | 2 | 16 | 18 | 19 | 21 | image/svg+xml 22 | 24 | 25 | 26 | 27 | 29 | 49 | 52 | 56 | 60 | 64 | 69 | 70 | 75 | 80 | 81 | -------------------------------------------------------------------------------- /ext/icons/knight128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeroSharp/Chess.com_Analysis_Chrome_extension/b3e9fbc6efffaacbb3b3d8a7fa12adc6e93717ff/ext/icons/knight128.png -------------------------------------------------------------------------------- /ext/icons/knight16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeroSharp/Chess.com_Analysis_Chrome_extension/b3e9fbc6efffaacbb3b3d8a7fa12adc6e93717ff/ext/icons/knight16.png -------------------------------------------------------------------------------- /ext/icons/knight256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeroSharp/Chess.com_Analysis_Chrome_extension/b3e9fbc6efffaacbb3b3d8a7fa12adc6e93717ff/ext/icons/knight256.png -------------------------------------------------------------------------------- /ext/icons/knight32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeroSharp/Chess.com_Analysis_Chrome_extension/b3e9fbc6efffaacbb3b3d8a7fa12adc6e93717ff/ext/icons/knight32.png -------------------------------------------------------------------------------- /ext/icons/knight48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeroSharp/Chess.com_Analysis_Chrome_extension/b3e9fbc6efffaacbb3b3d8a7fa12adc6e93717ff/ext/icons/knight48.png -------------------------------------------------------------------------------- /ext/icons/knight512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeroSharp/Chess.com_Analysis_Chrome_extension/b3e9fbc6efffaacbb3b3d8a7fa12adc6e93717ff/ext/icons/knight512.png -------------------------------------------------------------------------------- /ext/icons/knight64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeroSharp/Chess.com_Analysis_Chrome_extension/b3e9fbc6efffaacbb3b3d8a7fa12adc6e93717ff/ext/icons/knight64.png -------------------------------------------------------------------------------- /ext/js/jquery-3.5.1.min.js: -------------------------------------------------------------------------------- 1 | /*! jQuery v3.5.1 | (c) JS Foundation and other contributors | jquery.org/license */ 2 | !function(e,t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(C,e){"use strict";var t=[],r=Object.getPrototypeOf,s=t.slice,g=t.flat?function(e){return t.flat.call(e)}:function(e){return t.concat.apply([],e)},u=t.push,i=t.indexOf,n={},o=n.toString,v=n.hasOwnProperty,a=v.toString,l=a.call(Object),y={},m=function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},x=function(e){return null!=e&&e===e.window},E=C.document,c={type:!0,src:!0,nonce:!0,noModule:!0};function b(e,t,n){var r,i,o=(n=n||E).createElement("script");if(o.text=e,t)for(r in c)(i=t[r]||t.getAttribute&&t.getAttribute(r))&&o.setAttribute(r,i);n.head.appendChild(o).parentNode.removeChild(o)}function w(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?n[o.call(e)]||"object":typeof e}var f="3.5.1",S=function(e,t){return new S.fn.init(e,t)};function p(e){var t=!!e&&"length"in e&&e.length,n=w(e);return!m(e)&&!x(e)&&("array"===n||0===t||"number"==typeof t&&0+~]|"+M+")"+M+"*"),U=new RegExp(M+"|>"),X=new RegExp(F),V=new RegExp("^"+I+"$"),G={ID:new RegExp("^#("+I+")"),CLASS:new RegExp("^\\.("+I+")"),TAG:new RegExp("^("+I+"|[*])"),ATTR:new RegExp("^"+W),PSEUDO:new RegExp("^"+F),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:new RegExp("^(?:"+R+")$","i"),needsContext:new RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Y=/HTML$/i,Q=/^(?:input|select|textarea|button)$/i,J=/^h\d$/i,K=/^[^{]+\{\s*\[native \w/,Z=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ee=/[+~]/,te=new RegExp("\\\\[\\da-fA-F]{1,6}"+M+"?|\\\\([^\\r\\n\\f])","g"),ne=function(e,t){var n="0x"+e.slice(1)-65536;return t||(n<0?String.fromCharCode(n+65536):String.fromCharCode(n>>10|55296,1023&n|56320))},re=/([\0-\x1f\x7f]|^-?\d)|^-$|[^\0-\x1f\x7f-\uFFFF\w-]/g,ie=function(e,t){return t?"\0"===e?"\ufffd":e.slice(0,-1)+"\\"+e.charCodeAt(e.length-1).toString(16)+" ":"\\"+e},oe=function(){T()},ae=be(function(e){return!0===e.disabled&&"fieldset"===e.nodeName.toLowerCase()},{dir:"parentNode",next:"legend"});try{H.apply(t=O.call(p.childNodes),p.childNodes),t[p.childNodes.length].nodeType}catch(e){H={apply:t.length?function(e,t){L.apply(e,O.call(t))}:function(e,t){var n=e.length,r=0;while(e[n++]=t[r++]);e.length=n-1}}}function se(t,e,n,r){var i,o,a,s,u,l,c,f=e&&e.ownerDocument,p=e?e.nodeType:9;if(n=n||[],"string"!=typeof t||!t||1!==p&&9!==p&&11!==p)return n;if(!r&&(T(e),e=e||C,E)){if(11!==p&&(u=Z.exec(t)))if(i=u[1]){if(9===p){if(!(a=e.getElementById(i)))return n;if(a.id===i)return n.push(a),n}else if(f&&(a=f.getElementById(i))&&y(e,a)&&a.id===i)return n.push(a),n}else{if(u[2])return H.apply(n,e.getElementsByTagName(t)),n;if((i=u[3])&&d.getElementsByClassName&&e.getElementsByClassName)return H.apply(n,e.getElementsByClassName(i)),n}if(d.qsa&&!N[t+" "]&&(!v||!v.test(t))&&(1!==p||"object"!==e.nodeName.toLowerCase())){if(c=t,f=e,1===p&&(U.test(t)||z.test(t))){(f=ee.test(t)&&ye(e.parentNode)||e)===e&&d.scope||((s=e.getAttribute("id"))?s=s.replace(re,ie):e.setAttribute("id",s=S)),o=(l=h(t)).length;while(o--)l[o]=(s?"#"+s:":scope")+" "+xe(l[o]);c=l.join(",")}try{return H.apply(n,f.querySelectorAll(c)),n}catch(e){N(t,!0)}finally{s===S&&e.removeAttribute("id")}}}return g(t.replace($,"$1"),e,n,r)}function ue(){var r=[];return function e(t,n){return r.push(t+" ")>b.cacheLength&&delete e[r.shift()],e[t+" "]=n}}function le(e){return e[S]=!0,e}function ce(e){var t=C.createElement("fieldset");try{return!!e(t)}catch(e){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function fe(e,t){var n=e.split("|"),r=n.length;while(r--)b.attrHandle[n[r]]=t}function pe(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&e.sourceIndex-t.sourceIndex;if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function de(t){return function(e){return"input"===e.nodeName.toLowerCase()&&e.type===t}}function he(n){return function(e){var t=e.nodeName.toLowerCase();return("input"===t||"button"===t)&&e.type===n}}function ge(t){return function(e){return"form"in e?e.parentNode&&!1===e.disabled?"label"in e?"label"in e.parentNode?e.parentNode.disabled===t:e.disabled===t:e.isDisabled===t||e.isDisabled!==!t&&ae(e)===t:e.disabled===t:"label"in e&&e.disabled===t}}function ve(a){return le(function(o){return o=+o,le(function(e,t){var n,r=a([],e.length,o),i=r.length;while(i--)e[n=r[i]]&&(e[n]=!(t[n]=e[n]))})})}function ye(e){return e&&"undefined"!=typeof e.getElementsByTagName&&e}for(e in d=se.support={},i=se.isXML=function(e){var t=e.namespaceURI,n=(e.ownerDocument||e).documentElement;return!Y.test(t||n&&n.nodeName||"HTML")},T=se.setDocument=function(e){var t,n,r=e?e.ownerDocument||e:p;return r!=C&&9===r.nodeType&&r.documentElement&&(a=(C=r).documentElement,E=!i(C),p!=C&&(n=C.defaultView)&&n.top!==n&&(n.addEventListener?n.addEventListener("unload",oe,!1):n.attachEvent&&n.attachEvent("onunload",oe)),d.scope=ce(function(e){return a.appendChild(e).appendChild(C.createElement("div")),"undefined"!=typeof e.querySelectorAll&&!e.querySelectorAll(":scope fieldset div").length}),d.attributes=ce(function(e){return e.className="i",!e.getAttribute("className")}),d.getElementsByTagName=ce(function(e){return e.appendChild(C.createComment("")),!e.getElementsByTagName("*").length}),d.getElementsByClassName=K.test(C.getElementsByClassName),d.getById=ce(function(e){return a.appendChild(e).id=S,!C.getElementsByName||!C.getElementsByName(S).length}),d.getById?(b.filter.ID=function(e){var t=e.replace(te,ne);return function(e){return e.getAttribute("id")===t}},b.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&E){var n=t.getElementById(e);return n?[n]:[]}}):(b.filter.ID=function(e){var n=e.replace(te,ne);return function(e){var t="undefined"!=typeof e.getAttributeNode&&e.getAttributeNode("id");return t&&t.value===n}},b.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&E){var n,r,i,o=t.getElementById(e);if(o){if((n=o.getAttributeNode("id"))&&n.value===e)return[o];i=t.getElementsByName(e),r=0;while(o=i[r++])if((n=o.getAttributeNode("id"))&&n.value===e)return[o]}return[]}}),b.find.TAG=d.getElementsByTagName?function(e,t){return"undefined"!=typeof t.getElementsByTagName?t.getElementsByTagName(e):d.qsa?t.querySelectorAll(e):void 0}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},b.find.CLASS=d.getElementsByClassName&&function(e,t){if("undefined"!=typeof t.getElementsByClassName&&E)return t.getElementsByClassName(e)},s=[],v=[],(d.qsa=K.test(C.querySelectorAll))&&(ce(function(e){var t;a.appendChild(e).innerHTML="",e.querySelectorAll("[msallowcapture^='']").length&&v.push("[*^$]="+M+"*(?:''|\"\")"),e.querySelectorAll("[selected]").length||v.push("\\["+M+"*(?:value|"+R+")"),e.querySelectorAll("[id~="+S+"-]").length||v.push("~="),(t=C.createElement("input")).setAttribute("name",""),e.appendChild(t),e.querySelectorAll("[name='']").length||v.push("\\["+M+"*name"+M+"*="+M+"*(?:''|\"\")"),e.querySelectorAll(":checked").length||v.push(":checked"),e.querySelectorAll("a#"+S+"+*").length||v.push(".#.+[+~]"),e.querySelectorAll("\\\f"),v.push("[\\r\\n\\f]")}),ce(function(e){e.innerHTML="";var t=C.createElement("input");t.setAttribute("type","hidden"),e.appendChild(t).setAttribute("name","D"),e.querySelectorAll("[name=d]").length&&v.push("name"+M+"*[*^$|!~]?="),2!==e.querySelectorAll(":enabled").length&&v.push(":enabled",":disabled"),a.appendChild(e).disabled=!0,2!==e.querySelectorAll(":disabled").length&&v.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),v.push(",.*:")})),(d.matchesSelector=K.test(c=a.matches||a.webkitMatchesSelector||a.mozMatchesSelector||a.oMatchesSelector||a.msMatchesSelector))&&ce(function(e){d.disconnectedMatch=c.call(e,"*"),c.call(e,"[s!='']:x"),s.push("!=",F)}),v=v.length&&new RegExp(v.join("|")),s=s.length&&new RegExp(s.join("|")),t=K.test(a.compareDocumentPosition),y=t||K.test(a.contains)?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},D=t?function(e,t){if(e===t)return l=!0,0;var n=!e.compareDocumentPosition-!t.compareDocumentPosition;return n||(1&(n=(e.ownerDocument||e)==(t.ownerDocument||t)?e.compareDocumentPosition(t):1)||!d.sortDetached&&t.compareDocumentPosition(e)===n?e==C||e.ownerDocument==p&&y(p,e)?-1:t==C||t.ownerDocument==p&&y(p,t)?1:u?P(u,e)-P(u,t):0:4&n?-1:1)}:function(e,t){if(e===t)return l=!0,0;var n,r=0,i=e.parentNode,o=t.parentNode,a=[e],s=[t];if(!i||!o)return e==C?-1:t==C?1:i?-1:o?1:u?P(u,e)-P(u,t):0;if(i===o)return pe(e,t);n=e;while(n=n.parentNode)a.unshift(n);n=t;while(n=n.parentNode)s.unshift(n);while(a[r]===s[r])r++;return r?pe(a[r],s[r]):a[r]==p?-1:s[r]==p?1:0}),C},se.matches=function(e,t){return se(e,null,null,t)},se.matchesSelector=function(e,t){if(T(e),d.matchesSelector&&E&&!N[t+" "]&&(!s||!s.test(t))&&(!v||!v.test(t)))try{var n=c.call(e,t);if(n||d.disconnectedMatch||e.document&&11!==e.document.nodeType)return n}catch(e){N(t,!0)}return 0":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(te,ne),e[3]=(e[3]||e[4]||e[5]||"").replace(te,ne),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||se.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&se.error(e[0]),e},PSEUDO:function(e){var t,n=!e[6]&&e[2];return G.CHILD.test(e[0])?null:(e[3]?e[2]=e[4]||e[5]||"":n&&X.test(n)&&(t=h(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(te,ne).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=m[e+" "];return t||(t=new RegExp("(^|"+M+")"+e+"("+M+"|$)"))&&m(e,function(e){return t.test("string"==typeof e.className&&e.className||"undefined"!=typeof e.getAttribute&&e.getAttribute("class")||"")})},ATTR:function(n,r,i){return function(e){var t=se.attr(e,n);return null==t?"!="===r:!r||(t+="","="===r?t===i:"!="===r?t!==i:"^="===r?i&&0===t.indexOf(i):"*="===r?i&&-1:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i;function D(e,n,r){return m(n)?S.grep(e,function(e,t){return!!n.call(e,t,e)!==r}):n.nodeType?S.grep(e,function(e){return e===n!==r}):"string"!=typeof n?S.grep(e,function(e){return-1)[^>]*|#([\w-]+))$/;(S.fn.init=function(e,t,n){var r,i;if(!e)return this;if(n=n||j,"string"==typeof e){if(!(r="<"===e[0]&&">"===e[e.length-1]&&3<=e.length?[null,e,null]:q.exec(e))||!r[1]&&t)return!t||t.jquery?(t||n).find(e):this.constructor(t).find(e);if(r[1]){if(t=t instanceof S?t[0]:t,S.merge(this,S.parseHTML(r[1],t&&t.nodeType?t.ownerDocument||t:E,!0)),N.test(r[1])&&S.isPlainObject(t))for(r in t)m(this[r])?this[r](t[r]):this.attr(r,t[r]);return this}return(i=E.getElementById(r[2]))&&(this[0]=i,this.length=1),this}return e.nodeType?(this[0]=e,this.length=1,this):m(e)?void 0!==n.ready?n.ready(e):e(S):S.makeArray(e,this)}).prototype=S.fn,j=S(E);var L=/^(?:parents|prev(?:Until|All))/,H={children:!0,contents:!0,next:!0,prev:!0};function O(e,t){while((e=e[t])&&1!==e.nodeType);return e}S.fn.extend({has:function(e){var t=S(e,this),n=t.length;return this.filter(function(){for(var e=0;e\x20\t\r\n\f]*)/i,he=/^$|^module$|\/(?:java|ecma)script/i;ce=E.createDocumentFragment().appendChild(E.createElement("div")),(fe=E.createElement("input")).setAttribute("type","radio"),fe.setAttribute("checked","checked"),fe.setAttribute("name","t"),ce.appendChild(fe),y.checkClone=ce.cloneNode(!0).cloneNode(!0).lastChild.checked,ce.innerHTML="",y.noCloneChecked=!!ce.cloneNode(!0).lastChild.defaultValue,ce.innerHTML="",y.option=!!ce.lastChild;var ge={thead:[1,"","
"],col:[2,"","
"],tr:[2,"","
"],td:[3,"","
"],_default:[0,"",""]};function ve(e,t){var n;return n="undefined"!=typeof e.getElementsByTagName?e.getElementsByTagName(t||"*"):"undefined"!=typeof e.querySelectorAll?e.querySelectorAll(t||"*"):[],void 0===t||t&&A(e,t)?S.merge([e],n):n}function ye(e,t){for(var n=0,r=e.length;n",""]);var me=/<|&#?\w+;/;function xe(e,t,n,r,i){for(var o,a,s,u,l,c,f=t.createDocumentFragment(),p=[],d=0,h=e.length;d\s*$/g;function qe(e,t){return A(e,"table")&&A(11!==t.nodeType?t:t.firstChild,"tr")&&S(e).children("tbody")[0]||e}function Le(e){return e.type=(null!==e.getAttribute("type"))+"/"+e.type,e}function He(e){return"true/"===(e.type||"").slice(0,5)?e.type=e.type.slice(5):e.removeAttribute("type"),e}function Oe(e,t){var n,r,i,o,a,s;if(1===t.nodeType){if(Y.hasData(e)&&(s=Y.get(e).events))for(i in Y.remove(t,"handle events"),s)for(n=0,r=s[i].length;n").attr(n.scriptAttrs||{}).prop({charset:n.scriptCharset,src:n.url}).on("load error",i=function(e){r.remove(),i=null,e&&t("error"===e.type?404:200,e.type)}),E.head.appendChild(r[0])},abort:function(){i&&i()}}});var Ut,Xt=[],Vt=/(=)\?(?=&|$)|\?\?/;S.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var e=Xt.pop()||S.expando+"_"+Ct.guid++;return this[e]=!0,e}}),S.ajaxPrefilter("json jsonp",function(e,t,n){var r,i,o,a=!1!==e.jsonp&&(Vt.test(e.url)?"url":"string"==typeof e.data&&0===(e.contentType||"").indexOf("application/x-www-form-urlencoded")&&Vt.test(e.data)&&"data");if(a||"jsonp"===e.dataTypes[0])return r=e.jsonpCallback=m(e.jsonpCallback)?e.jsonpCallback():e.jsonpCallback,a?e[a]=e[a].replace(Vt,"$1"+r):!1!==e.jsonp&&(e.url+=(Et.test(e.url)?"&":"?")+e.jsonp+"="+r),e.converters["script json"]=function(){return o||S.error(r+" was not called"),o[0]},e.dataTypes[0]="json",i=C[r],C[r]=function(){o=arguments},n.always(function(){void 0===i?S(C).removeProp(r):C[r]=i,e[r]&&(e.jsonpCallback=t.jsonpCallback,Xt.push(r)),o&&m(i)&&i(o[0]),o=i=void 0}),"script"}),y.createHTMLDocument=((Ut=E.implementation.createHTMLDocument("").body).innerHTML="
",2===Ut.childNodes.length),S.parseHTML=function(e,t,n){return"string"!=typeof e?[]:("boolean"==typeof t&&(n=t,t=!1),t||(y.createHTMLDocument?((r=(t=E.implementation.createHTMLDocument("")).createElement("base")).href=E.location.href,t.head.appendChild(r)):t=E),o=!n&&[],(i=N.exec(e))?[t.createElement(i[1])]:(i=xe([e],t,o),o&&o.length&&S(o).remove(),S.merge([],i.childNodes)));var r,i,o},S.fn.load=function(e,t,n){var r,i,o,a=this,s=e.indexOf(" ");return-1").append(S.parseHTML(e)).find(r):e)}).always(n&&function(e,t){a.each(function(){n.apply(this,o||[e.responseText,t,e])})}),this},S.expr.pseudos.animated=function(t){return S.grep(S.timers,function(e){return t===e.elem}).length},S.offset={setOffset:function(e,t,n){var r,i,o,a,s,u,l=S.css(e,"position"),c=S(e),f={};"static"===l&&(e.style.position="relative"),s=c.offset(),o=S.css(e,"top"),u=S.css(e,"left"),("absolute"===l||"fixed"===l)&&-1<(o+u).indexOf("auto")?(a=(r=c.position()).top,i=r.left):(a=parseFloat(o)||0,i=parseFloat(u)||0),m(t)&&(t=t.call(e,n,S.extend({},s))),null!=t.top&&(f.top=t.top-s.top+a),null!=t.left&&(f.left=t.left-s.left+i),"using"in t?t.using.call(e,f):("number"==typeof f.top&&(f.top+="px"),"number"==typeof f.left&&(f.left+="px"),c.css(f))}},S.fn.extend({offset:function(t){if(arguments.length)return void 0===t?this:this.each(function(e){S.offset.setOffset(this,t,e)});var e,n,r=this[0];return r?r.getClientRects().length?(e=r.getBoundingClientRect(),n=r.ownerDocument.defaultView,{top:e.top+n.pageYOffset,left:e.left+n.pageXOffset}):{top:0,left:0}:void 0},position:function(){if(this[0]){var e,t,n,r=this[0],i={top:0,left:0};if("fixed"===S.css(r,"position"))t=r.getBoundingClientRect();else{t=this.offset(),n=r.ownerDocument,e=r.offsetParent||n.documentElement;while(e&&(e===n.body||e===n.documentElement)&&"static"===S.css(e,"position"))e=e.parentNode;e&&e!==r&&1===e.nodeType&&((i=S(e).offset()).top+=S.css(e,"borderTopWidth",!0),i.left+=S.css(e,"borderLeftWidth",!0))}return{top:t.top-i.top-S.css(r,"marginTop",!0),left:t.left-i.left-S.css(r,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var e=this.offsetParent;while(e&&"static"===S.css(e,"position"))e=e.offsetParent;return e||re})}}),S.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(t,i){var o="pageYOffset"===i;S.fn[t]=function(e){return $(this,function(e,t,n){var r;if(x(e)?r=e:9===e.nodeType&&(r=e.defaultView),void 0===n)return r?r[i]:e[t];r?r.scrollTo(o?r.pageXOffset:n,o?n:r.pageYOffset):e[t]=n},t,e,arguments.length)}}),S.each(["top","left"],function(e,n){S.cssHooks[n]=$e(y.pixelPosition,function(e,t){if(t)return t=Be(e,n),Me.test(t)?S(e).position()[n]+"px":t})}),S.each({Height:"height",Width:"width"},function(a,s){S.each({padding:"inner"+a,content:s,"":"outer"+a},function(r,o){S.fn[o]=function(e,t){var n=arguments.length&&(r||"boolean"!=typeof e),i=r||(!0===e||!0===t?"margin":"border");return $(this,function(e,t,n){var r;return x(e)?0===o.indexOf("outer")?e["inner"+a]:e.document.documentElement["client"+a]:9===e.nodeType?(r=e.documentElement,Math.max(e.body["scroll"+a],r["scroll"+a],e.body["offset"+a],r["offset"+a],r["client"+a])):void 0===n?S.css(e,t,i):S.style(e,t,n,i)},s,n?e:void 0,n)}})}),S.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(e,t){S.fn[t]=function(e){return this.on(t,e)}}),S.fn.extend({bind:function(e,t,n){return this.on(e,null,t,n)},unbind:function(e,t){return this.off(e,null,t)},delegate:function(e,t,n,r){return this.on(t,e,n,r)},undelegate:function(e,t,n){return 1===arguments.length?this.off(e,"**"):this.off(t,e||"**",n)},hover:function(e,t){return this.mouseenter(e).mouseleave(t||e)}}),S.each("blur focus focusin focusout resize scroll click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup contextmenu".split(" "),function(e,n){S.fn[n]=function(e,t){return 0= 0) { 3 | return true; 4 | } 5 | if (url.indexOf('live.chess.com') >= 0) { 6 | return true; 7 | } 8 | return false; 9 | } 10 | 11 | function isChessGames(url) { 12 | if (url.indexOf('chessgames.com') >= 0) { 13 | return true; 14 | } 15 | return false; 16 | } 17 | 18 | function isChessDB(url) { 19 | if (url.indexOf('chess-db.com') >= 0) { 20 | return true; 21 | } 22 | return false; 23 | } 24 | 25 | function isChessTempo(url) { 26 | if (url.indexOf('chesstempo.com') >= 0) { 27 | return true; 28 | } 29 | return false; 30 | } 31 | 32 | function getGameId(url) { 33 | // chessgames.com 34 | var refIndex = url.indexOf('chessgame?gid='); 35 | if (refIndex >= 0) { 36 | return url.slice(refIndex + 'chessgame?gid='.length); 37 | } 38 | 39 | // archived chess.com game v3 40 | refIndex = url.indexOf('live/game/'); 41 | if (refIndex >= 0) { 42 | return url.slice(refIndex + 'live/game/'.length); 43 | } 44 | 45 | // daily chess.com game v3 46 | refIndex = url.indexOf('game/daily/'); 47 | if (refIndex >= 0) { 48 | return url.slice(refIndex + 'game/daily/'.length); 49 | } 50 | 51 | // chesstempo.com 52 | var refIndex = url.indexOf('chesstempo.com/gamedb/game/'); 53 | if (refIndex >= 0) { 54 | return url.slice(refIndex + 'chesstempo.com/gamedb/game/'.length).split('/')[0]; 55 | } 56 | 57 | // live chess.com game 58 | refIndex = url.indexOf('#'); 59 | var ref = refIndex >= 0 ? url.slice(refIndex + 1) : ''; 60 | if (ref.indexOf('g') == 0) { 61 | return ref.split('=')[1]; 62 | } 63 | return ''; 64 | } 65 | 66 | chrome.action.onClicked.addListener(async function(tab) { 67 | var onDone = function(pgn) { 68 | if (!pgn) 69 | return; 70 | if (tab.url.indexOf("live#a=") > -1 || 71 | tab.url.indexOf("/events/") > -1 || 72 | (pgn.indexOf('[Result ') > -1 && pgn.indexOf('[Result "*"]') < 0) || 73 | (pgn.indexOf('[Result "*"]') > -1 && pgn.indexOf(' won on time') > -1)) // chess.com oddity where games can be lost on time but Result is not updated 74 | { 75 | let tabId; 76 | chrome.tabs.create({ 77 | url: "http://" + chrome.i18n.getUILanguage().split('-')[0] + ".lichess.org/paste" 78 | }, function(tab) { 79 | tabId = tab.id; 80 | }); 81 | chrome.tabs.onUpdated.addListener(function(id, info) { 82 | setTimeout(() => { 83 | if (id == tabId && info.status == "complete" && info.status != "aborted" && pgn != null) { 84 | chrome.tabs.sendMessage(tabId, pgn); 85 | pgn = null; 86 | } 87 | }, 100); 88 | }); 89 | } else { 90 | return notFinished(tab.id); 91 | } 92 | }; 93 | if (isChessGames(tab.url)) { 94 | // chessgames.com 95 | var gameId = getGameId(tab.url); 96 | var results = await getPgn(tab.id, "chessGames", gameId); 97 | onDone(results); 98 | } else if (isChessTempo(tab.url)) { 99 | // chesstempo.com 100 | var gameId = getGameId(tab.url); 101 | var results = await getPgn(tab.id, "chessTempo", gameId); 102 | onDone(results); 103 | } else if (isChessDB(tab.url)) { 104 | // chess-db.com 105 | var results = await getPgn(tab.id, "chessDB"); 106 | onDone(results); 107 | } else { 108 | // chess.com 109 | var results = await getPgn(tab.id, "chessCom"); 110 | onDone(results); 111 | } 112 | }); 113 | 114 | async function getPgn(tabId, site, ...args) { 115 | return await chrome.tabs.sendMessage(tabId, {action: "getPgn", site, actionArgs: args}); 116 | } 117 | 118 | async function notFinished(tabId, site, ...args) 119 | { 120 | return await chrome.tabs.sendMessage(tabId, {action: "notFinished", site, actionArgs: args}); 121 | } 122 | 123 | -------------------------------------------------------------------------------- /ext/src/bg/getpgn.js: -------------------------------------------------------------------------------- 1 | pgnFuncs = { 2 | chessCom: getCurrentPgn_chessCom, 3 | chessDB: getCurrentPgn_chessDB, 4 | chessTempo: getCurrentPgn_chessTempo, 5 | chessGames: getCurrentPgn_chessGames 6 | }; 7 | 8 | chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { 9 | if (request.action === "notFinished") { 10 | popuptoast("Game is not yet finished.") 11 | .then(sendResponse); 12 | return true; 13 | } 14 | 15 | if (request.action !== "getPgn") { 16 | return false; 17 | } 18 | 19 | pgnFunc = pgnFuncs[request.site]; 20 | if (!pgnFunc) { 21 | throw new Error(`Invalid site in getPgn message data: ${request.site}`); 22 | } 23 | 24 | pgnFunc(...(request.actionArgs || [])) 25 | .then(sendResponse); 26 | 27 | return true; 28 | }); 29 | 30 | 31 | // chess.com 32 | async function getCurrentPgn_chessCom() { 33 | debuglog("getCurrentPgn_chessCom"); 34 | 35 | var pgn = await openShareDialog() 36 | .then(openPgnTab) 37 | .then(copyPgn) 38 | .finally(closeShareDialog); 39 | if (pgn) { 40 | // The termination field confuses the PDF converter so the result 41 | // is often output as a draw. This replaces the content with "Normal" 42 | // which seems to work correctly. 43 | if (pgn.indexOf(" won on time") !== -1) { 44 | pgn = pgn.replace(/Termination "([^"]+)"/g, 'Termination "Time forfeit"'); 45 | } else { 46 | pgn = pgn.replace(/Termination "([^"]+)"/g, 'Termination "Normal"'); 47 | } 48 | return Promise.resolve(pgn); 49 | } 50 | return Promise.reject(); 51 | } 52 | 53 | // chessGames.com 54 | async function getCurrentPgn_chessGames(gameId) { 55 | debuglog('getCurrentPgn_chessGames(' + gameId + ')'); 56 | var pgnUrl = 'https://www.chessgames.com/perl/nph-chesspgn?text=1&gid=' + gameId; 57 | pgn = await $.get(pgnUrl); 58 | return Promise.resolve(pgn); 59 | } 60 | 61 | // chess-db.com 62 | async function getCurrentPgn_chessDB() { 63 | var pgn = null; 64 | var pgnInput = $('input[name="pgn"]'); 65 | if (pgnInput) 66 | { 67 | pgn = pgnInput.val(); 68 | return Promise.resolve(pgn); 69 | } 70 | return Promise.reject(); 71 | } 72 | 73 | // chessTempo.com 74 | async function getCurrentPgn_chessTempo(gameId) { 75 | debuglog('getCurrentPgn_chessTempo(' + gameId + ')'); 76 | if (!gameId || gameId === '') { 77 | // if the gameId is not defined, try to get it from the link 78 | var url = $('a:contains("Link")').attr('href'); 79 | // debuglog("After url = " + url); 80 | var refIndex = url.indexOf('gamedb/game/'); 81 | if (refIndex >= 0) { 82 | gameId = url.slice(refIndex + 'gamedb/game/'.length).split('/')[0]; 83 | } 84 | debuglog("gameId = " + gameId); 85 | } 86 | 87 | var pgn = await $.ajax({ 88 | url: $('form.ct-download-pgn-form')[0].action, 89 | type: 'POST', 90 | data : 'gameids=' + gameId, 91 | async: true, 92 | success: function(data){ 93 | return Promise.resolve(data); 94 | } 95 | }); 96 | 97 | if (pgn) { 98 | return Promise.resolve(pgn); 99 | } 100 | return Promise.reject(); 101 | } 102 | 103 | async function openPgnTab() { 104 | debuglog("openPgnTab"); 105 | var pgnDiv = document.querySelector('div.share-menu-tab-selector-component > div:nth-child(1)') || 106 | document.querySelector('div.alt-share-menu-tab.alt-share-menu-tab-image-component') || 107 | document.querySelector('div.share-menu-tab.share-menu-tab-image-component'); 108 | 109 | if (pgnDiv) { 110 | return Promise.resolve(); 111 | } 112 | var pgnTab = document.querySelector("#live_ShareMenuGlobalDialogDownloadButton") || 113 | document.querySelector(".icon-font-chess.download.icon-font-primary") || 114 | document.querySelector(".icon-download"); 115 | if (!pgnTab) { 116 | var headerElements = document.querySelectorAll( 117 | ".share-menu-dialog-component header *") || document; 118 | pgnTab = Array.from(headerElements).filter( 119 | (x) => x.textContent == "PGN")[0]; 120 | } 121 | if (pgnTab) { 122 | return new Promise((resolve, reject) => { 123 | pgnTab.click(); 124 | setTimeout(resolve, 500); 125 | }); 126 | } else { 127 | return Promise.reject(); 128 | } 129 | } 130 | 131 | async function openShareDialog() { 132 | debuglog("openShareDialog"); 133 | var shareButton = 134 | document.querySelector('span.secondary-controls-icon.download') || 135 | document.querySelector('button.share-button-component.icon-share') || 136 | document.querySelector('button.share-button-component.icon-share') || 137 | document.querySelector('button.icon-font-chess.share.live-game-buttons-button') || 138 | document.querySelector('button.share-button-component.share') || 139 | document.querySelector("button[data-test='download']") || 140 | document.querySelector("#shareMenuButton") || 141 | document.querySelector(".icon-font-chess.share.icon-font-primary") || 142 | document.querySelector(".icon-font-chess.share.game-buttons-icon") || 143 | document.querySelector(".icon-font-chess.share") || 144 | document.querySelector(".icon-share"); 145 | if (shareButton) { 146 | return new Promise((resolve, reject) => { 147 | shareButton.click() 148 | setTimeout(resolve, 1000); 149 | }); 150 | } else { 151 | debuglog("failed openShareDialog"); 152 | return Promise.reject(); 153 | } 154 | } 155 | 156 | function closeShareDialog() { 157 | debuglog("closeShareDialog"); 158 | var closeButton = 159 | document.querySelector("#live_ShareMenuGlobalDialogCloseButton") || 160 | document.querySelector("button.ui_outside-close-component") || 161 | document.querySelector(".icon-font-chess.x.icon-font-primary") || 162 | document.querySelector(".icon-font-chess.x.icon-font-secondary") || 163 | document.querySelector(".icon-font-chess.x.ui_outside-close-icon") || 164 | document.querySelector("#chessboard_ShareMenuGlobalDialogCloseButton") 165 | if (closeButton) { 166 | closeButton.click(); 167 | } else 168 | { 169 | debuglog("failed closeShareDialog"); 170 | } 171 | } 172 | 173 | async function copyPgn() { 174 | debuglog("copyPgn"); 175 | 176 | //share-menu-tab-selector-tab 177 | //board-tab-item-underlined-component 178 | //board-tab-item-underlined-active 179 | //share-menu-tab-selector-tab 180 | 181 | var pgnDiv = document.querySelector('div.alt-share-menu-tab.alt-share-menu-tab-gif-component') || 182 | document.querySelector('div.alt-share-menu-tab.alt-share-menu-tab-image-component') || 183 | document.querySelector('div.share-menu-tab.share-menu-tab-gif-component') || 184 | document.querySelector('div.share-menu-tab.share-menu-tab-image-component'); 185 | 186 | if (pgnDiv) { 187 | pgnAttr = pgnDiv.attributes["pgn"] 188 | if (pgnAttr) { 189 | return Promise.resolve(pgnAttr.value); 190 | } 191 | } 192 | 193 | // PGN with embedded analysis is not parsed correctly by lichess, so disable it. 194 | // Note: both radio buttons match this selector (there's nothing unique in the markup). 195 | // We're relying on the "Annotation" button being the first one, which is what querySelector gives us. 196 | var disableAnalysisRadioButton = 197 | document.querySelector('.share-menu-tab-pgn-toggle input[type=radio]'); 198 | if (disableAnalysisRadioButton) { 199 | debuglog("found disable analysis radio button"); 200 | await new Promise((resolve, reject) => { 201 | disableAnalysisRadioButton.click(); 202 | setTimeout(resolve, 500); 203 | debuglog("analysis disabled"); 204 | }); 205 | } else { 206 | debuglog("could not find disable analysis radio button!"); 207 | } 208 | 209 | var textarea = 210 | document.querySelector("#live_ShareMenuPgnContentTextareaId") || 211 | document.querySelector("textarea[name=pgn]") || 212 | document.querySelector(".form-textarea-component.pgn-download-textarea") || 213 | document.querySelector("#chessboard_ShareMenuPgnContentTextareaId"); 214 | 215 | if (textarea) { 216 | debuglog(textarea.value); 217 | } else 218 | { 219 | debuglog("textarea failed"); 220 | Promise.reject(); 221 | } 222 | return Promise.resolve(textarea.value); 223 | } 224 | 225 | async function popuptoast(message) { 226 | var toastMessage = $(''); 227 | 228 | $(document.body).append(toastMessage); 229 | toastMessage.stop().fadeIn(400).delay(2000).fadeOut(400); //fade out after 2 seconds 230 | return Promise.resolve(); 231 | } 232 | 233 | function debuglog(message) 234 | { 235 | var logDebugMessages = false; 236 | if (logDebugMessages) { 237 | console.log(message); 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /ext/src/bg/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bg", 3 | "lockfileVersion": 2, 4 | "requires": true, 5 | "packages": { 6 | "": { 7 | "devDependencies": { 8 | "@types/chrome": "^0.0.180" 9 | } 10 | }, 11 | "node_modules/@types/chrome": { 12 | "version": "0.0.180", 13 | "resolved": "https://registry.npmjs.org/@types/chrome/-/chrome-0.0.180.tgz", 14 | "integrity": "sha512-A/CuuKAaHq2CHEpYBAtl0lp2ib7TTXK7VjJI4q+c+1U/HDvZLJ8IlsdEDzzHdvkNdh36bGONxrMnO9YZrKqbAw==", 15 | "dev": true, 16 | "dependencies": { 17 | "@types/filesystem": "*", 18 | "@types/har-format": "*" 19 | } 20 | }, 21 | "node_modules/@types/filesystem": { 22 | "version": "0.0.32", 23 | "resolved": "https://registry.npmjs.org/@types/filesystem/-/filesystem-0.0.32.tgz", 24 | "integrity": "sha512-Yuf4jR5YYMR2DVgwuCiP11s0xuVRyPKmz8vo6HBY3CGdeMj8af93CFZX+T82+VD1+UqHOxTq31lO7MI7lepBtQ==", 25 | "dev": true, 26 | "dependencies": { 27 | "@types/filewriter": "*" 28 | } 29 | }, 30 | "node_modules/@types/filewriter": { 31 | "version": "0.0.29", 32 | "resolved": "https://registry.npmjs.org/@types/filewriter/-/filewriter-0.0.29.tgz", 33 | "integrity": "sha512-BsPXH/irW0ht0Ji6iw/jJaK8Lj3FJemon2gvEqHKpCdDCeemHa+rI3WBGq5z7cDMZgoLjY40oninGxqk+8NzNQ==", 34 | "dev": true 35 | }, 36 | "node_modules/@types/har-format": { 37 | "version": "1.2.8", 38 | "resolved": "https://registry.npmjs.org/@types/har-format/-/har-format-1.2.8.tgz", 39 | "integrity": "sha512-OP6L9VuZNdskgNN3zFQQ54ceYD8OLq5IbqO4VK91ORLfOm7WdT/CiT/pHEBSQEqCInJ2y3O6iCm/zGtPElpgJQ==", 40 | "dev": true 41 | } 42 | }, 43 | "dependencies": { 44 | "@types/chrome": { 45 | "version": "0.0.180", 46 | "resolved": "https://registry.npmjs.org/@types/chrome/-/chrome-0.0.180.tgz", 47 | "integrity": "sha512-A/CuuKAaHq2CHEpYBAtl0lp2ib7TTXK7VjJI4q+c+1U/HDvZLJ8IlsdEDzzHdvkNdh36bGONxrMnO9YZrKqbAw==", 48 | "dev": true, 49 | "requires": { 50 | "@types/filesystem": "*", 51 | "@types/har-format": "*" 52 | } 53 | }, 54 | "@types/filesystem": { 55 | "version": "0.0.32", 56 | "resolved": "https://registry.npmjs.org/@types/filesystem/-/filesystem-0.0.32.tgz", 57 | "integrity": "sha512-Yuf4jR5YYMR2DVgwuCiP11s0xuVRyPKmz8vo6HBY3CGdeMj8af93CFZX+T82+VD1+UqHOxTq31lO7MI7lepBtQ==", 58 | "dev": true, 59 | "requires": { 60 | "@types/filewriter": "*" 61 | } 62 | }, 63 | "@types/filewriter": { 64 | "version": "0.0.29", 65 | "resolved": "https://registry.npmjs.org/@types/filewriter/-/filewriter-0.0.29.tgz", 66 | "integrity": "sha512-BsPXH/irW0ht0Ji6iw/jJaK8Lj3FJemon2gvEqHKpCdDCeemHa+rI3WBGq5z7cDMZgoLjY40oninGxqk+8NzNQ==", 67 | "dev": true 68 | }, 69 | "@types/har-format": { 70 | "version": "1.2.8", 71 | "resolved": "https://registry.npmjs.org/@types/har-format/-/har-format-1.2.8.tgz", 72 | "integrity": "sha512-OP6L9VuZNdskgNN3zFQQ54ceYD8OLq5IbqO4VK91ORLfOm7WdT/CiT/pHEBSQEqCInJ2y3O6iCm/zGtPElpgJQ==", 73 | "dev": true 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /ext/src/bg/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "@types/chrome": "^0.0.180" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /screenshots/chessCom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeroSharp/Chess.com_Analysis_Chrome_extension/b3e9fbc6efffaacbb3b3d8a7fa12adc6e93717ff/screenshots/chessCom.png -------------------------------------------------------------------------------- /screenshots/lichessOrg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZeroSharp/Chess.com_Analysis_Chrome_extension/b3e9fbc6efffaacbb3b3d8a7fa12adc6e93717ff/screenshots/lichessOrg.png --------------------------------------------------------------------------------