You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/posts/how-to-edit-scripts-with-your-favorite-editor/index.md
+12-15Lines changed: 12 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,40 +36,37 @@ Install a local script
36
36
37
37
First make sure the local script is named with a suffix of `.user.js`.
38
38
39
-
There are two ways to install a local script:
39
+
Then use one of these methods:
40
40
41
-
-*Easy way:* drag the file into the browser.
41
+
-Drag the file into any Violentmonkey tab or popup.
42
42
43
-
It will be recognized by Violentmonkey and loaded in the confirmation page.
43
+
Requires Chrome/Chromium 86+ and Violentmonkey 2.16+.
44
44
45
-
Make sure *"Allow access to file URLs"* is checked in your *Chrome extension settings* (`chrome://extensions`).
45
+
- Drag the file into the browser toolbar or tab label area.
46
46
47
-

47
+
* In Chrome-like browsers you must enable *"Allow access to file URLs"* in Violentmonkey's details in `chrome://extensions` page first. Since this is dangerous (any userscript will be able to read any local file via GM_xmlhttpRequest), you may want to use the other methods instead.
48
48
49
-
**Note** that due to a [known issue](#known-issues), the *easy way***won't work for Firefox users**.
49
+
* In modern Firefox-like browsers don't close the file tab while tracking as it's used to read the contents of the file.
50
50
51
-
-*Hard way:* start a local HTTP server, then open the local script with a URL like`http://localhost:8080/my-script.user.js`.
51
+
-Set up a server and navigate to`http://localhost:8080/my-script.user.js`.
52
52
53
-
One of the best way is to use node/npm's [indexzero/http-server](https://github.com/indexzero/http-server#readme). If you have it installed, just type `http-server -c5` at the directory of your script to start a server.
53
+
The port number `:8080` may be different or even omitted depending on the server you installed.
54
54
55
-
Make sure the hostname is `localhost` and the script name ends with `.user.js`.
55
+
We recommend [indexzero/http-server](https://github.com/indexzero/http-server#readme). Once you install it, just type `http-server -c5` at the directory of your script to start a server. The `-c5` option sets cache time for max-age header to 5 seconds ([more info](https://github.com/violentmonkey/violentmonkey/issues/460#issuecomment-434335758)), thus forcing a browser to query the server URL every 5 seconds. The caching can be disabled with `-c-1` option.
56
56
57
-
**Note** that due to a [known issue](https://github.com/violentmonkey/violentmonkey/issues/460#issuecomment-434335758), the *hard way* needs to handle caching. In `http-server -c5` option `-c5` sets cache time for max-age header to 5 seconds, thus forcing a browser to query the server URL every 5 seconds. The caching can be disabled with `-c-1` option.
57
+
Make sure the hostname is `localhost` and the script name ends with `.user.js`.
58
58
59
59

60
60
61
-
Make sure the `track local file` option is checked and then confirm installation.
62
-
63
-

61
+
Click `Track external edits` button to confirm installation. You can also make it the default button for local files by ticking the checkbox on the right.
64
62
65
63
Edit and sync
66
64
---
67
65
68
66
After installation, the confirmation page will keep watching the file before the page is closed. Once the file is changed, the new version will be installed automatically. As a result, you edit the script in your favorite editor, and the changes are synced to Violentmonkey immediately.
69
67
70
-

68
+

71
69
72
70
Known issues
73
71
---
74
-
- In Firefox Violentmonkey is not allowed to access local files, so we have to start a local HTTP server for tracking. See [this on bugzilla](https://bugzilla.mozilla.org/show_bug.cgi?id=1266960).
75
72
- The older the file is, the more seldom a browser will query it. See [this Violentmonkey's issue](https://github.com/violentmonkey/violentmonkey/issues/460#issuecomment-434335758).
0 commit comments