SharePoint maintenance mode bookmarklet

This bookmark adds the default ?maintenancemode=true query string to the current URL.

Drag this to your bookmark bar.

function updateQueryStringParameter(uri, key, value) {
  var re = new RegExp('([?&])' + key + '=.*?(&|$)', 'i');
  var separator = uri.indexOf('?') !== -1 ? '&' : '?';

  if (uri.match(re)) {
    return uri.replace(re, '$1' + key + '=' + value + '$2');
  } else {
    return uri + separator + key + '=' + value;
  }
}

const url = updateQueryStringParameter(window.location.href, 'maintenancemode', 'true');
window.location.href = url;

Related posts