marcmagus: (regexp)
Magus ([personal profile] marcmagus) wrote2009-06-29 04:30 pm
Entry tags:

LJ New Comments working with Opera and with DreamWidth!

Thanks to a comment and link from [livejournal.com profile] pw201, the script maintainer, on my last post about the script, I've gotten the LJ New Comments GreaseMonkey script working correctly in Opera, and, further, working correctly in Opera with DreamWidth as well!

First, for full functionality in Opera using LiveJournal:

If you want to get DreamWidth working as well, you'll have to do a bit of extra work. Mair gave me the clue, that you need to get the GM emulation to set the correct domain in its cookies so the data can be retrieved again. Here are patches to both scripts to enable this. (I really need to get someplace to stick this sort of thing.)

For DreamWidth:

  • Patch Mair's patched aagmfunctions.js with my patch (below) to provide API for setting a cookie domain.
  • Patch LJ New Comments 1.3 with my patch (below) to use the domain API.
  • Turn on the hidden '&nc=xx' feature at DreamWidth by visiting http://www.dreamwidth.org/settings/?tag=comment.

Comments/suggestions welcome.

Hopefully these will work ok, but aagmfunctions.js in particular uses tabs for indentation, which could easily get lost somewhere along the way. If you have any trouble, let me know and I'll send the raw patch.

Patch for Mair's modified aagmfunctions.js

--- aagmfunctions.js    2009-06-29 16:19:09.000000000 -0400
+++ aa-gm-functions.js  2009-06-29 16:49:59.000000000 -0400
@@ -2,14 +2,17 @@
// version 1.2
// see http://www.howtocreate.co.uk/operaStuff/userJavaScript.html for details

-function GM_setValue( cookieName, cookieValue, lifeTime ) {
+function GM_setValue( cookieName, cookieValue, lifeTime, domainName ) {
    if( !cookieName ) { return; }
    if( lifeTime == "delete" ) { lifeTime = -10; } else { lifeTime = 31536000; }
+   var domainText = "";
+   if( !!domainName ) { domainText = ";domain=" + domainName; }
    document.cookie = 
-       escape( cookieName ) + "=" + 
-       escape( getRecoverableString( cookieValue ) ) +
-       ";expires=" + ( new Date( ( new Date() ).getTime() 
-                     + ( 1000 * lifeTime ) ) ).toGMTString() + ";path=/;domain=.livejournal.com";
+       escape( cookieName ) + "=" + 
+       escape( getRecoverableString( cookieValue ) ) +
+       ";expires=" + ( new Date( ( new Date() ).getTime() 
+                                   + ( 1000 * lifeTime ) ) ).toGMTString() 
+                   + ";path=/" + domainText;
}

function GM_getValue( cookieName, oDefault ) {

Patch for LJ New Comments (includes the prior modification for Opera functionality)

--- 2494.user.js    2009-06-29 16:54:16.000000000 -0400
+++ lj-new-comments.user.js 2009-06-29 17:11:01.000000000 -0400
@@ -27,6 +27,7 @@
// @include       http://*.dreamwidth.org/*
// ==/UserScript==

+(function () {
if (!GM_log || !GM_setValue || !GM_getValue)
{
    alert("LJ New Comments script requires a more recent version of Greasemonkey. Please upgrade to the latest version.");
@@ -255,9 +256,9 @@
        }
    }
    td_log("Storing " + entry_key + "'s comments in slot " + slot_index);
-    GM_setValue(site_prefix + "slot_order", slot_order.join(","));
-    GM_setValue(site_prefix + "access_order", access_order.join(","));
-    GM_setValue(site_prefix + "entry_" + slot_index, comment_list.join(","));
+    GM_setValue(site_prefix + "slot_order", slot_order.join(","),'forever', sitename);
+    GM_setValue(site_prefix + "access_order", access_order.join(","),'forever', sitename);
+    GM_setValue(site_prefix + "entry_" + slot_index, comment_list.join(","),'forever', sitename);
}

// Retrieve an array of the comment numbers we've seen for a given entry, given
@@ -283,7 +284,7 @@
            // If we found an old style key, remove the text in it, and
            // store it in our new slot arrangement, so that the seen
            // comments are not lost.
-            GM_setValue(site_prefix + entry_key,"");
+            GM_setValue(site_prefix + entry_key,"",'forever', sitename);
            store_comment_array(username, id, comment_list);
            td_log("Converted old key " + entry_key);
        }
@@ -296,7 +297,7 @@
        // friends or entry page to see whether there are new comments.
        access_order.splice(access_index,1);
        access_order.unshift(entry_key);
-        GM_setValue(site_prefix + "access_order", access_order.join(","));
+        GM_setValue(site_prefix + "access_order", access_order.join(","),'forever', sitename);
    }

    return comment_list;
@@ -635,3 +636,4 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.

+})();