Add a "Save and Edit" button to the mini panels edit page on every site

Here's a Tampermonkey script which adds a Save and Edit button to the mini panels content edit page for every site :) If you don't have the button, then every time you save, you are brought back to the mini-panels content overview page, which gets kind of long.
// ==UserScript==
// @name       minipanel saveedit
// @version    0.1
// @description  adds save and edit button to mini panel content wizard form
// @include      *admin/structure/mini-panels/list/home_featured/edit/content*
// @require http://code.jquery.com/jquery-latest.js
// @copyright  2014+, Jeff 
// ==/UserScript==
$(document).ready(function() {
 
  var pathname = window.location.pathname;
  while (pathname.charAt(0) === '/') {
    pathname = pathname.substr(1);
  }
 
  $('#edit-buttons' + ':not(.processed)')
      .addClass('processed')
      .append('<input type="button" id="saveedit" value="Save and Edit" class="btn">');
  $(document).on('click', '#saveedit', function() {
    var $form = $('#ctools-export-ui-edit-item-wizard-form');
    var action = $form.attr('action');
    var getQueryVariable = function(variable) {
      var query = window.location.search.substring(1);
      var vars = query.split("&");
      for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == +variable) {
          return pair[1];
        }
      }
      return(false);
    };
    var destination = getQueryVariable('destination');
    if (destination === false) {
      var newdest = action + '?destination=' + pathname;
      $form.attr('action', newdest);
    }
 
    $('#edit-return').trigger('click');
 
  });
 
});

Tags

Internal References

Article Type

General