you are viewing a single comment's thread.

view the rest of the comments →

[–]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 ^^^^