Skip to main content
added 74 characters in body
Source Link
Raphael
  • 131
  • 6

This "answer" relates to version 5a which has been superseded since.

This is a minimal failing example:

// ==UserScript==
// @name           Test
// @namespace      .
// @description    Test userscript.
// @require        http://code.jquery.com/jquery-1.7.1.min.js
// @require        http://josh.gitlin.name/userscripts/ThirdPlace.js
// @include        http://chat.stackexchange.com/rooms/*
// ==/UserScript==

/*
 * Injects functions into the page so they can freely interact with existing code
 * Taken from http://stackapps.com/q/2171/10127
 */
function inject() {
  for (var i = 0; i < arguments.length; ++i) {
    if (typeof(arguments[i]) == 'function') {
      var script = document.createElement('script');
      script.type = 'text/javascript';
      script.textContent = '(' + arguments[i].toString() + ')(jQuery)';
      document.body.appendChild(script);
    }
  }
}

inject(function($) {
  alert('inject');
  ThirdPlace.observe('newMessage',function(event) {
    alert(event);
  });

  ThirdPlace.observe('editMessage',function(event) {
    alert(event);
  });
});

The alert with inject is executed (when entering chat), the others are nor (when message events happen).

This is the error I get (repeatedly) when reloading the chat and when new messages come in:

Error: console.log.apply is not a function
Source File: resource://greasemonkey/runScript.js
Line: 410

Without

// @require        http://code.jquery.com/jquery-1.7.1.min.js

I get

Error: $ is not defined
Source File: file://.../ThirdPlace.js
Line: 587

I run Firefox 10.0.1

Follow-up questions:

  • Is there an event that is triggered after entering a room when all messages have been loaded? Or is a newMessage event triggered for all shown messages?
  • Do message events contain the corresponding DOM element, i.e. the div.message or div.content nodes?

This is a minimal failing example:

// ==UserScript==
// @name           Test
// @namespace      .
// @description    Test userscript.
// @require        http://code.jquery.com/jquery-1.7.1.min.js
// @require        http://josh.gitlin.name/userscripts/ThirdPlace.js
// @include        http://chat.stackexchange.com/rooms/*
// ==/UserScript==

/*
 * Injects functions into the page so they can freely interact with existing code
 * Taken from http://stackapps.com/q/2171/10127
 */
function inject() {
  for (var i = 0; i < arguments.length; ++i) {
    if (typeof(arguments[i]) == 'function') {
      var script = document.createElement('script');
      script.type = 'text/javascript';
      script.textContent = '(' + arguments[i].toString() + ')(jQuery)';
      document.body.appendChild(script);
    }
  }
}

inject(function($) {
  alert('inject');
  ThirdPlace.observe('newMessage',function(event) {
    alert(event);
  });

  ThirdPlace.observe('editMessage',function(event) {
    alert(event);
  });
});

The alert with inject is executed (when entering chat), the others are nor (when message events happen).

This is the error I get (repeatedly) when reloading the chat and when new messages come in:

Error: console.log.apply is not a function
Source File: resource://greasemonkey/runScript.js
Line: 410

Without

// @require        http://code.jquery.com/jquery-1.7.1.min.js

I get

Error: $ is not defined
Source File: file://.../ThirdPlace.js
Line: 587

I run Firefox 10.0.1

Follow-up questions:

  • Is there an event that is triggered after entering a room when all messages have been loaded? Or is a newMessage event triggered for all shown messages?
  • Do message events contain the corresponding DOM element, i.e. the div.message or div.content nodes?

This "answer" relates to version 5a which has been superseded since.

This is a minimal failing example:

// ==UserScript==
// @name           Test
// @namespace      .
// @description    Test userscript.
// @require        http://code.jquery.com/jquery-1.7.1.min.js
// @require        http://josh.gitlin.name/userscripts/ThirdPlace.js
// @include        http://chat.stackexchange.com/rooms/*
// ==/UserScript==

