Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7017767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:57:27+00:00 2026-05-27T22:57:27+00:00

I’ve created a GreaseMonkey script based on an in-page script that I’d like to

  • 0

I’ve created a GreaseMonkey script based on an in-page script that I’d like to use on a site, however I’m having the following issue:

In the script, we’ve created our namespace (brickJax) that contains the bulk of the functions, and I’ve required jQuery as we’re using the jQuery replaceText functions as well.

When I call the replaceText function from replaceSet I get the following error on the console:

uncaught exception: TypeError: $(node).replaceText is not a function

However, calling it as part of the GM_xmlhttpRequest onload callback works fine.

var brickJax = (function ($) {
  "use strict";
  var brickJax = {};

  //[Code here]

  function replaceSet(node, str, number, colour) {
    var text = '<a href="http://www.peeron.com/inv/sets/' + number + '-1">'
               + number + ' on Peeron</a>';

    // THIS LINE THROWS THE ERROR:
    $(node).replaceText(str, text);
  }

  function replaceImage(node, str, number, colour) {
    getBricksForImage(number, colour, node, str);
  }

  function getBricksForImage(number, colour, node, str) {
    GM_xmlhttpRequest({
        method: "POST",
        url: "http://brickjax.doodle.co.uk/bricks.aspx/JsonDetails/" + number 
             + "/" + colour,
        dataType: "jsonp",
        onload: function (data) {
            // THIS CALL WORKS PERFECTLY
            $(node).replaceText(str,
                                buildImage($.parseJSON(data.responseText)));
        }
    });
  };

  function buildImage(ajaxData) {
    var text = '<img style="max-height:100px;" src="' + ajaxData.Src 
               + '" alt="' + ajaxData.AltText + '" />';

    return text;
  }

  function replaceTags(element) {
    var elements = $(element).find('*').andSelf();
    elements = elements.not($('script,noscript,style,textarea,pre,code')
                       .find('*').andSelf());

    searchText(elements, /\[part:([\w\-]*)(?::([\w\-]*))?\]/gi, replaceImage);

    searchText(elements, /\[set:([\w\-]*)(?::([\w\-]*))?\]/gi, replaceSet);
  };

})(jQuery);

brickJax.replaceTags($('body'));

(function ($) { $.fn.replaceText = function (b, a, c) { [...] } })(jQuery);

In the actual script I’ve added logging, which shows that node is an HTML element in both cases.

What is it that I’m doing wrong in the call from replaceSet that is different from the call in callback that’s causing this error?

In the hosted version both calls work as expected.

Apologies for the wall of script, I’ve tried to cut it down to the bare essentials.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:57:28+00:00Added an answer on May 27, 2026 at 10:57 pm

    This is either closure related or due to the function being defined in an expression versus a declaration.

    Either way, the solution should be the same, move the definition of replaceText physically before the var brickJax = ... stuff.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.