Code Kata Slug

Get the slug for a Code Kata

  1. // ==UserScript==
  2. // @name Code Kata Slug
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.1
  5. // @description Get the slug for a Code Kata
  6. // @author Andrew Lane
  7. // @match https://www.codewars.com/kata/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (async () => {
  12. const pathname = location.pathname.split('/');
  13. if (pathname[2] === 'reviews') {
  14. return;
  15. }
  16.  
  17. const res = await fetch(`https://www.codewars.com/api/v1/code-challenges/${pathname[2]}`);
  18. const json = await res.json();
  19. pathname[2] = json.slug;
  20. history.replaceState({}, '', pathname.join('/'));
  21. })();