0

It works as expected - the desired functionality is to be able to invoke bang!'s more easily using the semi-colon key. However for some reason it also causes a perpetual refresh for URLs that contain a colon (for which it should actually do nothing).

Here's the code:

// ==UserScript==
// @name           DDG Semicolon Bangs
// @include        https://duckduckgo.com/?q*
// ==/UserScript==

    window.location.href = window.location.href.replace(/%3B/, '%21');

// End of script

Example test pages: https://duckduckgo.com/?q=w%3A+greasemonkey (why is this perpetually refreshing??!!?!?! garrrr!) and https://duckduckgo.com/?q=w%3B+greasemonkey (works as expected - hooray!)

1 Answers1

4

Don't count on the (browser-specific, nonstandard) thing that happens when you set the window location to the current location. Check whether the location matches your regex before replacing it. And use location.replace, to avoid setting an entry in your browser history.

var re = /%3B/g;
if (re.test(window.location.href)) {
    window.location.replace(window.location.href.replace(re,'%21'));
}
zetlen
  • 3,609
  • 25
  • 22