AutoLoggingPane?.user.js

This script runs for every page. If the page is using MochiKit.LoggingPane?, this script will hijack MochiKit.LoggingPane?.LoggingPane?() so it can keep track of all the logging panes that have been opened. If it detects that a logging pane is already open for the current URL, then it will connect the page to that pane.

The upshot of all that is that this script will keep your popup-window logging panes connected to the page even after reloading the page, or navigating away and returning to the page.

// ==UserScript==
// @name            Auto LoggingPane
// @description     Automatically connects to an open MochiKit.LoggingPane window for the default logger if the current page uses MochiKit.LoggingPane.
// @include         *
// ==/UserScript==

(function(){

    if(typeof(MochiKit) != "undefined" && typeof(MochiKit.LoggingPane) != "undefined") {
        // Find the base url of this page
        var url = location.href.split("?")[0];

        // Keep track of the original LoggingPane constructor
        _GM_LoggingPane = MochiKit.LoggingPane.LoggingPane;
        
        // Build a replacement constructor to keep track of created logging panes
        var rememberLoggingPane = function(inline, logger) {
            var pane = new _GM_LoggingPane(inline, logger);
            if(inline || !pane.win)
                return pane;

            // Remember this logging pane url
            var panes = GM_getValue("GM.AutoLoggingPane.panes", "");
            if(panes.indexOf(" " + url + " ") == -1) {
                panes += " " + url + " ";
                GM_setValue("GM.AutoLoggingPane.panes", panes);
                
                // Add an onunload handler to remove its name from the list also
                var forgetLoggingPane = function() {
                    var panes = GM_getValue("GM.AutoLoggingPane.panes", null);
                    panes = panes.replace(" " + url + " ", "");
                    GM_setValue("GM.AutoLoggingPane.panes", panes);
                };
                pane.win.addEventListener("unload", forgetLoggingPane, true);
            }            
            return pane;
        };

        // Hijack the LoggingPane constructor        
        MochiKit.LoggingPane.LoggingPane = rememberLoggingPane;
        if(typeof(LoggingPane) != "undefined")
            LoggingPane = rememberLoggingPane;
    
        // Now connect to any open loggingPane for this page
        var panes = GM_getValue("GM.AutoLoggingPane.panes", "");
        if(panes.indexOf(" " + url + " ") != -1) {

            var pane = MochiKit.LoggingPane.createLoggingPane();
            pane.logger.log("--- Refreshed " + url + " ---");
        }
    }
        
})();