/*
 * Injects functions into the page so they can freely interact with existing code
 * Taken from http://stackapps.com/q/2171/10127
 */
function inject() {
  for (var i = 0; i < arguments.length; ++i) {
    if (typeof(arguments[i]) == 'function') {
      var script = document.createElement('script');
      script.type = 'text/javascript';
      script.textContent = '(' + arguments[i].toString() + ')(jQuery)';
      document.body.appendChild(script);
    }
  }
}

inject(function($) {
  alert('inject');
  ThirdPlace.observe('newMessage',function(event) {
    alert(event);
  });

  ThirdPlace.observe('editMessage',function(event) {
    alert(event);
  });
});

The alert with inject is executed (when entering chat), the others are nor (when message events happen).

This is the error I get (repeatedly) when reloading the chat and when new messages come in:

Error: console.log.apply is not a function
Source File: resource://greasemonkey/runScript.js
Line: 410

Without

// @require        http://code.jquery.com/jquery-1.7.1.min.js

I get

Error: $ is not defined
Source File: file://.../ThirdPlace.js
Line: 587

I run Firefox 10.0.1

Follow-up questions:

  • Is there an event that is triggered after entering a room when all messages have been loaded? Or is a newMessage event triggered for all shown messages?
  • Do message events contain the corresponding DOM element, i.e. the div.message or div.content nodes?
added 295 characters in body
Source Link
Raphael
  • 131
  • 6

This is a minimal failing example:

// ==UserScript==
// @name           Test
// @namespace      .
// @description    Test userscript.
// @require        http://code.jquery.com/jquery-1.7.1.min.js
// @require        http://josh.gitlin.name/userscripts/ThirdPlace.js
// @include        http://chat.stackexchange.com/rooms/*
// ==/UserScript==

/*
 * Injects functions into the page so they can freely interact with existing code
 * Taken from http://stackapps.com/q/2171/10127
 */
function inject() {
  for (var i = 0; i < arguments.length; ++i) {
    if (typeof(arguments[i]) == 'function') {
      var script = document.createElement('script');
      script.type = 'text/javascript';
      script.textContent = '(' + arguments[i].toString() + ')(jQuery)';
      document.body.appendChild(script);
    }
  }
}

inject(function($) {
  alert('inject');
  ThirdPlace.observe('newMessage',function(event) {
    alert(event);
  });

  ThirdPlace.observe('editMessage',function(event) {
    alert(event);
  });
});

The alert with inject is executed (when entering chat), the others are nor (when message events happen).

This is the error I get (repeatedly) when reloading the chat and when new messages come in:

Error: console.log.apply is not a function
Source File: resource://greasemonkey/runScript.js
Line: 410

Without

// @require        http://code.jquery.com/jquery-1.7.1.min.js

I get

Error: $ is not defined
Source File: file://.../ThirdPlace.js
Line: 587

I run Firefox 10.0.1

Follow-up questions:

  • Is there an event that is triggered after entering a room when all messages have been loaded? Or is a newMessage event triggered for all shown messages?
  • Do message events contain the corresponding DOM element, i.e. the div.message or div.content nodes?

This is a minimal failing example:

// ==UserScript==
// @name           Test
// @namespace      .
// @description    Test userscript.
// @require        http://code.jquery.com/jquery-1.7.1.min.js
// @require        http://josh.gitlin.name/userscripts/ThirdPlace.js
// @include        http://chat.stackexchange.com/rooms/*
// ==/UserScript==

/*
 * Injects functions into the page so they can freely interact with existing code
 * Taken from http://stackapps.com/q/2171/10127
 */
function inject() {
  for (var i = 0; i < arguments.length; ++i) {
    if (typeof(arguments[i]) == 'function') {
      var script = document.createElement('script');
      script.type = 'text/javascript';
      script.textContent = '(' + arguments[i].toString() + ')(jQuery)';
      document.body.appendChild(script);
    }
  }
}

