Use external editor to write your user scripts for Tampermonkey!

2018-11-07 | Tutorials

This tutorial will help you set up comfortable environment for developing Tampermonkey user scripts directly in your editor.

If you are reading this article, you probably already know what you are looking for and so I will cut straight to the chase. Editing Tampermonkey scripts in its built-in editor is pure pain and I am going to show you how to set it up with external editor of your choosing.

Before you start, grant Tampermonkey access to local files. It is not possible to make this work without it. Here's how you do it:

  1. Click vertical triple-dot icon to open Chrome menu.
  2. More tools > Extensions > Tampermonkey > Details
  3. Scroll down and enable Allow access to file URLs.

Note that this is not something you should be doing without thinking with other extensions. There are security reasons for this to be disabled by default.

Once this is sorted, we can proceed further:

// ==UserScript==
// @name         FirstScript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Log 'hello world' into console.
// @author       You
// @match        https://danieldusek.com/*
// @require      utils.js
// @grant        none
// ==/UserScript==
console.log('Hello world');

if (typeof logExternal === 'function') { // Function defined in utils.js
    console.log('Hello from external file.');
} else { console.log('Unable to import utils.js'); }
// ==UserScript==
// @name         FirstScript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Log 'hello world' into console.
// @author       You
// @match        https://danieldusek.com/*
// @require      file://C:\Scripts\FirstScript\main.js
// @require      file://C:\Scripts\FirstScript\utils.js
// @grant        none
// ==/UserScript==​

And you are done. Whenever you now edit and save the file in its location with the editor of your choice, the Tampermonkey extension will reflect the changes after reload.

Additional notes that may be relevant to you: