linterna-magica-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[linterna-magica-commit] [31] Add support for split user configuration.


From: Ivaylo Valkov
Subject: [linterna-magica-commit] [31] Add support for split user configuration.
Date: Mon, 04 Apr 2011 19:46:10 +0000

Revision: 31
          
http://svn.sv.gnu.org/viewvc/?view=rev&root=linterna-magica&revision=31
Author:   valkov
Date:     2011-04-04 19:46:09 +0000 (Mon, 04 Apr 2011)
Log Message:
-----------
Add support for split user configuration. Useful on upgrade to new version. See 
tasks #11055

Ticket Links:
:-----------
    http://savannah.gnu.org/task/?11055

Modified Paths:
--------------
    trunk/src/lm_init_options.js
    trunk/src/lm_run.js

Added Paths:
-----------
    trunk/utilities/
    trunk/utilities/linterna_magica_user_config.user.js

Modified: trunk/src/lm_init_options.js
===================================================================
--- trunk/src/lm_init_options.js        2011-04-04 13:48:40 UTC (rev 30)
+++ trunk/src/lm_init_options.js        2011-04-04 19:46:09 UTC (rev 31)
@@ -37,7 +37,7 @@
        // Where to print the debugging information
        // web: Print messages in the web page (default)
        // console: Use the debugging console of the browser
-       "log_to": "console",
+       "log_to": "web",
        // Should Linterna  Mágica automatically check and notify for
        // updates.
        // <time><type>: Check at interval. (default 3w)

Modified: trunk/src/lm_run.js
===================================================================
--- trunk/src/lm_run.js 2011-04-04 13:48:40 UTC (rev 30)
+++ trunk/src/lm_run.js 2011-04-04 19:46:09 UTC (rev 31)
@@ -27,5 +27,62 @@
 
 // END OF LICENSE HEADER
 
-// Init
-var larerna_magica = new LinternaMagica(linterna_magica_options);
+// The initialisation code. This is kept outside the LinternaMagica
+// object on purpose. This function is called in setInterval for a
+// while, waiting for objects from "child" userscripts. With this code
+// the configuration options of the user and translations objects are
+// received. There is no other way for Greasemonkey (IceCat /
+// Firefox). Epiphany (and Midori) could make it without this code,
+// because the userscript is executed as if it is part of the web page
+// and there is access to the window object and everything is in
+// single scope.
+function linterna_magica_init ()
+{
+    window.linterna_magica_init_counter ++;
+
+    var ready_to_init = 0;
+
+    var data_window = null;
+
+    try
+    {
+       data_window = unsafeWindow;
+    }
+    catch(e)
+    {
+       data_window = window;
+    }
+
+    // 1.5 second with 250 ms interval.
+    if (window.linterna_magica_init_counter >= 6 ||
+       data_window.linterna_magica_user_config != undefined)
+    {
+       clearInterval(window.linterna_magica_init_timeout);
+       ready_to_init = 1;
+    }
+    
+    if (ready_to_init)
+    {
+       var config = new Object();
+
+       for (var o in linterna_magica_options)
+       {
+           // Zero migth be an option
+           if (data_window.linterna_magica_user_config[o] != undefined)
+           {
+               config[o] = data_window.linterna_magica_user_config[o];
+           }
+           else
+           {
+               config[o] = linterna_magica_options[o];
+           }
+       }
+
+       // Init
+       var larerna_magica = new LinternaMagica(config);
+    }
+}
+
+window.linterna_magica_init_counter = 0;
+window.linterna_magica_init_timeout = 
+    setInterval(linterna_magica_init, 250);

Added: trunk/utilities/linterna_magica_user_config.user.js
===================================================================
--- trunk/utilities/linterna_magica_user_config.user.js                         
(rev 0)
+++ trunk/utilities/linterna_magica_user_config.user.js 2011-04-04 19:46:09 UTC 
(rev 31)
@@ -0,0 +1,61 @@
+//  @licstart The following is the entire license notice for the
+//  JavaScript code in this page (or file).
+//
+//  This file is part of Linterna Mágica
+//
+//  Copyright (C) 2011  Ivaylo Valkov <address@hidden>
+//
+//  The JavaScript code in this page (or file) is free software: you
+//  can redistribute it and/or modify it under the terms of the GNU
+//  General Public License (GNU GPL) as published by the Free Software
+//  Foundation, either version 3 of the License, or (at your option)
+//  any later version.  The code is distributed WITHOUT ANY WARRANTY
+//  without even the implied warranty of MERCHANTABILITY or FITNESS
+//  FOR A PARTICULAR PURPOSE.  See the GNU GPL for more details.
+//
+//  As additional permission under GNU GPL version 3 section 7, you
+//  may distribute non-source (e.g., minimized or compacted) forms of
+//  that code without the copy of the GNU GPL normally required by
+//  section 4, provided you include this license notice and a URL
+//  through which recipients can access the Corresponding Source.
+//
+//  @licend The above is the entire license notice for the JavaScript
+//  code in this page (or file).
+//
+// @source http://e-valkov.org/linterna-magica
+
+// ==UserScript==
+// @name           Linterna Mágica user config
+// @namespace Linterna Mágica
+// @description  Useful if you want to keep your configuration intact when new 
version of Linterna Mágica is installed.
+// @include        http://*
+// @include        https://*
+
+// ==/UserScript==
+
+var linterna_magica_user_config = {
+    "debug": 0,
+    "log_to": "web",
+    "updates": "1w",
+    "priority": "self",
+    "autostart": "on",
+    "controls": "self",
+    "cookies": "restore",
+    "wait_dm": "off",
+};
+
+var script = document.createElement("script");
+var script_data = "window.linterna_magica_user_config = {" ; 
+for (var o in linterna_magica_user_config)
+{
+    script_data += "'"+o+ "' : '"+linterna_magica_user_config[o]+"',";
+}
+
+script_data += "};";
+
+script.textContent = script_data;
+
+var head = document.getElementsByTagName("head")[0];
+script.setAttribute("type", "text/javascript");
+head.appendChild(script);
+head.removeChild(script);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]