inject(function($) {
  alert('inject');
  ThirdPlace.observe('newMessage',function(event) {
    alert(event);
  });

  ThirdPlace.observe('editMessage',function(event) {
    alert(event);
  });
});

The alert with inject is executed (when entering chat), the others are nor (when message events happen).

This is the error I get (repeatedly) when reloading the chat and when new messages come in:

Error: console.log.apply is not a function
Source File: resource://greasemonkey/runScript.js
Line: 410

Without

// @require        http://code.jquery.com/jquery-1.7.1.min.js

I get

Error: $ is not defined
Source File: file://.../ThirdPlace.js
Line: 587

I run Firefox 10.0.1

This is a minimal failing example:

// ==UserScript==
// @name           Test
// @namespace      .
// @description    Test userscript.
// @require        http://code.jquery.com/jquery-1.7.1.min.js
// @require        http://josh.gitlin.name/userscripts/ThirdPlace.js
// @include        http://chat.stackexchange.com/rooms/*
// ==/UserScript==

/*
 * Injects functions into the page so they can freely interact with existing code
 * Taken from http://stackapps.com/q/2171/10127
 */
function inject() {
  for (var i = 0; i < arguments.length; ++i) {
    if (typeof(arguments[i]) == 'function') {
      var script = document.createElement('script');
      script.type = 'text/javascript';
      script.textContent = '(' + arguments[i].toString() + ')(jQuery)';
      document.body.appendChild(script);
    }
  }
}

inject(function($) {
  alert('inject');
  ThirdPlace.observe('newMessage',function(event) {
    alert(event);
  });

  ThirdPlace.observe('editMessage',function(event) {
    alert(event);
  });
});

The alert with inject is executed (when entering chat), the others are nor (when message events happen).

This is the error I get (repeatedly) when reloading the chat and when new messages come in:

Error: console.log.apply is not a function
Source File: resource://greasemonkey/runScript.js
Line: 410

Without

// @require        http://code.jquery.com/jquery-1.7.1.min.js

I get

Error: $ is not defined
Source File: file://.../ThirdPlace.js
Line: 587

I run Firefox 10.0.1

Follow-up questions:

  • Is there an event that is triggered after entering a room when all messages have been loaded? Or is a newMessage event triggered for all shown messages?
  • Do message events contain the corresponding DOM element, i.e. the div.message or div.content nodes?
Source Link
Raphael
  • 131
  • 6

This is a minimal failing example:

// ==UserScript==
// @name           Test
// @namespace      .
// @description    Test userscript.
// @require        http://code.jquery.com/jquery-1.7.1.min.js
// @require        http://josh.gitlin.name/userscripts/ThirdPlace.js
// @include        http://chat.stackexchange.com/rooms/*
// ==/UserScript==

/*
 * Injects functions into the page so they can freely interact with existing code
 * Taken from http://stackapps.com/q/2171/10127
 */
function inject() {
  for (var i = 0; i < arguments.length; ++i) {
    if (typeof(arguments[i]) == 'function') {
      var script = document.createElement('script');
      script.type = 'text/javascript';
      script.textContent = '(' + arguments[i].toString() + ')(jQuery)';
      document.body.appendChild(script);
    }
  }
}

inject(function($) {
  alert('inject');
  ThirdPlace.observe('newMessage',function(event) {
    alert(event);
  });

  ThirdPlace.observe('editMessage',function(event) {
    alert(event);
  });
});

The alert with inject is executed (when entering chat), the others are nor (when message events happen).

This is the error I get (repeatedly) when reloading the chat and when new messages come in:

Error: console.log.apply is not a function
Source File: resource://greasemonkey/runScript.js
Line: 410

Without

// @require        http://code.jquery.com/jquery-1.7.1.min.js

I get

Error: $ is not defined
Source File: file://.../ThirdPlace.js
Line: 587

I run Firefox 10.0.1