How do YOU edit a UserScript?

  • Inside Browser / Tampermonkey, or whatever you are using
  • Inside Browser / GreasyFork
  • In your favorite IDE / without build steps
  • In your favorite IDE / with build steps

0 voters

I used to need a build step, requiring an NPM module, cheerio, then how do you manage it?

  • Which bundler?
  • CopyPasta?
  • Externalize from GreasyFork?
  • Minify?

I think the latter two bottoms are not allowed on GreasyFork, unless from specific CDN’s.

1 Like

None of my scripts are complicated enough to warrant an IDE or build steps, so I write them directly in Tampermonkey.

2 Likes

In TamperMonkey, I set up script header that loads the code from a local file (via @require):

// ==UserScript==
// @name        New Script Name
// @namespace   rfindley
// @description This script is in development
// @version     1.0.0
// @include     /^https://(www|preview).wanikani.com//
// @require     file:///M:\projects\my_future_script.js
// @copyright   2020+, Robin Findley
// @license     MIT; http://opensource.org/licenses/MIT
// @run-at      document-start
// @grant       none
// ==/UserScript==

This does require changing a setting in TamperMonkey to allow loading local files:
image

Then I edit the local file in my favorite editor.

I also sometimes use the browser’s JS console for testing lines of code without reloading (e.g. making sure I’ve typed a selector query correctly, etc).

5 Likes

:ballot_box_with_check: I don’t.

5 Likes
  1. I find a user script by @Kumirei that I like.
  2. I edit it right in Tampermonkey
  3. I save it.
  4. I reload Wanikani
  5. I try script.
  6. If it breaks Wanikani, I just do something else and forget I know about it.
  7. If it runs, I see what it does and edit it a few more times until it does what I like, or some other fun thing.
  8. Requires no knowledge or skill.
  9. Was used to make an Omun harassing machine.

Examples

// ==UserScript==
// @name         Wanikani Forums: 10 Characters
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Inserts invisible text into any post not meeting the 10 character requirement
// @author       Kumirei
// @include      https://community.wanikani.com/t/*
// @grant        none
// ==/UserScript==

(function() {
    let body = document.getElementsByTagName('body')[0];
    body.addEventListener('keyup', e => {
        if (e.key == "Enter" && e.ctrlKey) post("enter");
    });
    body.addEventListener('mousedown', e => {
        let parent = e.target.parentElement;
        if (parent.className == "save-or-cancel" || parent.parentElement.className == "save-or-cancel") post("mousedown");
    });

    function post(msg){
        let elem = document.getElementsByClassName('d-editor-input')[0];
        let val = elem.value;
        if (val.length < 10) {
            elem.value = val + ' <!-- all hail kumirei -->';
            if (msg == "enter") {
                elem.focus();
                elem.blur();
                elem.focus();
                document.querySelector('.submit-panel .create').click();
            }
        }
    }
})();
5 Likes

What is it?

1 Like

Does this work for you in Firefox also? Just yesterday I tried this method too, but it seems to work only in Chromium for me. Tampermonkey’s issue tracker lists a few issues with loading local files in Firefox but the situation seems to have changed multiple times and I couldn’t find a definitive answer for the current state.

Apart from that I recently started trying out to build a script with webpack and specific userscript plugin and I really like it so far. May be overhead for simple scripts but I wanted to get more familiar with webpack anyway so this was a good opportunity.

1 Like

I ended up using Rollup, because it is easiest not to minify or obfuscate, in order to comply with Greasy Fork’s term.

Or do you host it elsewhere?

I am not hosting a script anywhere yet, but preventing webpack from minifying/obfuscating the code is a one-liner in the configuration. I tried using rollup two or three times in the past but I never got it to do what I wanted, may have been project specific issues though.

I don’t know yet whether I’ll use Greasy Fork or something else to host the script but it’s good to be aware of their terms, I didn’t know that minifyed code isn’t allowed.

I develop with Chrome, and only test with Firefox.

Better script: WaniKani Forums: Bye, 10 characters, 10 characters

2 Likes