empty2332 / Wikiwand redirect for Wikipedia

// ==UserScript==
// @name         Wikiwand redirect for Wikipedia
// @include      http://www.google.*
// @include      https://www.google.*
// @version      0.1
// @description  Wikiwand redirect for Wikipedia
// @author       empty
// @grant        none
// @copyright 2019, empty2332 (https://openuserjs.org/users/empty2332)
// @license MIT
// ==/UserScript==

window.addEventListener('mousedown', event => {
  const a = event.target.closest('a');
  if (a) {

    a.onmousedown = null;
    var wikiLocale = new RegExp('\/\/(.*).wikipedia');
    var keyword = new RegExp('([^\/]+$)');
    var url = a.href;

    if (wikiLocale.test(url)) {

      var localeArray = url.match(wikiLocale);
      var keywordArray = url.match(keyword);
      var newHref = 'https://www.wikiwand.com/' + localeArray[1] + '/' + keywordArray[0]
      a.href = newHref;

    }
  }
}, true);