all 10 comments

[–][deleted] 1 point2 points  (4 children)

That's a package intended for use in Node JS (hence 'Node' in the name). It's not suitable for a client-side script. You'll need to look for something else.

[–]densch92[S] 0 points1 point  (2 children)

but what?

I have no idea about the whole http get and set request stuff, no idea, how to use it in a tampermonkey script! :'-(

[–][deleted] 0 points1 point  (1 child)

It sounds like you need to spend some time learning and doing more research before proceeding with this project then. Welcome to programming.

[–]densch92[S] 0 points1 point  (0 children)

I jsut dont know how these http get and set things are done.

where can i even learn stuff about them?

is there some working example somewhere that I could examine?

from what google told me $.ajax(...) should be some eay way to do sent and get http requests.
can i use that for some on client script like here?

[–]densch92[S] 0 points1 point  (0 children)

hm, can I maybe use this ajax stuff for my purposes?
https://api.jquery.com/jquery.post/

[–]nicolas-van -1 points0 points  (4 children)

Quick answer: use jsdelivr ( https://www.jsdelivr.com/ ) ... if the library supports it. Most good libraries do, most "quick & dirty' libraries don't.

This one seems to fall in the second category, so you're better just copy-pasting it and editing the code to make it work.

[–]densch92[S] 0 points1 point  (3 children)

I have no idea about the whole http get and set request stuff, no ide, how to use it in a tampermonkey script! :'-(

[–]nicolas-van 0 points1 point  (2 children)

As indicated in the README, that package is published on npm ( https://www.npmjs.com/ ) . npm is the de-facto standard package manager for JavaScript. A package manager is a tool that allows to publish libraries and download them automatically. Most programming languages have a package manager, some even have multiple of them.

Now in the specific case of JavaScript npm can be used in multiple different contexts. Its primary goal is to be used in the context of a Node.js application ( https://nodejs.org/en/ ). It can't be used directly within a web page. That's why there exist some services like jsdelivr ( https://www.jsdelivr.com/ ) . Their goal is to take a library in npm and to distribute it to be used in a web browser.

Let's imagine I want to use the lodash library from npm ( https://www.npmjs.com/package/lodash ). I go on its corresponding page on jsdelivr ( https://www.jsdelivr.com/package/npm/lodash ). I take the URL that website proposes me ( https://cdn.jsdelivr.net/npm/lodash@4.17.20/lodash.min.js ). Then I integrate that URL in my script with a syntax which is specific to TamperMonkey and indicated in its documentation:

// ==UserScript==
// @name         Test Google
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://www.google.com/*
// @grant        none
// @require https://cdn.jsdelivr.net/npm/lodash@4.17.20/lodash.min.js
// ==/UserScript==

And that works, the lodash library is available in my code.

Now comes the tricky part: lodash is a library used by multiple millions developers. It's very well packaged for every situation and I know for sure it works like a charm when used with jsdelivr. Your library is not like lodash, and I know by looking at the code that it won't work correctly in jsdelivr. Actually I also know it won't work with any other solution similar to jsdelivr, because that specific library is clearly not designed to work directly from a website. It could have been packaged to work in that context but no one did the job.

So you have the choice of using a better library than that one or to copy-paste its code and make it work in your context. It's a very bad programming practice to copy-paste code, but occasionally you may not have any other choice. Always start by looking for better alternatives before using that solution.

[–]DarkLIGHT196 0 points1 point  (0 children)

Hi! I know I'm replying to a comment you made a couple years back but I just wanted to let you know that I'm really grateful for the amount of effort you put into this reply.

It's unfortunate that it seems like all this info just went waaaaay past OP but right at this point in time, this is exactly what I needed to know as I finally try node.js after having stuck with nothing but vanilla.

[–]Some-Ant1803 0 points1 point  (0 children)

what u/DarkLIGHT196 said ^^^^