Git Product home page Git Product logo

ts-userscript-builder's Introduction

TypeScript Userscript Builder

Or, how I learned to stop Googling and take matters into my own hands

This is a template that generates a userscript from Typescript using Gulp 4. While the actual functionality of the userscript is completely up to you, this template will provide an easily customizable workflow to simplify development. Or that's the theory anyway! Gulp 4 is not currently documented and I've never developed with Typescript before (especially not within the constraints of a userscript), so piecing together something functional has not been an easy task. Please feel free to reports bugs/suggestions.

Prerequisites

Initializing your userscript

  • Clone this repository to your disk, then rename the folder to whatever your userscript will be called.
  • If you are planning to host the compiled script with the source files, remove release from .gitignore. You will also have to change the clean build step to not delete the release/ directory
  • Run npm install in this directory to download the dependencies.
  • Open metadata.txt and customize the Include URL(s) & Icon URL
    • NOTE: The script includes every page by default. This is bad. Please limit it as soon as you confirm that the generated script is valid.
  • Open package.json and customize the name through repository entries. Many of these entries will be automatically inserted into the userscript's metadata block.
    • Note: The script assumes your desired metadata namespace will be your GitHub page, and that your author entry is the same as your GitHub name. If this isn't true, you can hard-code the metadata.txt as you see fit.
  • The template requests access for GM_setValue, GM_getValue, GM_listValue, GM_deleteValue and GM_addStyle as they are commonly needed. Additionally, GM_info is included to pass down package data into the script. Add or remove permissions as needed.
  • If you need to add information to your script that changes at compile-time (like a timestamp), you can gulp-inject it in the typescript processing tasks in gulpfile.js.
    • The included timestamp function returns UTC time formatted as "Jan 1"

Developing your userscript

To start developing, simply run npm run build. Assuming everything works, this will transpile the Typescript files into a single JavaScript file (in the build/ dir) with a userscript header and inline sourcemaps. Additionally, the userscript will have _dev appended to its name, to differentiate between the developmental version and the release version.

For best results, use Violentmonkey with Google Chrome. Allow the extension to access to file URLs (found at chrome://extensions) and select "track local file" when installing the userscript. As long as you keep the tab open, any changes you save will be automatically loaded in your browser when you reload.

For continuous development, run npm run watch. This task may halt when Typescript encounters an error, but will otherwise retranspile the script every time you save. If the script is halted, close the tab and drag the userscript into the browser window again to reinstall.

When you are ready to release your script, use npm version <patch|minor|major> to increment your script. This will increment the version, output a minified JavaScript file without the _dev suffix, push the changes, and clean the project directory.

ts-userscript-builder's People

Contributors

astranomaly avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.