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

  • SEARCH
  • Home
  • 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 8152211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:38:45+00:00 2026-06-06T15:38:45+00:00

I am creating a userscript and in Opera it works like a charm, but

  • 0

I am creating a userscript and in Opera it works like a charm, but in Fire Fox and Chrome it gives the following error:

Error: PunishCalc is not defined

I have the variables (so users can config multiple items in the script) at the top of the script like this:

var LoginFormat     = true;
var PunishCalc      = true;
var WorldList       = true;
var aWerelden       = Array();
var TitleTickets    = true;
var OverviewLink    = true;
var CookieMarker    = true;

As you can see, PunishCalc is actually defined there.

This is the most vital part of the script: it implements jQuery on the page.

function addJQuery(callback) 
{
    var script = document.createElement("script");
    script.setAttribute("src", "http://code.jquery.com/jquery-1.7.2.min.js");
    script.addEventListener("load", function() 
    {
        var script = document.createElement("script");
        script.textContent = "(" + callback.toString() + ")();";
        document.body.appendChild(script);
    }, false);
    document.body.appendChild(script);
}

function main()
{
    // All the code will be in here
}

addJQuery(main);

That leads me to the piece of code that uses the variable:

else if(document.location.href.indexOf("village.php?mode=list") > -1 && PunishCalc === true)
{
    // Code here
}

As you can see it just checks if the variable is true or not. That’s all it has to do. Does anyone have an idea why it works in Opera but not in Chrome or Firefox?

  • 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-06-06T15:38:47+00:00Added an answer on June 6, 2026 at 3:38 pm

    The whole problem comes from how jQuery is loaded.

    We insert a <script> tag in the page and add a listener to run something when the script is loaded. The code to run is main.toString(), which is actually every statements of main, but not the actual function.

    Userscripts in Firefox and Chrome are sandboxed, the page context and the script context are completely different. So when the main.toString() statements are executed, you are not in your userscript scope anymore, but in the current page scope. That is because of the inserted <script> which executes a code in its context: the current page. There is no PunishCalc defined here as it is defined in the userscript scope.

    To bypass this restriction, put every statements in your main function.

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

Sidebar

Related Questions

Creating extensions got much easier with Vs2010, but this seems not to be the
creating users through mysql admin, but unable to login mysql command line following on-line
Creating a website using simple html(not html5) and css but got stock in mouseover
When creating iPhone apps in simulator, I sometimes see messages like Springboard failed to
Creating a calculator-like dialog, I noticed that quickly clicking on a button in IE
Creating an installer for possible remote systems so that if they do not have
Creating a table without tbody using javascript createElement/appendChild will not add tbody in Firebug
Creating a Drawable that is completely empty seems like a common need, as a
Creating the closure is easy but using it is confusing for me. Here is
Creating a C# install package and I'd like on completed install for the Program

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.