- Notifications
You must be signed in to change notification settings - Fork0
User script template that acts as module and tries to simulate imports
License
NotificationsYou must be signed in to change notification settings
JenieX/userscript-modules-template
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
User script template that acts as module and tries to simulate imports.
I built this to help me develop my user scripts, after learning aboutGrunt, and I thought I should share.
- Nodejs
- Visual Studio Code, and two extensions
- Prettier
- ESLint
- Having both
grunt-cliandeslint-cliinstalled globallynpm install grunt-cli -gnpm install eslint-cli -g
// 'package.json' - Relevant keys{"name":"userscript-modules-template","version":"0.0.1","description":"User script template that acts as module and tries to simulate imports","author":{"name":"FlowerForWar"},"devURL":"http://192.168.1.39:3905/user-script-grunt?folder=<%= pkg.name %>&_=.js","license":"MIT","userscript":{"namespace":"https://github.com/<%= pkg.author.name %>","other":{"match":"*://*/*","grant":["GM.getValue","GM_getValue","GM.setValue","GM_setValue","GM.xmlHttpRequest","GM_xmlhttpRequest","GM.setClipboard","GM_setClipboard"],"run-at":"document-start","noframes":"","compatible":["edge Tampermonkey or Violentmonkey","firefox Greasemonkey, Tampermonkey or Violentmonkey","chrome Tampermonkey or Violentmonkey","opera Tampermonkey or Violentmonkey"],"supportURL":"https://github.com/<%= pkg.author.name %>/<%= pkg.name %>/issues","homepageURL":"https://github.com/<%= pkg.author.name %>/<%= pkg.name %>","updateURL":"https://github.com/<%= pkg.author.name %>/<%= pkg.name %>/raw/main/dist/<%= pkg.name %>.meta.js","downloadURL":"https://github.com/<%= pkg.author.name %>/<%= pkg.name %>/raw/main/dist/<%= pkg.name %>.user.js","icon":"https://violentmonkey.github.io/icons/icon-48x48.png","license":"<%= pkg.license %>"}}}
Relevant files are inside thesrc folder
- src
- index.js
- js
- fancyFunction.js
- addStyle.js
- nested
- myArray.js
- more-nested
- css
- html
// 'src/index.js' - The main js file// https://github.com/FlowerForWar/userscript-modules-template/blob/main/src/index.jsimportfancyFunctionfrom'./js/fancyFunction.js';importaddStylefrom'./js/addStyle.js';fancyFunction();addStyle(`include: dist/another.css`,'userscript-modules-template-style-1');addStyle('include: dist/main.min.css','userscript-modules-template-style-2');document.body.insertAdjacentHTML('beforeend','include: dist/element.html');console.log('userscript-modules-template');
// 'dist/userscript-modules-template.user.js' - The output// https://github.com/FlowerForWar/userscript-modules-template/blob/main/dist/userscript-modules-template.user.js// ==UserScript==//@name userscript-modules-template//@version 0.0.1//@namespace https://github.com/FlowerForWar//@description User script template that acts as module and tries to simulate imports//@author FlowerForWar//@match *://*/*//@grant GM.getValue//@grant GM_getValue//@grant GM.setValue//@grant GM_setValue//@grant GM.xmlHttpRequest//@grant GM_xmlhttpRequest//@grant GM.setClipboard//@grant GM_setClipboard//@run-at document-start//@noframes//@compatible edge Tampermonkey or Violentmonkey//@compatible firefox Greasemonkey, Tampermonkey or Violentmonkey//@compatible chrome Tampermonkey or Violentmonkey//@compatible opera Tampermonkey or Violentmonkey//@supportURL https://github.com/FlowerForWar/userscript-modules-template/issues//@homepageURL https://github.com/FlowerForWar/userscript-modules-template//@updateURL https://github.com/FlowerForWar/userscript-modules-template/raw/main/dist/userscript-modules-template.meta.js//@downloadURL https://github.com/FlowerForWar/userscript-modules-template/raw/main/dist/userscript-modules-template.user.js//@icon https://violentmonkey.github.io/icons/icon-48x48.png//@license MIT// ==/UserScript==constmyString='Hello';constmyArray=[1,2,myString];functionfancyFunction(){console.log(myArray);}functionaddStyle(styleText,id){consthead=document.getElementsByTagName('head')[0]||document.documentElement;conststyle=document.createElement('style');style.setAttribute('type','text/css');style.textContent=styleText;if(id){style.setAttribute('id',id);}head.appendChild(style);returnstyle;}fancyFunction();addStyle(`.info { background: DarkGray; box-shadow: 0 0 1px rgba(169, 169, 169, 0.25); color: #fff;}.alert { background: DarkRed; box-shadow: 0 0 1px rgba(139, 0, 0, 0.25); color: #fff;}.success { background: DarkGreen; box-shadow: 0 0 1px rgba(0, 100, 0, 0.25); color: #fff;}`,'userscript-modules-template-style-1');addStyle('body{background-color:#fff}','userscript-modules-template-style-2');document.body.insertAdjacentHTML('beforeend','<ul><li>first</li><li>second</li><li>third</li></ul>');console.log('userscript-modules-template');
npm installnpm startwhich will build everything and watch
- Style files are
scss, if you don't know what that is, just use them like css files htmlandscssfiles can be nested inside their parent folders, but their names must be unique- If you don't want to use any css files or html files, keep their folders empty
userscript-modules-template.dev.jsfile will be created as well (the main reason for this project), which is basically a request to thedist/userscript-modules-template.user.jsfile that is needed to be served somehow.
About
User script template that acts as module and tries to simulate imports
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published