Last active
September 17, 2020 14:38
-
-
Save okj579/9324be428c2e452498e82cc3fe81be7e to your computer and use it in GitHub Desktop.
MDN I'm Feeling Lucky
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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