Incorporating fresh Javascript code at the bottom of the webpage with Greasemonkey or Tampermonkey

I've been working on a simple script using Tampermonkey that displays information about people connected to my teamspeak server.

Here is the code I have:

window.addEventListener('load',function() { $("body").append ( ' [SOME JAVASCRIPT CODE]' ); },
true);

However, for some reason it's not functioning as expected. If I change the code to normal HTML text, it works without any errors.

The javascript code is working fine when used separately. Here is an example of the code:

<script type="text/javascript">
<!--
var ouvert = 1;
var style = "classic";
var couleur_fond = "FFFFFF";
var couleur_texte = "666666";
var largeur = 390;
var hauteur = 350;
var ip = "aphrodite.ts3-serveur.com";
var port = 13500;
var query = 62101;
var lang = "en";
var taille_police = 12;
var voir_salons = 1;
//-->
</script>
<script type="text/javascript" src="http://www.ts3-serveur.com/web_script/webscript_ts3.js"></script>

Any suggestions on why it's not working?

Answer №1

If you're experiencing issues with the current Tampermonkey version where the "load" callback is not being fired, there is a workaround available. You can either wait for the next beta version by visiting this link or use "DOMContentLoaded" as an alternative solution.

Please remember to include the following line in the script header:

// @run-at         document-start

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

problem with concealed picture when hovering cursor

While I know this issue has been discussed before, I am facing a slight confusion regarding displaying an image on MouseOver. Currently, I have a div container with a colored background that shows when hovered over. You can see an example of this here - sc ...

Verify the position of the scrollbar without triggering any reflow

Here is a function I have: is_bottom: function() { if (settings.scrollBottomOffset === -1) { return false; } else { var scroll_height, scroll_top, height; scroll_height = ...

Show a variety of randomly selected pictures from various sources using the command image/next

I'm in the process of building a basic news aggregation website using Next.js. I’ve run into an issue where I need to include specific domains in my next.config file for the Image component to work properly. The problem is, the URLs for the images o ...

Hide the selection box when hovering over the Div

Looking for a quick solution. I want the option drop down to close when another div element is hovered over. First, open the drop down and hover over the red element on the right side. When hovering over the red element, I would like the drop down to clos ...

How come I'm not receiving an error message when I enter an incorrect email or password?

Whenever I try to log in with the wrong password and email, no error message is displayed. Instead, it simply logs me in and takes me to the main page. Can someone please assist me in implementing an error message display for incorrect login details? imp ...

React JS: Autocomplete with multiple options available

I currently have the following state: const[values,setValues]=useState<IValue[]>([]); const[value,setValue]=useState<IValue|null>(); <Autocomplete options={values} value={value} id="value_id" getOptionLabel={(option:IValue)=& ...

Understanding Java and JavaScript variables within a JSP webpage

I am currently working on populating a pie chart from Google with data fetched from my database. Although I have successfully retrieved the desired results in my result set, I am facing challenges in converting my Java variables into JavaScript variables ...

Ways to include external JavaScript in an HTML document along with CSS styling

Check out this code snippet in HTML with embedded JavaScript. I'm trying to externalize the JS file, but it's not functioning as expected when I do so. How can I resolve this issue and ensure that the element moves upon clicking when the script i ...

Real-time JSON Data Retrieval Using Ajax jQuery and Google Sheet API

Seeking a live data search tool that works with JSON spreadsheets Check out this link for more information name = data.feed.entry[i]['gsx$name']['$t']; img = data.feed.entry[i]['gsx$img']['$t']; price ...

How can JavaScript be used to prevent pinch and zoom functionality on Google Maps?

In my project, I am utilizing Google Maps but I want to disable the zooming effect on the map. To achieve this, I have disabled the zoom control using zoomControl: false,. However, this modification only applies to desktops and laptops as they do not suppo ...

Overriding model methods in SailsJS

As I integrate caching (redis) into my project, my preference is to incorporate it into the model logic rather than the controller. This would involve overwriting the model method and including the caching logic within that. I am aware that certain method ...

Papaparse seems to be having trouble parsing all of the data

Currently, I am working on a React application that is responsible for fetching and displaying CSV file data from the public folder. Below is a snippet of my React container: import React, { Component } from 'react' import * as Chart from "char ...

Bootstrap: The search icon button within the input box breaks away from the input box on resolutions other than desktop

I am attempting to place a Search Icon Button inside the Search Input Box while using Bootstrap. Although everything appears correctly at Desktop resolution, at non-desktop resolutions when the menu items collapse into a dropdown, the button and input box ...

In JavaScript, eliminate all characters in a string after the second hyphen using only one line of code

Is it possible to extract the language from a string before the 2nd occurrence of a dash (-) using a single line of Javascript? For example: en-AU-Option-A would become en-AU ...

What is the best way to transmit a string as POST data from another webpage?

In the index.php file, there is a search page with an input box. The form on this page uses the POST method. <form id="someID" action="result.php" method="post"> <input name="name" id="name" type="text"> <input type="submit" value=" ...

Having trouble locating the name 'div' when starting a new React project?

After creating a new React application using the command: "npx create-react-app poi-search --template typescript", ESLint prompted me for permission and then displayed several errors. You can view the screenshot here. I am currently using the latest versi ...

Refreshing my perspective with AngularJS

I am currently trying to modify the following code snippet: <p>You have <span ng-model="char-count">{{255 - (name.length + email.length + textarea.length)}}</span> characters left</p> It seems like wrapping 255 - name.length + ema ...

Vue triggering axios on every dropdown selection made

I have a Vue template that currently calls a method (axios call) upon page load, which works well. However, I would like to modify it so that whenever I select an option from the dropdown menu, it will re-call the axios method with the selected option. S ...

Is there a way to execute code before a user navigates away from the page?

Every attempt I've made has failed. I am trying to execute some code before the user exits the page: window.onbeforeunload = function(){ alert(1); } window.addEventListener("beforeunload", function(e){ alert(2); }); window.addEve ...

Using Vue.js and JavaScript to access a single variable across multiple class methods

I am working on organizing my custom channel logic into its own class. During the created lifecycle method, I am executing each method in the class I created. However, I am facing a challenge in retaining the instance of the socket that was created in the ...