Lichess Display Country Flag

Display username + rating + country flag in game ( if user registered his country in 'bio')

// ==UserScript==
// @name        Lichess Display Country Flag
// @namespace   http://example.com
// @description Display username + rating + country flag in game ( if user registered his country in 'bio')
// @include     https://lichess.org/*
// @version     2
// @grant       none
// @run-at      document-idle
// ==/UserScript==

setTimeout(function(){
 var $ = window.jQuery;

  var utop = window.document.getElementsByClassName('ruser-top')[0].innerText.split('\n')[0]
if(utop.indexOf(' ') > -1){utop = utop.substring(3);}
var url = 'https://lichess.org/api/user/'+utop;
var xhr = new XMLHttpRequest();
xhr.open("GET", url);

xhr.onreadystatechange = function () {
   if (xhr.readyState === 4) {
       var newsArr = JSON.parse(xhr.responseText);
       console.log(newsArr.profile.country);
	  if(xhr.responseText.indexOf('country') > -1){
	  var urlflag = 'https://lichess1.org/assets/_1FzRvx/images/flags/'+newsArr.profile.country+'.png'
	  var im = new Image (20,20);
	  im.src = urlflag;
	  document.getElementsByTagName('rating')[0].after(im);
      im.style.marginLeft = '10px';}
   }};

xhr.send();

var ubottom = window.document.getElementsByClassName('ruser-bottom')[0].innerText.split('\n')[0]
if(ubottom.indexOf(' ') > -1){ubottom = ubottom.substring(3);}
var url = 'https://lichess.org/api/user/'+ubottom;
var xhr2 = new XMLHttpRequest();
xhr2.open("GET", url);

xhr2.onreadystatechange = function () {
   if (xhr2.readyState === 4) {
      var newsArr2 = JSON.parse(xhr2.responseText);
	  if(xhr2.responseText.indexOf('country') > -1){
	  var urlflag = 'https://lichess1.org/assets/_1FzRvx/images/flags/'+newsArr2.profile.country+'.png'
	  var im = new Image (20,20);
	  im.src = urlflag;
	  document.getElementsByTagName('rating')[1].after(im);
      im.style.marginLeft = '10px';
	  }
   }};

xhr2.send() }, 100);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址