Stefan
Stefan

Reputation: 1

showModalDialog in Firefox

Is it possible to convert this Chrome plugin to work in Firefox?

https://github.com/chuckhendo/showModalDialog-shim

The plugin need to replace window.showModalDialog with window.open

'use strict';

var shim = '(' + function() {
if(typeof window.showModalDialog !== 'function') {
    window.showModalDialog = function() {
        var opts = arguments[2];
        opts = opts
            .replace(/;/g, ',')
            .replace(/:/g, '=')
            .replace(/dialogWidth/g, 'width')
            .replace(/dialogHeight/g, 'height')
            .replace(/center/g, 'centerScreen');
        return window.open.call(this, arguments[0], '_blank', opts );
    };
}
} + ')();';

var scriptEl = document.createElement('script');
scriptEl.textContent = shim;
(document.head||document.documentElement).appendChild(scriptEl);

Upvotes: 0

Views: 1716

Answers (1)

Ben Holmes
Ben Holmes

Reputation: 11

You can run this in GreaseMonkey. Install the GreaseMonkey extension, then add the code above as a user script.

Here it is rewritten for GreaseMoney:

// ==UserScript==
// @name        AddShowModal
// @namespace   http://www.weirdies.net
// @version     1
// @grant       none
// @include     *
// ==/UserScript==

(function () {
    var shim = '(' + function() {
    if(typeof window.showModalDialog !== 'function') {
       window.showModalDialog = function() {
        var opts = arguments[2];
        opts = opts
        .replace(/;/g, ',')
        .replace(/:/g, '=')
        .replace(/dialogWidth/g, 'width')
        .replace(/dialogHeight/g, 'height')
        .replace(/center/g, 'centerScreen');
    return window.open.call(this, arguments[0], '_blank', opts );
   };
}
} + ')();';



var scriptEl = document.createElement('script');
scriptEl.textContent = shim;
(document.head||document.documentElement).appendChild(scriptEl);
})();

I confirmed it works with OWA 10 to bring up the attach dialog etc without having to set dom.disable_window_showModalDialog to false and disable Electolysis. It seems a little clumsy, and it doesn't seem to convert the width and height properly (it opens full screen and I don't have time to debug it right now), but it works.

Upvotes: 1

Related Questions