|
| 1 | +// ==UserScript== |
| 2 | +// @name rollup-userscript-template |
| 3 | +// @description Bundle typescript, react and JSX/TSX script files into a single userscript file with rollup |
| 4 | +// @namespace github.com/cvzi |
| 5 | +// @require https://unpkg.com/react@17/umd/react.development.js |
| 6 | +// @require https://unpkg.com/react-dom@17/umd/react-dom.development.js |
| 7 | +// @include https://github.com/* |
| 8 | +// @version 1.1.5 |
| 9 | +// @homepage https://github.com/cvzi/rollup-userscript-template |
| 10 | +// @author cuzi |
| 11 | +// @license MIT |
| 12 | +// @grant GM.getValue |
| 13 | +// ==/UserScript== |
| 14 | + |
| 15 | +/* |
| 16 | +MIT License |
| 17 | +
|
| 18 | +Copyright (c) 2020 cvzi |
| 19 | +
|
| 20 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 21 | +of this software and associated documentation files (the "Software"), to deal |
| 22 | +in the Software without restriction, including without limitation the rights |
| 23 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 24 | +copies of the Software, and to permit persons to whom the Software is |
| 25 | +furnished to do so, subject to the following conditions: |
| 26 | +
|
| 27 | +The above copyright notice and this permission notice shall be included in all |
| 28 | +copies or substantial portions of the Software. |
| 29 | +
|
| 30 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 31 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 32 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 33 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 34 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 35 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 36 | +SOFTWARE. |
| 37 | +*/ |
| 38 | + |
| 39 | +/* globals React, ReactDOM */ |
| 40 | +(function (ReactDOM, React$1) { |
| 41 | + 'use strict'; |
| 42 | + |
| 43 | + var helloWorld = (function () { |
| 44 | + window.setTimeout(function delayedError() { |
| 45 | + throw 'I am a delayed error'; |
| 46 | + }, 3000); |
| 47 | + return 'Plain javascript'; |
| 48 | + })(); |
| 49 | + |
| 50 | + var getSomeValueFromGM = (function () { |
| 51 | + return () => GM.getValue('test', 'a default value'); |
| 52 | + })(); |
| 53 | + |
| 54 | + class SomeList extends React$1.Component { |
| 55 | + constructor(props) { |
| 56 | + super(props); |
| 57 | + } |
| 58 | + render() { |
| 59 | + return (React$1.createElement("div", { className: "some-list" }, |
| 60 | + React$1.createElement("h1", null, |
| 61 | + "This is a list for ", |
| 62 | + this.props.name), |
| 63 | + React$1.createElement("ul", null, |
| 64 | + React$1.createElement("li", null, "plain javascript"), |
| 65 | + React$1.createElement("li", null, "typescript"), |
| 66 | + React$1.createElement("li", null, "react"), |
| 67 | + React$1.createElement("li", null, "JSX/TSX")))); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + ReactDOM.render( /*#__PURE__*/React.createElement(SomeList, { |
| 72 | + name: helloWorld |
| 73 | + }), document.body); |
| 74 | + getSomeValueFromGM().then(function (s) { |
| 75 | + ReactDOM.render( /*#__PURE__*/React.createElement(SomeList, { |
| 76 | + name: s |
| 77 | + }), document.body); |
| 78 | + }); |
| 79 | + |
| 80 | +}(ReactDOM, React)); |
0 commit comments