Created
December 19, 2020 04:22
-
-
Save disco0/6e5980de095a9fc5812d6f25f959f019 to your computer and use it in GitHub Desktop.
Userscript Meta TextMate Snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"Userscript Meta": | |
{ | |
"description": "Userscript meta heading", | |
"prefix": "!meta", | |
"scope": "typescript,javascript", | |
"body": | |
[ | |
"// ==UserScript==", | |
"// @name ${1}", | |
"// @author ${2}", | |
"// @description ${3}", | |
"// @version ${4:0.0.1}", | |
"// @namespace ${5}", | |
"//", | |
"// @include /${6:https?:\\/\\/}/", | |
"//", | |
"// @grant ${7:none}", | |
"//", | |
"// @require ${8}", | |
"//", | |
"// @resource ${9}", | |
// Most personal userscripts I write load through a wrapper *.user.js file, so any changes to the script content | |
// (the evaluated code, not metadata) are updated immediately. Tab stop 10 is for the wrapper script, such that: | |
// Browser -[Installs]-> `file:///.../script_name.user.js` -[@requires]-> `file:///.../script_name.js` | |
// | |
// I'm sure there's a better way to do this (it probably also works on Firefox too, lol). | |
// | |
// Expansion steps used for optional @require insertion: | |
// - Insert directory, replacing all `\` path separators with standard `/` | |
// - Additional subdirectory `js` (If you're compiling from ts, this should be "outDir") | |
// - Insert base of filename, removing `.user` part if it exists | |
// - `.js` extension | |
"${10://\n// @require file:///${TM_DIRECTORY/(?<!(?:[\\\\]{2})*[\\\\])[\\\\]/\\//g}/js/${TM_FILENAME_BASE/\\.user//}.js}", | |
"//", | |
"// ==/UserScript==", | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment