Skip to content

Instantly share code, notes, and snippets.

@okj579
Last active September 17, 2020 14:38
Show Gist options
  • Save okj579/9324be428c2e452498e82cc3fe81be7e to your computer and use it in GitHub Desktop.
Save okj579/9324be428c2e452498e82cc3fe81be7e to your computer and use it in GitHub Desktop.
MDN I'm Feeling Lucky
// ==UserScript==
// @name MDN I'm feeling lucky
// @author okj579
// @version 2.0.1
// @description Redirects you from the search page to the first result if it matches your query exactly (or with '..' instead of '.prototype.')
// @downloadURL https://raw.githubusercontent.com/imosnet/userscripts/master/mdn-im-feeling-lucky.user.js
// @match https://developer.mozilla.org/*/search?*
// @icon https://www.google.com/s2/favicons?domain=developer.mozilla.org
// @grant none
// ==/UserScript==
(function() {
'use strict';
if (history.state && history.state.redirected) return;
var input = document.querySelector('.search-input-field'),
result = document.querySelector('a.result-title');
if (input.value.replace('..', '.prototype.').toLowerCase() === result.innerText.replace(/\(\)$/, '').toLowerCase()) {
history.replaceState({redirected:true}, document.title, window.location);
window.open(result.href, '_self', null, false);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment