Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should add User Documentation #72

Open
LukeSavefrogs opened this issue Apr 21, 2022 · 2 comments
Open

Should add User Documentation #72

LukeSavefrogs opened this issue Apr 21, 2022 · 2 comments

Comments

@LukeSavefrogs
Copy link

I find this project very interesting. 🥇

I find it very hard to start using it though, because of the lack of user documentation.
I have questions like:

  1. What is the entry point of the script (so the file i should start editing to get started)?
  2. Where should i place my personal code?
  3. What are all those extra files like ./src/operations.ts, ./src/site.ts, etc.? What should i do with them? And how can i use them to customize the experience?

I could help setting up the Documentation if you want, but i need help understanding the base structure first.

Going through the examples you linked didn't help, unfortunately 😕

@SimonAlling
Copy link
Owner

Thanks for submitting this issue – I agree that the documentation is indeed subpar. I'll try to answer your questions, for starters.

  1. What is the entry point of the script (so the file i should start editing to get started)?

I think this is the best way to start building a userscript:

$ npm install --global userscripter
$ mkdir my-userscript
$ cd my-userscript
$ userscripter init
$ npm install
$ echo "node_modules/" > .gitignore # due to an issue solved in #67 but not published atm
$ git init
$ git add .
$ git commit -m "Initial commit"

At this point, you most likely want to start editing src/userscript.ts, src/operations.ts, and/or src/stylesheets.ts (see Example Userscript for inspiration). The entry point of the userscript itself is src/main.ts, but I typically don't edit it much.

  1. Where should i place my personal code?

Short answer: Anywhere in src/. 🙂

Long answer: The files created by userscripter init are just a suggestion; you can use any structure you want for your business code. The key is the userscripter.run call in the entry module, which is src/main.ts by default. The argument to userscripter.run can be constructed in any way you like – Userscripter imposes no restrictions on the contents of src/, except that it uses main.ts as the entry point for the userscript by default.

For small userscripts, I typically write my operations "inline" in src/operations.ts and my styles in src/stylesheets.ts. For large userscripts, I write them in separate files and import them in said files.

  1. What are all those extra files like ./src/operations.ts, ./src/site.ts, etc.? What should i do with them? And how can i use them to customize the experience?

They're part of a boilerplate structure that I've used throughout my userscripts:

File name Purpose
main.ts Webpack entry point
userscript.ts Userscript metadata
operations.ts Operations performed by userscript (modifying the DOM etc)
stylesheets.ts Styles inserted by userscript
config.ts Constants chosen at will by the userscript author
site.ts Constants that have to match the host site in some way
preferences.ts User-facing preferences (for more complex userscripts)

You don't have to use that structure if you don't want to. As long as you keep main.ts and the userscripter.run call in it, you can use any structure you want. 🙂

💡 Writing this comment gave me an idea: userscripter init could perhaps offer a choice between a "simple" userscript, with everything required to get started in a single file (src/main.ts), and a "complex" one, which could be the same as today.

@LukeSavefrogs
Copy link
Author

Thanks for taking your time to write this introduction! It really helped me understand the basics of how it works!

In my opinion, the table you wrote should be in the README.md since it's so useful...

💡 Writing this comment gave me an idea: userscripter init could perhaps offer a choice between a "simple" userscript, with everything required to get started in a single file (src/main.ts), and a "complex" one, which could be the same as today.

This would be a great idea, it would help a lot to build just what you want and it would simplify the learning curve😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants