├── .github └── dependabot.yml ├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── bin ├── balls.sh ├── index.cjs ├── index.d.ts └── start.sh ├── docs ├── configuration │ ├── bare.md │ ├── encoding.md │ ├── logging.md │ └── modes.md └── examples │ └── uv-dynamic-multi │ ├── dynamic │ ├── dynamic.client.js │ ├── dynamic.client.js.map │ ├── dynamic.config.js │ ├── dynamic.handler.js │ ├── dynamic.handler.js.map │ ├── dynamic.html.js │ ├── dynamic.html.js.map │ ├── dynamic.worker.js │ └── dynamic.worker.js.map │ ├── index.html │ ├── resources │ ├── img │ │ └── logo.png │ ├── scripts │ │ ├── backdrop.js │ │ ├── index.js │ │ └── notice.js │ └── style.css │ ├── sw.js │ └── uv │ ├── uv.bundle.js │ ├── uv.bundle.js.LICENSE.txt │ ├── uv.bundle.js.map │ ├── uv.client.js │ ├── uv.client.js.map │ ├── uv.config.js │ ├── uv.handler.js │ ├── uv.handler.js.map │ ├── uv.sw.js │ └── uv.sw.js.map ├── esbuild.dev.js ├── esbuild.prod.js ├── fortnite ├── index.js ├── lib ├── client │ ├── client.ts │ └── index.ts ├── dynamic.config.js ├── global │ ├── bundle.ts │ ├── client.ts │ ├── client │ │ ├── index.ts │ │ ├── methods.ts │ │ └── methods │ │ │ ├── core │ │ │ ├── eval.ts │ │ │ ├── function.ts │ │ │ ├── get.ts │ │ │ ├── html.ts │ │ │ ├── location.ts │ │ │ ├── protocol.ts │ │ │ ├── reflect.ts │ │ │ └── window.ts │ │ │ ├── document │ │ │ ├── attr.ts │ │ │ ├── cookie.ts │ │ │ ├── mutation.ts │ │ │ ├── style.ts │ │ │ └── write.ts │ │ │ ├── init.ts │ │ │ ├── window │ │ │ ├── blob.ts │ │ │ ├── fetch.ts │ │ │ ├── history.ts │ │ │ ├── imports.ts │ │ │ ├── message.ts │ │ │ ├── navigator.ts │ │ │ ├── niche.ts │ │ │ ├── policy.ts │ │ │ ├── rtc.ts │ │ │ ├── storage.ts │ │ │ ├── worker.ts │ │ │ └── ws.ts │ │ │ └── wrap.ts │ ├── codec.ts │ ├── cookie │ │ ├── db.ts │ │ ├── index.ts │ │ └── parse.ts │ ├── headers.ts │ ├── http.ts │ ├── http │ │ ├── request.ts │ │ └── response.ts │ ├── is │ │ ├── css.ts │ │ ├── html.ts │ │ └── js.ts │ ├── istype.ts │ ├── meta.ts │ ├── meta │ │ ├── load.ts │ │ └── type.ts │ ├── middleware.ts │ ├── modules.ts │ ├── regex.ts │ ├── rewrite.ts │ ├── rewrite │ │ ├── css.ts │ │ ├── html │ │ │ ├── generateHead.ts │ │ │ ├── html.ts │ │ │ ├── nodewrapper.ts │ │ │ └── srcset.ts │ │ ├── js │ │ │ ├── emit.ts │ │ │ ├── iterate.ts │ │ │ ├── js.ts │ │ │ ├── object │ │ │ │ ├── Eval.ts │ │ │ │ └── PostMessage.ts │ │ │ ├── process.ts │ │ │ ├── type │ │ │ │ ├── AssignmentExpression.ts │ │ │ │ ├── CallExpression.ts │ │ │ │ ├── Identifier.ts │ │ │ │ ├── Imports.ts │ │ │ │ ├── Literal.ts │ │ │ │ ├── MemberExpression.ts │ │ │ │ ├── Property.ts │ │ │ │ ├── ThisExpression.ts │ │ │ │ └── VariableDeclaractor.ts │ │ │ └── types.ts │ │ └── manifest.ts │ ├── url.ts │ ├── url │ │ ├── decode.ts │ │ └── encode.ts │ ├── util.ts │ └── util │ │ ├── about.ts │ │ ├── class.ts │ │ ├── clone.ts │ │ ├── edit.ts │ │ ├── encode.ts │ │ ├── error.ts │ │ ├── file.ts │ │ ├── path.ts │ │ ├── reqHeader.ts │ │ ├── resHeader.ts │ │ ├── rewritePath.ts │ │ └── route.ts ├── handler │ └── index.ts ├── html │ └── index.ts ├── types.d.ts └── worker │ └── index.ts ├── package.json ├── pnpm-lock.yaml ├── static ├── index.html ├── resources │ ├── img │ │ └── logo.png │ ├── scripts │ │ ├── backdrop.js │ │ ├── index.js │ │ ├── notice.js │ │ └── settings.js │ └── style.css └── sw.js └── tsconfig.json /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "npm" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "daily" 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .DS_Store 4 | **/.DS_Store 5 | package-lock.json -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ![Frame_1_6](https://github.com/NebulaServices/Dynamic/assets/81369743/373dc333-ff38-46c7-90f7-bd34899a6807) 4 | ![Version](https://img.shields.io/badge/status-BETA-build) 5 | [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/Naereen/StrapDown.js/graphs/commit-activity) 6 | [![License](https://img.shields.io/github/license/NebulaServices/Dynamic.svg)](https://github.com/NebulaServices/Dynamic/blob/main/LICENSE) 7 | [![TypeScript](https://badgen.net/badge/icon/typescript?icon=typescript&label)](https://typescriptlang.org) 8 | [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) 9 | 10 | ## Features 11 | 12 | - Customizable and easily configurable 13 | - Seriously Simple to use 14 | - Highly supportive, and supports your favorite sites: 15 | - Google (login and suite apps) 16 | - Youtube 17 | - Discord 18 | - TikTok 19 | - And so much more 20 | - Diabolically fast 21 | - Written in TypeScript 22 | 23 | ## Implementation 24 | See [Examples](https://github.com/NebulaServices/Dynamic/tree/main/examples); 25 | 26 | ## Getting started (How to run) 27 | 28 | ### Method 1 29 | 30 | 1. Clone and change directory into Dynamic 31 | ```bash 32 | git clone https://github,com/NebulaServices/Dynamic.git && cd Dynamic 33 | ``` 34 | 35 | 2. Run bash script and follow the instructions in the script 36 | ```bash 37 | ./bin/start.sh 38 | ``` 39 | 40 | 41 | ### Method 2 42 | 43 | 1. Clone and change directory into Dynamic 44 | ```bash 45 | git clone https://GitHub.com/NebulaServices/Dynamic.git && cd Dynamic 46 | ``` 47 | 48 | 2. Install dependencies 49 | ```bash 50 | npm i 51 | ``` 52 | 53 | 3. Build Dynamic Bundles 54 | ```bash 55 | npm run build 56 | ``` 57 | 58 | 4. Run the server 59 | ```bash 60 | npm start 61 | ``` 62 | 63 | ## Notice 64 | 65 | Hi there, we're launching this project in **early public beta**. Behind the scenes we're working hard at rewriting and bug fixes. Thanks for understanding. 66 | 67 | ## Developer support 68 | We have our very own developer support server! Join with this link: https://discord.gg/shESgmwt3M 69 | 70 | ## Authors 71 | 72 | - [@Sylvie](https://www.github.com/Sylvie-TN) - Lead developer 73 | - [@GreenyDev](https://github.com/GreenyDEV) - Documentation, project manager 74 | 75 | 76 | Made with ❤️ By Nebula Services 77 | 78 | -------------------------------------------------------------------------------- /bin/balls.sh: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NebulaServices/Dynamic/0783cd628049089dae3fd773e93bc36a816d0f96/bin/balls.sh -------------------------------------------------------------------------------- /bin/index.cjs: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const { resolve } = require("node:path"); 4 | 5 | const dynamicPath = resolve(__dirname, "..", "dist"); 6 | 7 | exports.dynamicPath = dynamicPath; 8 | -------------------------------------------------------------------------------- /bin/index.d.ts: -------------------------------------------------------------------------------- 1 | declare const dynamicPath: string; 2 | 3 | export { dynamicPath }; 4 | -------------------------------------------------------------------------------- /bin/start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | tput setaf 33; echo "Thanks for using Dynamic!"; tput sgr0 3 | 4 | #Navigating to the project root 5 | scriptDir="${0%/*}" 6 | cd $scriptDir 7 | cd ../ 8 | echo "Project Directory: $(pwd)" 9 | 10 | tput bold; echo "Dev build is currently still being working on, choose at your own risk"; tput sgr0 11 | 12 | while [[ $devAns != "dev" ]] || [[ $devAns != "prod" ]] 13 | do 14 | echo "Dev or Prod? dev/prod" 15 | read devAns 16 | if [[ $devAns == "dev" ]] || [[ $devAns == "prod" ]] 17 | then 18 | break 19 | else 20 | tput setaf 124; echo "Invalid Input"; tput sgr0 21 | fi 22 | done 23 | 24 | echo "Checking if packages are installed" 25 | if ls | grep -q node_modules 26 | then 27 | echo "node_modules found" 28 | 29 | while [[ $cleanAns != "y" ]] || [[ $cleanAns != "n" ]] 30 | do 31 | echo "Would you like to reinstall? y/n" 32 | read cleanAns 33 | if [[ $cleanAns == "y" ]] || [[ $cleanAns == "n" ]] 34 | then 35 | break 36 | else 37 | tput setaf 124; echo "Invalid Input"; tput sgr0 38 | fi 39 | done 40 | 41 | if [[ $cleanAns = "y" ]] 42 | then 43 | echo "Cleaning node_modules" 44 | rm -rf node_modules 45 | echo "Installing node_modules" 46 | npm install 47 | elif [[ $cleanAns = "n" ]] 48 | then 49 | echo "Skipping packages" 50 | fi 51 | 52 | else 53 | echo "node_modules not found" 54 | 55 | while [[ $installAns != "y" ]] || [[ $installAns != "n" ]] 56 | do 57 | echo "Would you like to install? y/n" 58 | read installAns 59 | if [[ $installAns == "y" ]] || [[ $installAns == "n" ]] 60 | then 61 | break 62 | else 63 | tput setaf 124; echo "Invalid Input"; tput sgr0 64 | fi 65 | done 66 | 67 | if [[ $installAns == "y" ]] 68 | then 69 | echo "Installing node_modules" 70 | npm install 71 | elif [[ $installAns == "n" ]] 72 | then 73 | echo "Skipping packages" 74 | fi 75 | fi 76 | 77 | if [[ $devAns == "dev" ]] 78 | then 79 | while [[ $buildAns != "y" ]] || [[ $buildAns != "n" ]] 80 | do 81 | echo "Would you like to build and start? y/n" 82 | read buildAns 83 | if [[ $buildAns == "y" ]] || [[ $buildAns == "n" ]] 84 | then 85 | break 86 | else 87 | tput setaf 124; echo "Invalid Input"; tput sgr0 88 | fi 89 | done 90 | 91 | if [[ $buildAns == 'y' ]] 92 | then 93 | echo "Running Dynamic" 94 | npm run build:dev 95 | elif [[ $buildAns == 'n' ]] 96 | then 97 | tput setaf 124; echo "Exiting Dynamic"; tpur sgr0 98 | fi 99 | 100 | elif [[ $devAns == "prod" ]] 101 | then 102 | 103 | while [[ $buildAns != "build" ]] || [[ $buildAns != "start" ]] || [[ $buildAns != "both" ]] 104 | do 105 | tput sitm; echo "Hint: ctrl + c to exit"; tput sgr0 106 | echo "Would you like to build, start, or both? build/start/both" 107 | read buildAns 108 | if [[ $buildAns == "build" ]] || [[ $buildAns == "start" ]] || [[ $buildAns == "both" ]] 109 | then 110 | break 111 | else 112 | tput setaf 124; echo "Invalid Input"; tput sgr0 113 | fi 114 | done 115 | 116 | if [[ $buildAns == "build" ]] 117 | then 118 | echo "Building Dynamic" 119 | npm run build:$devAns 120 | elif [[ $buildAns == "start" ]] 121 | then 122 | echo "Starting Dynamic" 123 | npm run start 124 | elif [[ $buildAns == "both" ]] 125 | then 126 | echo "Doing Both!" 127 | echo "Building Dynamic" 128 | npm run build:$devAns 129 | echo "Starting Dynamic :)" 130 | npm run start 131 | fi 132 | fi 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /docs/configuration/bare.md: -------------------------------------------------------------------------------- 1 | # Bare version and path 2 | 3 | 4 | You might have noticed this setting in your configuration file: 5 | ```js 6 | bare: { 7 | version: 2, 8 | path: '/bare/', 9 | }, 10 | ``` 11 | This is refering to the Bare endpoint that Dynamic uses. The version is what Dynamic concatonates to the path. It will finally look something like `/path/version/`. There are differences in the versions. Details on the specification can be found here: 12 | 13 | * v1: https://github.com/tomphttp/specifications/blob/master/BareServerV1.md 14 | * v2: https://github.com/tomphttp/specifications/blob/master/BareServerV2.md 15 | * v3: https://github.com/tomphttp/specifications/blob/master/BareServerV3.md 16 | 17 | ## Unsupported versions. 18 | Dynamic does not have stable support v3 as of now. -------------------------------------------------------------------------------- /docs/configuration/encoding.md: -------------------------------------------------------------------------------- 1 | # URL Encoding and Decoding 2 | 3 | In the context of Dynamic, and other popular Interception proxies, URL Encoding and Decoding is the way Dynamic changes the URLs, specifically to hide them. 4 | 5 | ## Encoding types 6 | There's a few types of encodings that Dynamic currently supports. 7 | 8 | ### XOR 9 | The XOR encryption algorithm is an example of symmetric encryption where the same key is used to both encrypt and decrypt a message. Symmetric Encryption: The same cryptographic key is used both to encrypt and decrypt messages 10 | 11 | Okay, yes, XOR is a cipher not an encoding. But for the purpose of simplicity, we're going to refer to it as an encoding. 12 | 13 | Example: 14 | * `https://google.com` 15 | * `hvtrs8%2F-wuw%2Cgmoelg.aoo%2F` 16 | * `https://www.youtube.com` 17 | * `hvtrs8%2F-wuw%2Cymuvu%60e%2Ccmm-` 18 | 19 | Want to use XOR? Change your `encoding` value to `xor` 20 | 21 | ### AES 22 | Similar to the XOR encoding, AES (Advanced Encryption Standard) encoding is a type of symmetric encryption where the same key is used to both encrypt and decrypt a message, however AES doesn't settle for a one-byte affair; it operates with much longer key lengths (up to 256 bits) compared to the 8 bits of XOR. Like XOR, it is also a cipher and not an encoding. If you're trying to hide your activity the best, AES is the way to go. While the URL may not be readable, it will be **very** difficult for a third party to decrypt the URL without the key. 23 | 24 | Example: 25 | * `https://google.com` 26 | * `88b1yAJnVf99jJZjWhNiho+l5CUg1PRDZGg0Dn005/MseDO3Sn2Mzs` 27 | * `https://www.youtube.com` 28 | * `+Bu/h2WhD6UXm5YAYzOuiiPEmA5l/gEZC0CUtY4jb3h6f4Cgwzsm/i` 29 | 30 | If this fits your need, Change your `encoding` value to `aes` 31 | 32 | ### Plain 33 | In computing, plain encoding is a loose term for data (e.g. file contents) that represent *only characters* of readable material but not its graphical representation nor other objects (floating-point numbers, images, etc.). It may also include a limited number of "whitespace" characters that affect simple arrangement of text. 34 | Note that this provides very little URL cloaking. 35 | 36 | Example: 37 | * `https://google.com` 38 | * `https%3A%2F%2Fgoogle.com` 39 | * `https://www.youtube.com` 40 | * `https%3A%2F%2Fwww.youtube.com` 41 | 42 | If this fits your need, Change your `encoding` value to `plain` 43 | 44 | ### Base64 45 | Base64 is a encoding algorithm that allows you to transform any characters into an alphabet which consists of Latin letters, digits, plus, and slash. Thanks to it, Dynamic can hide URLs by turning the letters of the URL into numbers. 46 | 47 | Example: 48 | * `https://google.com` 49 | * `aHR0cHM6Ly9nb29nbGUuY29t` 50 | * `https://www.youtube.com` 51 | * `aHR0cHM6Ly93d3cueW91dHViZS5jb20=` 52 | 53 | If this fits your need, Change your `encoding` value to `base64` 54 | 55 | 56 | -------------------------------------------------------------------------------- /docs/configuration/logging.md: -------------------------------------------------------------------------------- 1 | # Developer console logging 2 | // 0: none, 1: errors, 2: errors + warnings, 3: errors + warnings + info 3 | Dynamic gives you the option to choose what kind of logs are allowed to appear in the Developer console found in the inspect element menu. 4 | 5 | ## No logging 6 | For absolutely no logging, change the value in your configuration to `0` 7 | 8 | ## Errors only 9 | If you only want errors in console, but want to ignore warnings, this is the level for you! Turn the value in your configuration to `1` 10 | 11 | ## Indecisive 12 | Looking for both Errors and Warnings? Change the value in your configuration to `2` 13 | 14 | ## The everything burger 15 | Exactly what it sounds like, errors + warnings + info. Set the value in your configuration to `2` 16 | -------------------------------------------------------------------------------- /docs/configuration/modes.md: -------------------------------------------------------------------------------- 1 | # Performance modes 2 | Dynamic provides two performance options to fit your needs. 3 | 4 | ## Development 5 | 6 | When you set your performance mode to `development`, Dynamic will not cache itself or minify at all. 7 | 8 | This mode is recommended when: 9 | * Creating middleware with the Dynamic API 10 | * Testing features that require debugging 11 | 12 | ## Production 13 | 14 | When you set your performance mode to `production`, Dynamic will cache its bundle and configuration file. This is Dynamics peak performance mode. 15 | 16 | This mode is recommended when: 17 | * Production or public use is intended 18 | * When speed is priority over middleware updates. 19 | -------------------------------------------------------------------------------- /docs/examples/uv-dynamic-multi/dynamic/dynamic.config.js: -------------------------------------------------------------------------------- 1 | self.__dynamic$config = { 2 | prefix: '/service/', 3 | encoding: 'xor', 4 | mode: 'production', // development: zero caching, no minification, production: speed-oriented 5 | logLevel: 0, // 0: none, 1: errors, 2: errors + warnings, 3: errors + warnings + info 6 | bare: { 7 | version: 2, // v3 is bad 8 | path: '/bare/', 9 | }, 10 | tab: { 11 | title: 'Service', 12 | icon: null, 13 | ua: null, 14 | }, 15 | assets: { 16 | prefix: '/dynamic/', 17 | files: { 18 | handler: 'dynamic.handler.js', 19 | client: 'dynamic.client.js', 20 | worker: 'dynamic.worker.js', 21 | config: 'dynamic.config.js', 22 | inject: null, 23 | } 24 | }, 25 | block: [ 26 | 27 | ] 28 | }; -------------------------------------------------------------------------------- /docs/examples/uv-dynamic-multi/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dynamic 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |

Dynamic

16 |
17 | 18 |
19 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /docs/examples/uv-dynamic-multi/resources/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NebulaServices/Dynamic/0783cd628049089dae3fd773e93bc36a816d0f96/docs/examples/uv-dynamic-multi/resources/img/logo.png -------------------------------------------------------------------------------- /docs/examples/uv-dynamic-multi/resources/scripts/index.js: -------------------------------------------------------------------------------- 1 | let workerLoaded; 2 | 3 | async function worker() { 4 | return await navigator.serviceWorker.register("/sw.js", { 5 | scope: "/service", 6 | }); 7 | } 8 | 9 | document.addEventListener('DOMContentLoaded', async function(){ 10 | await worker(); 11 | workerLoaded = true; 12 | }) 13 | 14 | function prependHttps(url) { 15 | if (!url.startsWith('http://') && !url.startsWith('https://')) { 16 | return 'https://' + url; 17 | } 18 | return url; 19 | } 20 | 21 | function isUrl(val = "") { 22 | // Use a regular expression to check for a valid URL pattern 23 | const urlPattern = /^(http(s)?:\/\/)?([\w-]+\.)+[\w]{2,}(\/.*)?$/; 24 | return urlPattern.test(val); 25 | } 26 | 27 | const inpbox = document.getElementById("uform"); 28 | inpbox.addEventListener("submit", async (event) => { 29 | event.preventDefault(); 30 | console.log("Connecting to service -> loading"); 31 | if (typeof navigator.serviceWorker === "undefined") { 32 | alert( 33 | "An error occurred registering your service worker. Please contact support - discord.gg/unblocker" 34 | ); 35 | } 36 | if (!workerLoaded) { 37 | await worker(); 38 | } 39 | 40 | const form = document.querySelector("form"); 41 | const formValue = document.querySelector("form input").value; 42 | const url = isUrl(formValue) ? prependHttps(formValue) : 'https://www.google.com/search?q=' + encodeURIComponent(formValue); 43 | 44 | location.href = form.action + "?url=" + encodeURIComponent(url); 45 | }); 46 | -------------------------------------------------------------------------------- /docs/examples/uv-dynamic-multi/resources/scripts/notice.js: -------------------------------------------------------------------------------- 1 | const delay = ms => new Promise(res => setTimeout(res, ms)); 2 | 3 | 4 | async function greet(){ 5 | const style = 'background-color: black; color: white; font-style: italic; border: 5px solid red; font-size: 2em;' 6 | let visited = localStorage.getItem('visited') 7 | await delay(500); 8 | console.log("%cPlease, do not put anything in this developer console. You risk your data.", style) 9 | await delay(500); 10 | if (!visited) { 11 | console.log('showing warning') 12 | alert('Hello! Thanks for using Dynamic.\nPlease be aware that this is a public beta version of Dynamic. Please report bugs to our GitHub issues page :)\n\n(we will only show you this announcement once.)') 13 | } 14 | localStorage.setItem("visited", "true") 15 | } 16 | greet() -------------------------------------------------------------------------------- /docs/examples/uv-dynamic-multi/resources/style.css: -------------------------------------------------------------------------------- 1 | html { 2 | width: 100%; 3 | height: 100%; 4 | } 5 | body { 6 | background-color: #080808; 7 | color: #ffffff; 8 | font-family: 'Roboto', sans-serif; 9 | font-size: 16px; 10 | line-height: 1.5; 11 | margin: 0; 12 | padding: 0; 13 | width: 100%; 14 | height: 100%; 15 | display: flex; 16 | align-items: center; 17 | justify-content: center; 18 | align-content: center; 19 | flex-direction: column; 20 | position: absolute; 21 | z-index: 1; 22 | } 23 | h1 { 24 | font-size: 72px; 25 | font-weight: 700; 26 | margin: 0 0 -43px 0; 27 | font-style: italic; 28 | } 29 | form { 30 | display: flex; 31 | flex-direction: row; 32 | align-items: flex-start; 33 | margin: 64px auto; 34 | max-width: 480px; 35 | width: 100%; 36 | justify-content: center; 37 | align-content: center; 38 | } 39 | input[name="url"] { 40 | background-color: #0f0f0fbf; 41 | border: 1px solid #ffffff24; 42 | color: #ffffff; 43 | font-size: 16px; 44 | border-radius: 9px; 45 | margin: 0 0 16px 0; 46 | font-family: 'Roboto', sans-serif; 47 | padding: 16px; 48 | text-align: center; 49 | width: 100%; 50 | outline: transparent; 51 | } 52 | input[name="url"]::placeholder { 53 | color: #bfbfbf; 54 | } 55 | input[type="submit"] { 56 | background-color: #daff46; 57 | color: black; 58 | border: none; 59 | font-size: 16px; 60 | font-weight: 700; 61 | padding: 16px; 62 | text-align: center; 63 | text-transform: uppercase; 64 | transition: background-color 0.2s ease-in-out; 65 | width: 100%; 66 | } 67 | input[type="submit"]:hover { 68 | background-color: #00c853; 69 | cursor: pointer; 70 | } 71 | 72 | 73 | svg { 74 | position: absolute; 75 | top: 0; 76 | left: 0; 77 | z-index: -1; 78 | filter: blur(97px); 79 | } 80 | 81 | 82 | .footer { 83 | display: flex; 84 | align-items: flex-end; 85 | justify-content: center; 86 | flex-direction: row; 87 | align-content: center; 88 | flex-wrap: nowrap; 89 | position: absolute; 90 | bottom: 0; 91 | width: 100%; 92 | 93 | } 94 | 95 | .copyright { 96 | position: absolute; 97 | left: 17px; 98 | } 99 | 100 | canvas { 101 | width: 100%; 102 | height: 100%; 103 | position: absolute; 104 | z-index: -2; 105 | } -------------------------------------------------------------------------------- /docs/examples/uv-dynamic-multi/sw.js: -------------------------------------------------------------------------------- 1 | importScripts('/dynamic/dynamic.config.js'); 2 | importScripts('/dynamic/dynamic.worker.js'); 3 | importScripts('dist/uv.bundle.js'); 4 | importScripts('dist/uv.config.js'); 5 | importScripts(__uv$config.sw || 'dist/uv.sw.js'); 6 | 7 | const uv = new UVServiceWorker(); 8 | const dynamic = new Dynamic(); 9 | 10 | self.dynamic = dynamic; 11 | 12 | self.addEventListener('fetch', 13 | event => { 14 | event.respondWith( 15 | (async function() { 16 | if (await dynamic.route(event)) { 17 | return await dynamic.fetch(event); 18 | } 19 | 20 | if (event.request.url.startsWith(location.origin + "/service/uv/")) { 21 | return await uv.fetch(event); 22 | } 23 | 24 | return await fetch(event.request); 25 | })() 26 | ); 27 | } 28 | ); -------------------------------------------------------------------------------- /docs/examples/uv-dynamic-multi/uv/uv.bundle.js.LICENSE.txt: -------------------------------------------------------------------------------- 1 | /*! 2 | * mime-db 3 | * Copyright(c) 2014 Jonathan Ong 4 | * Copyright(c) 2015-2022 Douglas Christopher Wilson 5 | * MIT Licensed 6 | */ 7 | -------------------------------------------------------------------------------- /docs/examples/uv-dynamic-multi/uv/uv.config.js: -------------------------------------------------------------------------------- 1 | /*global Ultraviolet*/ 2 | self.__uv$config = { 3 | prefix: '/service/uv/', 4 | bare: 'https:///', 5 | encodeUrl: Ultraviolet.codec.plain.encode, 6 | decodeUrl: Ultraviolet.codec.plain.decode, 7 | handler: '/dist/uv.handler.js', 8 | client: '/dist/uv.client.js', 9 | bundle: '/dist/uv.bundle.js', 10 | config: '/dist/uv.config.js', 11 | sw: '/dist/uv.sw.js', 12 | }; 13 | -------------------------------------------------------------------------------- /docs/examples/uv-dynamic-multi/uv/uv.sw.js: -------------------------------------------------------------------------------- 1 | (()=>{"use strict";const e=self.Ultraviolet,t=["cross-origin-embedder-policy","cross-origin-opener-policy","cross-origin-resource-policy","content-security-policy","content-security-policy-report-only","expect-ct","feature-policy","origin-isolation","strict-transport-security","upgrade-insecure-requests","x-content-type-options","x-download-options","x-frame-options","x-permitted-cross-domain-policies","x-powered-by","x-xss-protection"],r=["GET","HEAD"];class i extends e.EventEmitter{constructor(t=__uv$config){super(),t.bare||(t.bare="/bare/"),t.prefix||(t.prefix="/service/"),this.config=t;const r=(Array.isArray(t.bare)?t.bare:[t.bare]).map((e=>new URL(e,location).toString()));this.address=r[~~(Math.random()*r.length)],this.bareClient=new e.BareClient(this.address)}async fetch({request:i}){let a;try{if(!i.url.startsWith(location.origin+this.config.prefix))return await fetch(i);const c=new e(this.config,this.address);"function"==typeof this.config.construct&&this.config.construct(c,"service");const l=await c.cookie.db();c.meta.origin=location.origin,c.meta.base=c.meta.url=new URL(c.sourceUrl(i.url));const d=new o(i,this,c,r.includes(i.method.toUpperCase())?null:await i.blob());if("blob:"===c.meta.url.protocol&&(d.blob=!0,d.base=d.url=new URL(d.url.pathname)),i.referrer&&i.referrer.startsWith(location.origin)){const e=new URL(c.sourceUrl(i.referrer));(d.headers.origin||c.meta.url.origin!==e.origin&&"cors"===i.mode)&&(d.headers.origin=e.origin),d.headers.referer=e.href}const h=await c.cookie.getCookies(l)||[],u=c.cookie.serialize(h,c.meta,!1);d.headers["user-agent"]=navigator.userAgent,u&&(d.headers.cookie=u);const p=new n(d,null,null);if(this.emit("request",p),p.intercepted)return p.returnValue;a=d.blob?"blob:"+location.origin+d.url.pathname:d.url;const m=await this.bareClient.fetch(a,{headers:d.headers,method:d.method,body:d.body,credentials:d.credentials,mode:location.origin!==d.address.origin?"cors":d.mode,cache:d.cache,redirect:d.redirect}),f=new s(d,m),b=new n(f,null,null);if(this.emit("beforemod",b),b.intercepted)return b.returnValue;for(const e of t)f.headers[e]&&delete f.headers[e];if(f.headers.location&&(f.headers.location=c.rewriteUrl(f.headers.location)),"document"===i.destination){const e=f.headers["content-disposition"];if(!/\s*?((inline|attachment);\s*?)filename=/i.test(e)){const t=/^\s*?attachment/i.test(e)?"attachment":"inline",[r]=new URL(m.finalURL).pathname.split("/").slice(-1);f.headers["content-disposition"]=`${t}; filename=${JSON.stringify(r)}`}}if(f.headers["set-cookie"]&&(Promise.resolve(c.cookie.setCookies(f.headers["set-cookie"],l,c.meta)).then((()=>{self.clients.matchAll().then((function(e){e.forEach((function(e){e.postMessage({msg:"updateCookies",url:c.meta.url.href})}))}))})),delete f.headers["set-cookie"]),f.body)switch(i.destination){case"script":case"worker":{const e=[c.bundleScript,c.clientScript,c.configScript,c.handlerScript].map((e=>JSON.stringify(e))).join(",");f.body=`if (!self.__uv && self.importScripts) { ${c.createJsInject(this.address,this.bareClient.manfiest,c.cookie.serialize(h,c.meta,!0),i.referrer)} importScripts(${e}); }\n`,f.body+=c.js.rewrite(await m.text())}break;case"style":f.body=c.rewriteCSS(await m.text());break;case"iframe":case"document":(function(t,r=""){return"text/html"===(e.mime.contentType(r||t.pathname)||"text/html").split(";")[0]})(c.meta.url,f.headers["content-type"]||"")&&(f.body=c.rewriteHtml(await m.text(),{document:!0,injectHead:c.createHtmlInject(c.handlerScript,c.bundleScript,c.clientScript,c.configScript,this.address,this.bareClient.manfiest,c.cookie.serialize(h,c.meta,!0),i.referrer)}))}return"text/event-stream"===d.headers.accept&&(f.headers["content-type"]="text/event-stream"),crossOriginIsolated&&(f.headers["Cross-Origin-Embedder-Policy"]="require-corp"),this.emit("response",b),b.intercepted?b.returnValue:new Response(f.body,{headers:f.headers,status:f.status,statusText:f.statusText})}catch(e){return["document","iframe"].includes(i.destination)?(console.error(e),function(e,t,r){let i,s,o,n,a="";!function(e){return e instanceof Error&&"object"==typeof e.body}(e)?(i=500,s="Error processing your request",n="Internal Server Error",o=e instanceof Error?e.name:"UNKNOWN"):(i=e.status,s="Error communicating with the Bare server",n=e.body.message,o=e.body.code,a=e.body.id);return new Response(function(e,t,r,i,s,o,n){if("The specified host could not be resolved."===i)return function(e,t){const r=new URL(e),i=`remoteHostname.textContent = ${JSON.stringify(r.hostname)};bareServer.href = ${JSON.stringify(t)};uvHostname.textContent = ${JSON.stringify(location.hostname)};reload.addEventListener("click", () => location.reload());uvVersion.textContent = ${JSON.stringify("2.0.0")};`;return`Error

This site can’t be reached


’s server IP address could not be found.

Try:


Ultraviolet v

`, 26 | //``, 27 | ``, 28 | ] 29 | 30 | if (this.ctx.config.assets.files.inject) array.unshift(``); 31 | if (cookies) array.unshift(``); 32 | if (script) array.unshift(``); 33 | if (bare) array.unshift(``); 34 | 35 | return array; 36 | } 37 | 38 | /*if (self.__dynamic$config) { 39 | var cache = self.__dynamic$config.mode == 'development'; 40 | } else var cache = false; 41 | 42 | var head: Array = [ 43 | {nodeName: 'script', tagName: 'script', namespaceURI: 'http://www.w3.org/1999/xhtml', childNodes: [], attrs: [{name: 'src', value: scriptURL+(cache?'?'+Math.floor(Math.random()*(99999-10000)+10000):'')}]}, 44 | {nodeName: 'script', tagName: 'script', namespaceURI: 'http://www.w3.org/1999/xhtml', childNodes: [], attrs: [{name: 'src', value: configURL+(cache?'?'+Math.floor(Math.random()*(99999-10000)+10000):'')}]}, 45 | ]; 46 | 47 | if (this.ctx.config.assets.files.inject) head.unshift({nodeName: 'script', tagName: 'script', namespaceURI: 'http://www.w3.org/1999/xhtml', childNodes: [], attrs: [{name: 'src', value: this.ctx.config.assets.files.inject+(cache?'?'+Math.floor(Math.random()*(99999-10000)+10000):'')}]}); 48 | if (cookies) head.unshift({nodeName: 'script', tagName: 'script', namespaceURI: 'http://www.w3.org/1999/xhtml', childNodes: [], attrs: [{name: 'src', value: 'data:application/javascript;base64,'+btoa(`self.__dynamic$cookies = atob("${btoa(cookies)}");document.currentScript?.remove();`)}]}); 49 | if (script) head.unshift({nodeName: 'script', tagName: 'script', namespaceURI: 'http://www.w3.org/1999/xhtml', childNodes: [], attrs: [{name: 'src', value: 'data:application/javascript;base64,'+btoa(script+';document.currentScript?.remove();')}]}); 50 | 51 | return head;*/ 52 | 53 | 54 | /*var array: Array = [ 55 | new Element('script', {src: scriptURL+(cache?'?'+Math.floor(Math.random()*(99999-10000)+10000):'')}), 56 | new Element('script', {src: configURL+(cache?'?'+Math.floor(Math.random()*(99999-10000)+10000):'')}), 57 | ] 58 | 59 | if (cookies) array.unshift(new Element('script', {src: 'data:application/javascript;base64,'+btoa(`self.__dynamic$cookies = atob("${btoa(cookies)}");document.currentScript?.remove();`)}, [])); 60 | if (script) array.unshift(new Element('script', {src: 'data:application/javascript;base64,'+btoa(script+';document.currentScript?.remove();')}, [])); 61 | 62 | return array;*/ 63 | } -------------------------------------------------------------------------------- /lib/global/rewrite/html/html.ts: -------------------------------------------------------------------------------- 1 | import Srcset from './srcset'; 2 | import Node from './nodewrapper'; 3 | import MetaURL from '../../meta/type'; 4 | import generateHead from './generateHead'; 5 | import { Element } from 'parse5/dist/tree-adapters/default'; 6 | import DynamicRewrites from '../../rewrite'; 7 | 8 | export default class html { 9 | 10 | ctx: any; 11 | 12 | generateHead: Function = generateHead; 13 | 14 | config: Array = [ 15 | { 16 | "elements": "all", 17 | "tags": ['style'], 18 | "action": "css" 19 | }, 20 | { 21 | "elements": ['script', 'iframe', 'embed', 'input', 'track', 'media', 'source', 'img', 'a', 'link', 'area', 'form', 'object'], 22 | "tags": ['src', 'href', 'action', 'data'], 23 | "action": "url" 24 | }, 25 | { 26 | "elements": ['source', 'img'], 27 | "tags": ['srcset'], 28 | "action": "srcset" 29 | }, 30 | /*{ 31 | "elements": ['a', 'link', 'area'], 32 | "tags": ['href'], 33 | "action": "url" 34 | }, 35 | { 36 | "elements": ['form'], 37 | "tags": ['action'], 38 | "action": "url" 39 | }, 40 | { 41 | "elements": ['object'], 42 | "tags": ['data'], 43 | "action": "url", 44 | },*/ 45 | { 46 | "elements": ['script', 'link'], 47 | "tags": ['integrity'], 48 | "action": "rewrite", 49 | "new": "nointegrity", 50 | }, 51 | { 52 | "elements": ['script', 'link'], 53 | "tags": ['nonce'], 54 | "action": "rewrite", 55 | "new": "nononce", 56 | }, 57 | { 58 | "elements": ['meta'], 59 | "tags": ['http-equiv'], 60 | "action": "http-equiv", 61 | }, 62 | { 63 | "elements": ['iframe'], 64 | "tags": ['srcdoc'], 65 | "action": "html", 66 | }, 67 | { 68 | "elements": ['link'], 69 | "tags": ["imagesrcset"], 70 | "action": "srcset", 71 | }, 72 | { 73 | "elements": 'all', 74 | "tags": ['onclick'], 75 | "action": "js", 76 | } 77 | ]; 78 | 79 | constructor(ctx: DynamicRewrites) { 80 | this.ctx = ctx.ctx; 81 | } 82 | 83 | generateRedirect(url: string) { 84 | return ` 85 | 86 | 301 Moved 87 |

301 Moved

88 | The document has moved 89 | here. 90 | 91 | ` 92 | } 93 | 94 | iterate(_dom: Object, cb: Function) { 95 | function it(dom: Object | any = _dom) { 96 | for (var i = 0; i < dom.childNodes.length; i++) { 97 | cb(dom.childNodes[i]); 98 | 99 | if (dom.childNodes[i].childNodes) if (dom.childNodes[i].childNodes.length) { 100 | it(dom.childNodes[i]); 101 | }; 102 | } 103 | } 104 | 105 | it(_dom); 106 | } 107 | 108 | rewrite(src: string, meta: MetaURL, head: Array = []) { 109 | if (Array.isArray(src)) src = src[0]; 110 | 111 | if (!src) return src; 112 | 113 | src = src.toString(); 114 | 115 | if (!src.match(/<\!DOCTYPE[^>]*>/gi)) { 116 | src = "" + src 117 | } 118 | 119 | return src.replace(/(|)/im, `$1${head.join(``)}\n`).replace(/<(script|link)\b[^>]*>/g, (e, n) => e.replace(/\snonce\s*=\s*"[^"]*"/, e => e.replace("nonce", "nononce")).replace(/\sintegrity\s*=\s*"[^"]*"/, e => e.replace("integrity", "nointegrity"))); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /lib/global/rewrite/html/nodewrapper.ts: -------------------------------------------------------------------------------- 1 | export default class Node { 2 | Original: Object | any | null = null; 3 | ctx: any; 4 | 5 | constructor(element: Element, ctx: any) { 6 | this.Original = element; 7 | 8 | var that = this; 9 | 10 | this.Original.attribs = new Proxy(this.Original.attribs||{}, { 11 | set: (target:any, prop: string, value:any): any => { 12 | var a = target[prop] = value; 13 | 14 | that.Original.attrs = Object.keys(target).map((key:any) => { 15 | return { 16 | name: key, 17 | value: target[key] + '' 18 | } 19 | }); 20 | 21 | return a || (a + ' '); 22 | }, 23 | deleteProperty: (target: any, prop: string): any => { 24 | var a = delete target[prop]; 25 | 26 | that.Original.attrs = Object.keys(target).map((key:any) => { 27 | return { 28 | name: key, 29 | value: target[key] 30 | } 31 | }); 32 | 33 | return a; 34 | } 35 | }); 36 | 37 | this.ctx = ctx; 38 | } 39 | 40 | getAttribute(attr: string) { 41 | if (!this.Original.attribs) return false; 42 | 43 | return (typeof this.Original.attribs[attr] == 'undefined' ? null : this.Original.attribs[attr].trim()); 44 | } 45 | 46 | setAttribute(attr: string, value: any) { 47 | if (!this.Original.attribs) return false; 48 | 49 | return this.Original.attribs[attr] = value; 50 | } 51 | 52 | removeAttribute(attr: string) { 53 | if (!this.Original.attribs) return false; 54 | 55 | return delete this.Original.attribs[attr]; 56 | } 57 | 58 | hasAttribute(attr: string) { 59 | if (!this.Original.attribs) return false; 60 | 61 | return this.Original.attribs.hasOwnProperty(attr); 62 | } 63 | } -------------------------------------------------------------------------------- /lib/global/rewrite/html/srcset.ts: -------------------------------------------------------------------------------- 1 | export default { 2 | encode(val: string | undefined, dynamic: Object | any) { 3 | if (!val) return val; 4 | if (!(val.toString())) return val; 5 | 6 | return val.split(', ').map((s: any) => { 7 | return s.split(' ').map((e: any,i: any)=>{ 8 | if (i == 0) { 9 | return dynamic.url.encode(e, dynamic.baseURL || dynamic.meta); 10 | } 11 | 12 | return e; 13 | }).join(' '); 14 | }).join(', '); 15 | }, 16 | decode(val: string | undefined) { 17 | if (!val) return val; 18 | 19 | return val; 20 | }, 21 | } -------------------------------------------------------------------------------- /lib/global/rewrite/js/emit.ts: -------------------------------------------------------------------------------- 1 | import Identifier from './type/Identifier'; 2 | import MemberExpression from "./type/MemberExpression"; 3 | import Literal from './type/Literal'; 4 | import CallExpression from './type/CallExpression'; 5 | import AssignmentExpression from './type/AssignmentExpression'; 6 | import ThisExpression from './type/ThisExpression'; 7 | import Property from './type/Property'; 8 | import Imports from './type/Imports'; 9 | import VariableDeclarator from './type/VariableDeclaractor'; 10 | 11 | function Emit(node: Object | any, type: string, parent: Object | any = {}, ctx: Object | any = {}, dynamic: Object | any = {}, config: Object | any = {}) { 12 | if (node.__dynamic) return; 13 | 14 | switch(type) { 15 | case "Identifier": 16 | Identifier(node, parent); 17 | break; 18 | case "MemberExpression": 19 | MemberExpression(node, parent, config); 20 | break; 21 | case "Literal": 22 | Literal(node, parent); 23 | break; 24 | case "CallExpression": 25 | CallExpression(node, parent); 26 | break; 27 | case "AssignmentExpression": 28 | AssignmentExpression(node, parent); 29 | break; 30 | case "ThisExpression": 31 | //ThisExpression(node, parent); 32 | break; 33 | case "Property": 34 | Property(node, parent); 35 | break; 36 | case "VariableDeclarator": 37 | VariableDeclarator(node, parent); 38 | break; 39 | case "CatchClause": 40 | //node.body.body.unshift({"type":"ExpressionStatement","start":21,"end":37,"expression":{"type":"CallExpression","start":21,"end":36,"callee":{"type":"MemberExpression","start":21,"end":34,"object":{"type":"Identifier","start":21,"end":28,"name":"console"},"property":{"type":"Identifier","start":29,"end":34,"name":"error"},"computed":false,"optional":false},"arguments":[{type: "Identifier", name: "typeof E == 'undefined' ? typeof d == 'undefined' ? null : d : E"}],"optional":false}}); 41 | break; 42 | default: 43 | break; 44 | } 45 | 46 | Imports(node, parent, ctx, dynamic); 47 | } 48 | 49 | export default Emit; -------------------------------------------------------------------------------- /lib/global/rewrite/js/iterate.ts: -------------------------------------------------------------------------------- 1 | export default function Iterate(ast: Object, handler: Function) { 2 | if (typeof ast != 'object' || !handler) return; 3 | walk(ast, null, handler); 4 | function walk(node: Object | any, parent: Object | null, handler: Function) { 5 | if (typeof node != 'object' || !handler) return; 6 | node.parent = parent; 7 | handler(node, parent, handler); 8 | for (const child in node) { 9 | if (child === 'parent') continue; 10 | if (Array.isArray(node[child])) { 11 | node[child].forEach((entry: Object | undefined) => { 12 | if (entry) walk(entry, node, handler) 13 | }); 14 | } else { 15 | if (node[child]) walk(node[child], node, handler); 16 | }; 17 | }; 18 | if (typeof node.iterateEnd === 'function') node.iterateEnd(); 19 | }; 20 | }; -------------------------------------------------------------------------------- /lib/global/rewrite/js/js.ts: -------------------------------------------------------------------------------- 1 | import MetaURL from '../../meta/type'; 2 | import iterate from './iterate'; 3 | import process from './process'; 4 | import emit from './emit'; 5 | import DynamicRewrites from '../../rewrite'; 6 | 7 | export default class js { 8 | iterate = iterate; 9 | process = process; 10 | emit = emit; 11 | 12 | ctx; 13 | 14 | constructor(ctx: DynamicRewrites) { 15 | this.ctx = ctx.ctx; 16 | } 17 | 18 | rewrite(this: js, src: string | Object | any, config: Object | any = {}, inject: Boolean = true, dynamic: Object | any = {}) { 19 | if (!src) return src; 20 | 21 | if (src instanceof Object) return src; 22 | 23 | src = src.toString(); 24 | 25 | if (src.includes('/* dynamic.js */')) return src; 26 | 27 | src = `/* dynamic.js */ \n\n${src}`; 28 | 29 | try { 30 | try { 31 | src = this.process(src, config, {module: true, ...this.ctx}, dynamic); 32 | } catch(e) { 33 | //console.log('module failed',e) 34 | src = this.process(src, config, {module: false, ...this.ctx}, dynamic); 35 | } 36 | } catch(e) { 37 | //console.trace('backup failed', e, src) 38 | } 39 | 40 | if (inject) { 41 | src = ` 42 | if (typeof self !== undefined && typeof self.importScripts == 'function' && typeof self.__dynamic == 'undefined') importScripts('/dynamic/dynamic.config.js', '/dynamic/dynamic.handler.js?'+Math.floor(Math.random()*(99999-10000)+10000)); 43 | 44 | ${src}`; 45 | } 46 | 47 | return src; 48 | } 49 | } -------------------------------------------------------------------------------- /lib/global/rewrite/js/object/Eval.ts: -------------------------------------------------------------------------------- 1 | import { Node } from "../types"; 2 | 3 | export default function Eval(node: Node, parent: Node = {} as any) { 4 | if (node.__dynamic) return; 5 | 6 | if (node.arguments.length) { 7 | node.arguments = [{ 8 | type: 'CallExpression', 9 | callee: { 10 | type: 'Identifier', 11 | name: '__dynamic$wrapEval', 12 | __dynamic: true, 13 | }, 14 | arguments: node.arguments, 15 | __dynamic: true, 16 | }] as Array; 17 | 18 | node.__dynamic = true; 19 | } 20 | 21 | return; 22 | } -------------------------------------------------------------------------------- /lib/global/rewrite/js/object/PostMessage.ts: -------------------------------------------------------------------------------- 1 | import { Node } from "../types"; 2 | 3 | export default function PostMessage(node: Node, parent: Node = {} as any) { 4 | Object.entries({ 5 | type: 'CallExpression', 6 | callee: { 7 | type: 'MemberExpression', 8 | object: {type: 'Identifier', name: 'self'}, 9 | property: {type: 'Identifier', name: '__dynamic$message'}, 10 | }, 11 | arguments: [ 12 | node.object||node, 13 | {type: 'Identifier', name: 'self', __dynamic: true} 14 | ] 15 | }).forEach(([name,value]) => (node as any)[name] = value) 16 | 17 | return; 18 | } -------------------------------------------------------------------------------- /lib/global/rewrite/js/process.ts: -------------------------------------------------------------------------------- 1 | import DynamicRewrites from "../../rewrite"; 2 | import js from "./js"; 3 | 4 | export default function process(this: js, src: string, config: Object | any = {}, ctx: any, dynamic: Object | any) { 5 | var ast = this.ctx.modules.acorn.parse(src.toString(), { sourceType: config.module ? 'module' : 'script', allowImportExportEverywhere: true, allowAwaitOutsideFunction: true, allowReturnOutsideFunction: true, ecmaVersion: "latest", preserveParens: false, loose: true, allowReserved: true }); 6 | 7 | this.iterate(ast, (node: any, parent: any = null) => { 8 | this.emit(node, node.type, parent, ctx, dynamic, config); 9 | }); 10 | 11 | src = this.ctx.modules.estree.generate(ast); 12 | 13 | return src; 14 | } 15 | -------------------------------------------------------------------------------- /lib/global/rewrite/js/type/AssignmentExpression.ts: -------------------------------------------------------------------------------- 1 | import Eval from '../object/Eval'; 2 | import PostMessage from '../object/PostMessage'; 3 | import { Node } from '../types'; 4 | 5 | export default function AssignmentExpression(node: Node, parent: Node = {} as any) { 6 | if (node.left.type == 'Identifier') { 7 | if (node.left.__dynamic === true) return; 8 | 9 | if (node.left.name == 'location') { 10 | var ol = structuredClone(node.left), or = structuredClone(node.right); 11 | node.right.type = 'CallExpression'; 12 | node.right.callee = {type: 'Identifier', name: 'ds$'} as Node; 13 | node.right.arguments = [ol, or]; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /lib/global/rewrite/js/type/CallExpression.ts: -------------------------------------------------------------------------------- 1 | import Eval from '../object/Eval'; 2 | import PostMessage from '../object/PostMessage'; 3 | import { Node } from '../types'; 4 | 5 | export default function CallExpression(node: Node, parent: Node = {} as any) { 6 | if (parent.type=='AssignmentExpression'&&parent.left==node) return; 7 | 8 | if (node.callee.type=='Identifier') { 9 | if (node.callee.name=='postMessage') { 10 | let original = 'undefined'; 11 | node.callee.type = 'CallExpression'; 12 | node.callee.callee = {type: 'Identifier', name: '__dynamic$message'} as Node; 13 | node.callee.arguments = [{type: 'Identifier', name: original}, {type: 'Identifier', name: 'self', __dynamic: true}] as Array; 14 | 15 | return; 16 | } 17 | 18 | if (node.callee.name=='eval') { 19 | //node.callee.name = '__dynamic$eval'; 20 | Eval(node); 21 | } 22 | } 23 | 24 | if (node.callee.type=='MemberExpression') { 25 | if (node.callee.property.name=='postMessage' && node.callee.object.type!=='Super') { 26 | let original: Node = node.callee.object; 27 | node.callee.type = 'CallExpression'; 28 | node.callee.callee = {type: 'Identifier', name: '__dynamic$message'} as Node; 29 | node.callee.arguments = [original, {type: 'Identifier', name: 'self', __dynamic: true}] as Array; 30 | 31 | return; 32 | } 33 | 34 | if (node.callee.object.name=='eval') { 35 | //node.callee.object.name = '__dynamic$eval'; 36 | Eval(node); 37 | } 38 | } 39 | 40 | if (node.arguments.length > 0 && node.arguments.length < 4) { 41 | // fallback postmessage rewriting 42 | /*if (node.callee?.object?.type !== 'Literal') 43 | if (node.arguments[1] && node.arguments[1].type == "Literal" && node.arguments[1].value == '*') { 44 | node.callee = { 45 | type: 'CallExpression', 46 | callee: { 47 | type: 'Identifier', 48 | name: 'dg$', 49 | __dynamic: true, 50 | }, 51 | arguments: [ node.callee ], 52 | __dynamic: true, 53 | } 54 | }*/ 55 | } 56 | 57 | try {} catch {} 58 | } -------------------------------------------------------------------------------- /lib/global/rewrite/js/type/Identifier.ts: -------------------------------------------------------------------------------- 1 | import Eval from '../object/Eval'; 2 | import PostMessage from '../object/PostMessage'; 3 | import { Node } from '../types'; 4 | 5 | export default function Identifier(node: Node, parent: Node = {} as any) { 6 | if (typeof node.name !== 'string') return false; 7 | 8 | if (node.__dynamic === true) return; 9 | 10 | if (!['parent', 'top', 'postMessage', 'opener', 'window', 'self', 'globalThis', 'parent', 'location'].includes(node.name)) return false; 11 | 12 | //if (parent.type=='AssignmentExpression'&&parent.left==node&&node.name=='location') return; //node.name = '__dynamic$location' 13 | 14 | if (parent.type=='CallExpression'&&(parent.callee==node)) return; 15 | if (parent.type=='MemberExpression'&&(parent.object!==node&&(!['document', 'window', 'self', 'globalThis'].includes(parent.object.name)))) return; 16 | if (parent.type=='FunctionDeclaration') return; 17 | if (parent.type=='VariableDeclaration') return; 18 | if (parent.type=='VariableDeclarator'&&parent.id==node) return; 19 | if (parent.type=='LabeledStatement') return; 20 | if (parent.type=='Property'&&parent.key==node) return; 21 | if (parent.type=='ArrowFunctionExpression'&&parent.params.includes(node)) return; 22 | if (parent.type=='FunctionExpression'&&parent.params.includes(node)) return; 23 | if (parent.type=='FunctionExpression'&&parent.id==node) return; 24 | if (parent.type=='CatchClause'&&parent.param==node) return; 25 | if (parent.type=='ContinueStatement') return; 26 | if (parent.type=='BreakStatement') return; 27 | if (parent.type=='AssignmentExpression'&&parent.left==node) return; 28 | if (parent.type=='UpdateExpression') return; 29 | if (parent.type=='UpdateExpression') return; 30 | if (parent.type=='ForInStatement'&&parent.left==node) return; 31 | if (parent.type=='MethodDefinition'&&parent.key==node) return; 32 | if (parent.type=='AssignmentPattern'&&parent.left==node) return; 33 | if (parent.type=='NewExpression') return; 34 | if (parent?.parent?.type=='NewExpression') return; 35 | if (parent.type=='UnaryExpression'&&parent.argument==node) return; 36 | if (parent.type=='Property' && parent.shorthand == true && parent.value == node) return; 37 | 38 | //if (node.name=='location') return node.name = '__dynamic$location' 39 | if (node.name == '__dynamic') return node.name = 'undefined'; 40 | 41 | if (node.name=='eval' && parent.right !== node) return node.name = '__dynamic$eval'; 42 | 43 | node.name = `dg$(${node.name})`; 44 | } -------------------------------------------------------------------------------- /lib/global/rewrite/js/type/Imports.ts: -------------------------------------------------------------------------------- 1 | import Eval from '../object/Eval'; 2 | import PostMessage from '../object/PostMessage'; 3 | import { Node } from '../types'; 4 | 5 | export default function Imports(node: Node, parent: Node = {} as any, ctx: Object | any = {}, dynamic: Object | any = {}) { 6 | if (node.type=='Literal'&&(parent.type=='ImportDeclaration'||parent.type=='ExportNamedDeclaration'||parent.type=='ExportAllDeclaration')) { 7 | var og = node.value + ''; 8 | node.value = ctx.url.encode(node.value, dynamic.meta); 9 | node.raw = node.raw.replace(og, node.value); 10 | node.__dynamic = true; 11 | } 12 | 13 | if (node.type=='ImportExpression') { 14 | node.source = {type: 'CallExpression', callee: {type: 'Identifier', name: '__dynamic$import'}, arguments: [node.source, {type: 'Literal', __dynamic: true, value: ctx.meta.href}]} as Node; 15 | node.__dynamic = true; 16 | } 17 | } -------------------------------------------------------------------------------- /lib/global/rewrite/js/type/Literal.ts: -------------------------------------------------------------------------------- 1 | import Eval from '../object/Eval'; 2 | import PostMessage from '../object/PostMessage'; 3 | import { Node } from '../types'; 4 | 5 | export default function Literal(node: Node, parent: Node = {} as any) { 6 | if (!((node.value as any) instanceof String)) return false; 7 | 8 | if (node.value==('__dynamic')) node.value = 'undefined'; 9 | 10 | if (!['location', 'parent', 'top', 'postMessage'].includes(node.value)) return false; 11 | 12 | if (node.value=='postMessage' && parent.type != 'AssignmentExpression' && parent.left != node) PostMessage(node, parent); 13 | if (node.value=='location') node.value = '__dynamic$location'; 14 | if (node.value=='__dynamic') node.value = 'undefined'; 15 | if (node.value=='eval') node.value = '__dynamic$eval'; 16 | } -------------------------------------------------------------------------------- /lib/global/rewrite/js/type/MemberExpression.ts: -------------------------------------------------------------------------------- 1 | import Eval from '../object/Eval'; 2 | import PostMessage from '../object/PostMessage'; 3 | import { Node } from '../types'; 4 | 5 | export default function MemberExpression(node: Node, parent: Node = {} as any, config: any = {}) { 6 | /*if (config.destination !== 'worker') if (node.object.type!=='Identifier') { 7 | if (node.object.type == 'MemberExpression') return node.object = { 8 | type: 'CallExpression', 9 | callee: {type: 'Identifier', name: '__dynamic$get'}, 10 | arguments: [node.object] 11 | } 12 | } 13 | 14 | if (config.destination !== 'worker') if (node.object.type=='Identifier') { 15 | node.object = { 16 | type: 'CallExpression', 17 | callee: {type: 'Identifier', name: '__dynamic$get'}, 18 | arguments: [node.object] 19 | } 20 | }*/ 21 | 22 | node.object.name+=''; 23 | 24 | if (parent.type!=='AssignmentExpression'&&parent.left!==node) { 25 | if (node.property.value == 'postMessage' && (parent.type=='CallExpression'&&parent.callee==node)) return PostMessage(node, parent); 26 | if (node.object.value == 'postMessage' && (parent.type=='CallExpression'&&parent.callee==node)) return PostMessage(node, parent); 27 | 28 | if ((node.property.name=='postMessage'||node.object.name=='postMessage') && node.object.type!=='Super') { 29 | var original:string = node.object?.name 30 | node.type = 'CallExpression'; 31 | node.callee = {type: 'Identifier', name: '__dynamic$message'} as Node; 32 | node.arguments = [{type: 'Identifier', name: original} as Node, {type: 'Identifier', name: 'self', __dynamic: true} as Node] 33 | if (parent.type=='CallExpression') { 34 | parent.arguments = parent.arguments 35 | } 36 | 37 | return; 38 | } 39 | } 40 | 41 | if (node.property.name=='eval') node.property.name = '__dynamic$eval'; 42 | if (node.object.name=='eval') node.object.name = '__dynamic$eval'; 43 | 44 | if (config.destination!=='worker') { 45 | if (node.property.name=='window'&&node.object.name!='top'&&(node.object.name=='self'||node.object.name=='globalThis')) if (parent.type!=='NewExpression'&&(parent.type!=='CallExpression'||((parent.type=='CallExpression')&&node!==parent.callee))) node.property.name = '__dynamic$window'; 46 | if (node.object.name=='top') if (parent.type!=='NewExpression'&&(parent.type!=='CallExpression'||((parent.type=='CallExpression')&&node!==parent.callee))) node.object.name = 'top.__dynamic$window'; 47 | if (node.property.name=='top'&&(node.object.name=='self'||node.object.name=='globalThis')) if (parent.type!=='NewExpression'&&(parent.type!=='CallExpression'||((parent.type=='CallExpression')&&node!==parent.callee))) node.property.name = 'top.__dynamic$window'; 48 | if (parent.type!=='NewExpression'&&(parent.type!=='CallExpression'||((parent.type=='CallExpression')&&node!==parent.callee))) { 49 | if (node.object.name=='window') { 50 | node.object = { 51 | type: 'CallExpression', 52 | callee: {type: 'Identifier', name: 'dg$'} as Node, 53 | arguments: [node.object], 54 | __dynamic: true 55 | } as Node; 56 | }; 57 | if (node.object.name=='parent') { 58 | node.object = { 59 | type: 'CallExpression', 60 | callee: {type: 'Identifier', name: 'dg$'}, 61 | arguments: [node.object], 62 | __dynamic: true 63 | } as Node; 64 | }; 65 | if (node.property.name == '__dynamic') node.property.name = 'undefined'; 66 | if (node.object.name=='self') { 67 | node.object = { 68 | type: 'CallExpression', 69 | callee: {type: 'Identifier', name: 'dg$'}, 70 | arguments: [node.object], 71 | __dynamic: true 72 | } as Node; 73 | }; 74 | if (node.object.name=='document') { 75 | node.object = { 76 | type: 'CallExpression', 77 | callee: {type: 'Identifier', name: 'dg$'}, 78 | arguments: [node.object], 79 | __dynamic: true 80 | } as Node; 81 | }; 82 | if (node.object.name=='globalThis') { 83 | node.object = { 84 | type: 'CallExpression', 85 | callee: {type: 'Identifier', name: 'dg$'}, 86 | arguments: [node.object], 87 | __dynamic: true 88 | } as Node; 89 | }; 90 | } 91 | if (node.object.name=='location') { 92 | node.object = { 93 | type: 'CallExpression', 94 | callee: {type: 'Identifier', name: 'dg$'}, 95 | arguments: [node.object], 96 | __dynamic: true 97 | } as Node; 98 | }; 99 | if (node.property.name=='location' && parent.type !== "BinaryExpression" && parent.type !== "AssignmentExpression") { 100 | node.property.__dynamic = true; 101 | 102 | node.__dynamic = true; 103 | let original: any = Object.assign({}, node); 104 | 105 | node.type = "CallExpression"; 106 | node.callee = {type: 'Identifier', name: 'dg$', __dynamic: true} as Node; 107 | node.arguments = [original]; 108 | node.__dynamic = true; 109 | } 110 | } 111 | 112 | if (node.computed && config.destination !== 'worker') { 113 | node.property = { 114 | type: "CallExpression", 115 | callee: {type: 'Identifier', name: 'dp$'}, 116 | arguments: [node.property], 117 | __dynamic: true, 118 | } as Node; 119 | } 120 | 121 | //if (!['self', 'globalThis'].includes(node.object.name)) return false; 122 | 123 | //if (parent.type=='CallExpression'&&parent.callee==node) return; 124 | 125 | //if (node.object.name=='document') return node.object.name = `d$g_(${node.object.name})`; 126 | 127 | //return node.object.name = '__dynamic$'+node.object.name; 128 | } -------------------------------------------------------------------------------- /lib/global/rewrite/js/type/Property.ts: -------------------------------------------------------------------------------- 1 | // why am i doing this 2 | 3 | import { Node } from "../types"; 4 | 5 | export default function Property(node: Node, parent: Node = {} as any) { 6 | if (node.parent.type == "ObjectPattern") return; 7 | if (node.parent?.parent?.type == "AssignmentExpression") return; 8 | 9 | node.shorthand = false; 10 | } -------------------------------------------------------------------------------- /lib/global/rewrite/js/type/ThisExpression.ts: -------------------------------------------------------------------------------- 1 | import Eval from '../object/Eval'; 2 | import PostMessage from '../object/PostMessage'; 3 | import { Node } from '../types'; 4 | 5 | export default function CallExpression(node: Node, parent: Node = {} as any) { 6 | if (node.go === false) return; 7 | 8 | if (parent.type == 'CallExpression' && parent.arguments.includes(node)) return; 9 | 10 | if (parent.type !== "SequenceExpression" && parent.type !== "VariableDeclarator") return; 11 | 12 | node.type = 'CallExpression'; 13 | node.callee = {type: 'Identifier', name: 'dg$', __dynamic: true} as Node; 14 | node.__dynamic = true; 15 | node.arguments = [{type: 'ThisExpression', go: false, __dynamic: true}] as Array; 16 | } -------------------------------------------------------------------------------- /lib/global/rewrite/js/type/VariableDeclaractor.ts: -------------------------------------------------------------------------------- 1 | import { Node } from "../types"; 2 | 3 | export default function VariableDeclarator(node: Node, parent: Node = {} as any) { 4 | if (node.id.type !== 'Identifier') return false; 5 | if (node.id.__dynamic === true) return; 6 | 7 | if (node.id.name == 'location') return;// node.id.name = '__dynamic$location'; 8 | } -------------------------------------------------------------------------------- /lib/global/rewrite/js/types.ts: -------------------------------------------------------------------------------- 1 | export type Node = Object & { 2 | type: string; 3 | value: string | Node | any; 4 | name: string; 5 | callee: Node; 6 | arguments: Array; 7 | expression: Node; 8 | property: Node; 9 | operator: string; 10 | left: Node; 11 | right: Node; 12 | body: Node; 13 | param: Node; 14 | source: Node; 15 | test: Node; 16 | consequent: Node; 17 | alternate: Node; 18 | shorthand: boolean; 19 | argument: Node; 20 | declarations: Array; 21 | id: Node; 22 | init: Node; 23 | params: Array; 24 | async: boolean; 25 | generator: boolean; 26 | computed: boolean; 27 | key: Node; 28 | object: Node; 29 | start: number; 30 | end: number; 31 | loc: { 32 | start: { 33 | line: number; 34 | column: number; 35 | }; 36 | end: { 37 | line: number; 38 | column: number; 39 | }; 40 | }; 41 | range: [number, number]; 42 | raw: string; 43 | parent: Node; 44 | __dynamic: boolean; 45 | go?: boolean; 46 | } -------------------------------------------------------------------------------- /lib/global/rewrite/manifest.ts: -------------------------------------------------------------------------------- 1 | import MetaURL from "../meta/type"; 2 | import DynamicRewrites from "../rewrite"; 3 | 4 | export default class manifest { 5 | 6 | ctx; 7 | 8 | config = { 9 | rewrite: [ 10 | ['icons', 'urlit'], 11 | ['name', ' - Dynamic'], 12 | ['start_url', 'url'], 13 | ['scope', 'url'], 14 | ['short_name', ' - Dynamic'], 15 | ['shortcuts', 'urlev'], 16 | ], 17 | delete: [ 18 | 'serviceworker' 19 | ] 20 | } 21 | 22 | constructor(ctx: DynamicRewrites) { 23 | this.ctx = ctx.ctx; 24 | } 25 | 26 | rewrite(this: manifest, src: string, meta: MetaURL) { 27 | const manifest = JSON.parse(src); 28 | 29 | for (let config in this.config) { 30 | if (config == 'rewrite') { 31 | for (var [name, action] of this.config[config]) { 32 | if (action == 'urlit' && manifest[name]) { 33 | for (var i = 0; i < manifest[name].length; i++) { 34 | manifest[name][i].src = this.ctx.url.encode(manifest[name][i].src, meta); 35 | } 36 | 37 | continue; 38 | } 39 | 40 | if (action == 'urlev' && manifest[name]) { 41 | for (var i = 0; i < manifest[name].length; i++) { 42 | manifest[name][i].url = this.ctx.url.encode(manifest[name][i].url, meta); 43 | } 44 | 45 | continue; 46 | } 47 | 48 | if (action == 'url' && manifest[name]) { 49 | manifest[name] = this.ctx.url.encode(manifest[name], meta); 50 | 51 | continue; 52 | } 53 | 54 | if (action == 'url' || action == 'urlit' || action == 'urlev') continue; 55 | 56 | manifest[name] = manifest[name] + action; 57 | } 58 | } else if (config == 'delete') { 59 | for (var name of this.config[config]) { 60 | if (manifest[name]) delete manifest[name]; 61 | } 62 | } 63 | } 64 | 65 | return JSON.stringify(manifest) as string; 66 | } 67 | } -------------------------------------------------------------------------------- /lib/global/url.ts: -------------------------------------------------------------------------------- 1 | import Encode from './url/encode'; 2 | import Decode from './url/decode'; 3 | import { DynamicBundle } from './bundle'; 4 | 5 | class DynamicUrlRewriter { 6 | encode: Function = Encode; 7 | decode: Function = Decode; 8 | 9 | ctx: DynamicBundle; 10 | 11 | constructor(ctx: DynamicBundle) { 12 | this.ctx = ctx; 13 | } 14 | } 15 | 16 | export default DynamicUrlRewriter; -------------------------------------------------------------------------------- /lib/global/url/decode.ts: -------------------------------------------------------------------------------- 1 | import DynamicUrlRewriter from "../url"; 2 | 3 | declare const self: any; 4 | 5 | export default function decode(this: DynamicUrlRewriter, url: string | URL) { 6 | if (!url) return url; 7 | 8 | url = new String(url).toString(); 9 | 10 | if (url.match(this.ctx.regex.BypassRegex)) return url; 11 | 12 | var index = url.indexOf(this.ctx.config.prefix); 13 | 14 | if(index == -1) 15 | return url; 16 | 17 | try { 18 | url = new URL(url, new URL(self.location.origin)).href; 19 | 20 | index = url.indexOf(this.ctx.config.prefix); 21 | 22 | if (url.slice(index + this.ctx.config.prefix.length).trim() == 'about:blank') 23 | return 'about:blank'; 24 | 25 | var search = (new URL(url).search + new URL(url).hash) || ''; 26 | var base = new URL(this.ctx.encoding.decode(url.slice(index + this.ctx.config.prefix.length) 27 | .replace('https://', 'https:/') 28 | .replace('https:/', 'https://').split('?')[0])); 29 | } catch(e) { 30 | return url; 31 | } 32 | 33 | url = base.origin + base.pathname + search + (new URL(url).search ? base.search.replace('?', '&') : base.search); 34 | 35 | return url; 36 | } -------------------------------------------------------------------------------- /lib/global/url/encode.ts: -------------------------------------------------------------------------------- 1 | import MetaURL from "../meta/type"; 2 | import DynamicUrlRewriter from "../url"; 3 | 4 | export default function encode(this: DynamicUrlRewriter, url: URL | string | any, meta: MetaURL) { 5 | if (!url) return url; 6 | url = new String(url).toString(); 7 | 8 | if (url.startsWith('about:blank')) return location.origin + this.ctx.config.prefix + url; 9 | 10 | if (!url.match(this.ctx.regex.ProtocolRegex) && url.match(/^([a-zA-Z0-9\-]+)\:\/\//g)) return url; 11 | if (url.startsWith('chrome-extension://')) return url; 12 | 13 | if(url.startsWith('javascript:') 14 | && !url.startsWith('javascript:__dynamic$eval') // for some reason the tag gets called multiple times 15 | ) 16 | { 17 | let urlData = new URL(url); 18 | 19 | return `javascript:__dynamic$eval(${JSON.stringify(urlData.pathname)})` 20 | } 21 | 22 | if (url.match(this.ctx.regex.WeirdRegex)) { 23 | var data = this.ctx.regex.WeirdRegex.exec(url); 24 | 25 | if (data) url = data[2]; 26 | } 27 | 28 | if (url.startsWith(location.origin+this.ctx.config.prefix) || url.startsWith(this.ctx.config.prefix)) return url; 29 | if (url.startsWith(location.origin+this.ctx.config.assets.prefix+'dynamic.')) return url; 30 | if (url.match(this.ctx.regex.BypassRegex)) return url; 31 | 32 | if (url.match(this.ctx.regex.DataRegex)) { 33 | try { 34 | var data = this.ctx.regex.DataRegex.exec(url); 35 | 36 | if (data) { 37 | var [_, type, charset, base64, content] = data; 38 | 39 | if (base64=='base64') 40 | content = (this.ctx.modules.base64.atob(decodeURIComponent(content))); 41 | else 42 | content = decodeURIComponent(content); 43 | 44 | if (type) { 45 | if (type=='text/html') { 46 | content = this.ctx.rewrite.html.rewrite(content, meta, this.ctx.rewrite.html.generateHead(location.origin+'/dynamic/dynamic.client.js', location.origin+'/dynamic/dynamic.config.js', '', `window.__dynamic$url = "${meta.href}"; window.__dynamic$parentURL = "${location.href}";`)); 47 | } else if (type=='text/css') { 48 | content = this.ctx.rewrite.css.rewrite(content, meta); 49 | } else if (type=='text/javascript'||type=='application/javascript') { 50 | content = this.ctx.rewrite.js.rewrite(content, meta); 51 | } 52 | } 53 | 54 | if (base64=='base64') 55 | content = this.ctx.modules.base64.btoa(content); 56 | else 57 | content = encodeURIComponent(content); 58 | 59 | if (charset) { 60 | if (base64) 61 | url = `data:${type};${charset};${base64},${content}`; 62 | else 63 | url = `data:${type};${charset},${content}`; 64 | } else { 65 | if (base64) 66 | url = `data:${type};${base64},${content}`; 67 | else 68 | url = `data:${type},${content}`; 69 | } 70 | } 71 | } catch {}; 72 | 73 | return url; 74 | } 75 | 76 | url = new String(url).toString(); 77 | 78 | if (meta.href.match(this.ctx.regex.BypassRegex)) ( 79 | url = new URL(url, new URL((this.ctx.parent.__dynamic || this.ctx).meta.href)).href 80 | ); 81 | 82 | url = new URL(url, meta.href); 83 | 84 | return (this.ctx._location?.origin||(location.origin=='null'?location.ancestorOrigins[0]:location.origin))+this.ctx.config.prefix+(this.ctx.encoding.encode(url.origin + url.pathname) + url.search + url.hash); 85 | } 86 | -------------------------------------------------------------------------------- /lib/global/util.ts: -------------------------------------------------------------------------------- 1 | import { route, routePath } from './util/route'; 2 | import path from './util/path'; 3 | import resHeader from './util/resHeader'; 4 | import reqHeader from './util/reqHeader'; 5 | import clone from './util/clone'; 6 | import Class from './util/class'; 7 | import file from './util/file'; 8 | import edit from './util/edit'; 9 | import error from './util/error'; 10 | import about from './util/about'; 11 | import encode from './util/encode'; 12 | import rewritePath from './util/rewritePath'; 13 | import { DynamicBundle } from './client'; 14 | 15 | class DynamicUtil { 16 | route: Function = route; 17 | routePath: Function = routePath; 18 | path: Function = path; 19 | resHeader: Function = resHeader; 20 | reqHeader: Function = reqHeader; 21 | clone: Function = clone; 22 | class: Function = Class; 23 | file: Function = file; 24 | edit: Function = edit; 25 | error: Function = error; 26 | encode: Function = encode; 27 | rewritePath: Function = rewritePath; 28 | 29 | about = about; 30 | 31 | ctx: DynamicBundle & { encoding: any }; 32 | 33 | constructor(ctx: DynamicBundle) { 34 | this.ctx = ctx; 35 | } 36 | } 37 | 38 | export default DynamicUtil; -------------------------------------------------------------------------------- /lib/global/util/about.ts: -------------------------------------------------------------------------------- 1 | export default class about { 2 | rawHeaders = {}; 3 | headers = new Headers({}); 4 | status = 200; 5 | statusText = 'OK'; 6 | 7 | body: Blob; 8 | 9 | constructor(blob: Blob) { 10 | this.body = blob; 11 | } 12 | 13 | async blob() { 14 | return this.body; 15 | } 16 | 17 | async text() { 18 | return await this.body.text(); 19 | } 20 | } -------------------------------------------------------------------------------- /lib/global/util/class.ts: -------------------------------------------------------------------------------- 1 | export default function Class(obj: any) { 2 | try { 3 | new (new Proxy(obj, { construct: () => ({}) })); 4 | 5 | if (!Object.getOwnPropertyNames(obj).includes('arguments')) throw new Error(""); 6 | 7 | return true; 8 | } catch (err) { 9 | return false; 10 | } 11 | }; -------------------------------------------------------------------------------- /lib/global/util/clone.ts: -------------------------------------------------------------------------------- 1 | export default function copyInstance(original: any) { 2 | var copied: Object = Object.assign( 3 | Object.create( 4 | Object.getPrototypeOf(original) 5 | ), 6 | original 7 | ); 8 | 9 | return copied; 10 | } -------------------------------------------------------------------------------- /lib/global/util/edit.ts: -------------------------------------------------------------------------------- 1 | declare const self: any; 2 | 3 | export default async function Edit(req: Request) { 4 | let request: Response; 5 | 6 | if (self.__dynamic$config.mode !== 'development') { 7 | var cache = await caches.open('__dynamic$files'); 8 | 9 | if (!cache) request = await fetch(req); 10 | else 11 | request = await cache.match(req.url) || await fetch(req); 12 | } else request = await fetch(req); 13 | let text = await request.blob(); 14 | 15 | if (req.url.startsWith(location.origin + '/dynamic/dynamic.config.js') || req.url.startsWith(location.origin + '/dynamic/dynamic.client.js')) { 16 | text = new Blob([`${await text.text()}\nself.document?.currentScript?.remove();`], {type: 'application/javascript'}); 17 | } 18 | 19 | return new Response(text, { 20 | headers: request.headers, 21 | status: request.status, 22 | statusText: request.statusText 23 | }); 24 | } -------------------------------------------------------------------------------- /lib/global/util/encode.ts: -------------------------------------------------------------------------------- 1 | import DynamicUtil from "../util"; 2 | 3 | export default function encode(this: DynamicUtil, self: Window | any) { 4 | var obj = this.ctx.encoding; 5 | 6 | if (typeof this.ctx.config.encoding == 'object') { 7 | obj = { 8 | ...obj, 9 | ...this.ctx.encoding, 10 | } 11 | } else { 12 | obj = { 13 | ...this.ctx.encoding[this.ctx.config.encoding], 14 | } 15 | } 16 | 17 | this.ctx.encoding = { 18 | ...this.ctx.encoding, 19 | ...obj, 20 | } 21 | 22 | return this.ctx.encoding; 23 | } -------------------------------------------------------------------------------- /lib/global/util/error.ts: -------------------------------------------------------------------------------- 1 | export default async function Error(request: Request, error: Error) { 2 | 3 | } -------------------------------------------------------------------------------- /lib/global/util/file.ts: -------------------------------------------------------------------------------- 1 | declare const self: any; 2 | 3 | export default function File(req: Request) { 4 | return req.url.toString().substr(location.origin.length, req.url.toString().length).startsWith(self.__dynamic$config.assets.prefix); 5 | }; -------------------------------------------------------------------------------- /lib/global/util/path.ts: -------------------------------------------------------------------------------- 1 | import DynamicUtil from "../util"; 2 | 3 | export default function path(this: DynamicUtil, { url }: Request) { 4 | return !(url.toString().substr(location.origin.length, this.ctx.config.prefix.length).startsWith(this.ctx.config.prefix)); 5 | } -------------------------------------------------------------------------------- /lib/global/util/reqHeader.ts: -------------------------------------------------------------------------------- 1 | import MetaURL from "../meta/type"; 2 | import DynamicUtil from "../util"; 3 | 4 | export default function Header(this: DynamicUtil, headers: Object | any, meta: MetaURL, request: Request & { client: any }, cookies: string) { 5 | let { referrer }: any = request; 6 | 7 | [ 8 | 'origin', 9 | 'Origin', 10 | 'host', 11 | 'Host', 12 | 'referer', 13 | 'Referer' 14 | ].forEach((header: string) => { 15 | if (headers[header]) delete headers[header]; 16 | }); 17 | 18 | headers['Origin'] = `${meta.protocol}//${meta.host}${meta.port ? ':'+meta.port : ''}`; 19 | headers['Host'] = meta.host + (meta.port ? ':'+meta.port : ''); 20 | headers['Referer'] = meta.href; 21 | 22 | if (request.referrerPolicy == 'strict-origin-when-cross-origin') headers['Referer'] = `${meta.protocol}//${meta.host}/`; 23 | 24 | if (request.referrerPolicy == 'origin' && meta.origin) { 25 | referrer = meta.origin+'/'; 26 | } 27 | 28 | if (cookies) { 29 | switch(request.credentials) { 30 | case 'omit': 31 | break; 32 | case 'same-origin': 33 | if (request.client) if (meta.origin == request.client.__dynamic$location.origin) headers['Cookie'] = cookies; 34 | if (!request.client) headers['Cookie'] = cookies; 35 | break; 36 | case 'include': 37 | headers['Cookie'] = cookies; 38 | break; 39 | default: 40 | break; 41 | } 42 | headers['Cookie'] = cookies; 43 | } 44 | 45 | if (referrer && referrer != location.origin+'/') { 46 | try { 47 | headers['Referer'] = this.ctx.url.decode(referrer); 48 | if (request.referrerPolicy=='strict-origin-when-cross-origin') headers['Referer'] = new URL(this.ctx.url.decode(referrer)).origin; 49 | headers['Origin'] = new URL(this.ctx.url.decode(referrer)).origin; 50 | } catch {} 51 | } 52 | 53 | if (request.client) { 54 | headers['Origin'] = request.client.__dynamic$location.origin; 55 | headers['Referer'] = request.client.__dynamic$location.href; 56 | 57 | if (request.referrerPolicy=='strict-origin-when-cross-origin') headers['Referer'] = request.client.__dynamic$location.origin; 58 | } 59 | 60 | if (this.ctx.config.tab) { 61 | if (this.ctx.config.tab.ua) { 62 | delete headers['user-agent']; 63 | delete headers['User-Agent']; 64 | 65 | headers['user-agent'] = this.ctx.config.tab.ua; 66 | } 67 | } 68 | 69 | headers['sec-fetch-dest'] = request.destination || 'empty'; 70 | headers['sec-fetch-mode'] = request.mode || 'cors'; 71 | headers['sec-fetch-site'] = request.client ? request.client.__dynamic$location.origin == meta.origin ? request.client.__dynamic$location.port == meta.port ? 'same-origin' : 'same-site' : 'cross-origin' : 'none'; 72 | if (request.mode == 'navigate') headers['sec-fetch-site'] = 'same-origin'; 73 | headers['sec-fetch-user'] = '?1'; 74 | 75 | return new Headers(headers); 76 | } -------------------------------------------------------------------------------- /lib/global/util/resHeader.ts: -------------------------------------------------------------------------------- 1 | import Cookie from "../cookie"; 2 | import MetaURL from "../meta/type"; 3 | import DynamicUtil from "../util"; 4 | 5 | export default async function Header(this: DynamicUtil, headers: Object | any, meta: MetaURL, Cookies: Cookie) { 6 | 7 | for (const header in headers) { 8 | if (this.ctx.headers.csp.indexOf(header.toLowerCase())!==-1) delete headers[header]; 9 | 10 | if (header.toLowerCase() == 'location') { 11 | headers[header] = this.ctx.url.encode(headers[header], meta); 12 | 13 | continue; 14 | } 15 | 16 | if (header.toLowerCase() === 'set-cookie') { 17 | if (!Array.isArray(headers[header])) headers[header] = this.ctx.modules.setCookieParser(headers[header], {decodeValues: false}); else headers[header] = headers[header].map((e: any)=>this.ctx.modules.setCookieParser(e, {decodeValues: false})[0]); 18 | 19 | for await (var cookie of headers[header]) { 20 | await Cookies.set(meta.host, this.ctx.modules.cookie.serialize(cookie.name, cookie.value, {...cookie, encode: (e:any) => e})); 21 | 22 | continue; 23 | } 24 | 25 | delete headers[header]; 26 | 27 | continue; 28 | } 29 | } 30 | 31 | return new Headers(headers); 32 | } -------------------------------------------------------------------------------- /lib/global/util/rewritePath.ts: -------------------------------------------------------------------------------- 1 | import MetaURL from "../meta/type"; 2 | import DynamicUtil from "../util"; 3 | 4 | export default function rewritePath(this: DynamicUtil, request: Request, client: Object | any, meta: MetaURL | URL) { 5 | if (!request.url.startsWith('http')) return request.url; 6 | 7 | let url: any = request.url.toString(); 8 | 9 | if (request.url.startsWith(location.origin)) url = url.substr(self.location.origin.length); 10 | 11 | url = new URL(url, new URL(client.__dynamic$location.href)).href; 12 | 13 | return this.ctx.url.encode(url, meta); 14 | } -------------------------------------------------------------------------------- /lib/global/util/route.ts: -------------------------------------------------------------------------------- 1 | import DynamicUtil from "../util"; 2 | 3 | async function route(this: DynamicUtil, request: Request) { 4 | var url; 5 | 6 | if (request.method === "GET") { 7 | var parsed = new URL(request.url); 8 | url = parsed.searchParams.get('url'); 9 | } else if (request.method === "POST") { 10 | const formData = await request.formData(); 11 | 12 | url = formData.get('url'); 13 | 14 | if (url === null) { 15 | var parsed = new URL(request.url); 16 | url = parsed.searchParams.get('url'); 17 | } 18 | 19 | if (!url) return new Response('Error: Invalid or Unfound url', {status: 400}); 20 | } else { 21 | return new Response('Error: Invalid method', {status: 405}); 22 | } 23 | 24 | return new Response('', {status: 301, headers: {location: location.origin+this.ctx.config.prefix+this.ctx.encoding.encode(url)}}); 25 | } 26 | 27 | function routePath(this: any, { url }: Request) { 28 | return !(url.toString().substr(location.origin.length, (this.ctx.config.prefix+'route').length).startsWith(this.ctx.config.prefix+'route')); 29 | } 30 | 31 | export { route, routePath }; -------------------------------------------------------------------------------- /lib/handler/index.ts: -------------------------------------------------------------------------------- 1 | import { DynamicBundle } from '../global/client'; 2 | importScripts('/dynamic/dynamic.config.js'); 3 | 4 | import init from '../global/client/methods/init'; 5 | import wrap from '../global/client/methods/wrap'; 6 | 7 | (function(self: Window | any) { 8 | const __dynamic: DynamicBundle = new DynamicBundle(self.__dynamic$config); 9 | self.__dynamic = __dynamic; 10 | 11 | const __dynamic$baseURL: string = __dynamic.url.decode(location.pathname); 12 | 13 | __dynamic.meta.load(new URL(__dynamic$baseURL)); 14 | 15 | init(self, null), wrap(self); 16 | 17 | __dynamic.client.message(self); 18 | __dynamic.client.location(self, false); 19 | __dynamic.client.window(self); 20 | __dynamic.client.get(self); 21 | __dynamic.client.reflect(self); 22 | __dynamic.client.imports(self); 23 | __dynamic.client.blob(self); 24 | })(self); -------------------------------------------------------------------------------- /lib/html/index.ts: -------------------------------------------------------------------------------- 1 | import Srcset from '../global/rewrite/html/srcset'; 2 | import Node from '../global/rewrite/html/nodewrapper'; 3 | import MetaURL from '../global/meta/type'; 4 | import generateHead from '../global/rewrite/html/generateHead'; 5 | import { Element } from 'parse5/dist/tree-adapters/default'; 6 | import * as parse5 from 'parse5'; 7 | 8 | (self as any).html = class html { 9 | 10 | ctx; 11 | 12 | generateHead = generateHead; 13 | 14 | config = [ 15 | { 16 | "elements": "all", 17 | "tags": ['style'], 18 | "action": "css" 19 | }, 20 | { 21 | "elements": ['script', 'iframe', 'embed', 'input', 'track', 'media', 'source', 'img'], 22 | "tags": ['src'], 23 | "action": "url" 24 | }, 25 | { 26 | "elements": ['source', 'img'], 27 | "tags": ['srcset'], 28 | "action": "srcset" 29 | }, 30 | { 31 | "elements": ['a', 'link', 'area'], 32 | "tags": ['href'], 33 | "action": "url" 34 | }, 35 | { 36 | "elements": ['form'], 37 | "tags": ['action'], 38 | "action": "url" 39 | }, 40 | { 41 | "elements": ['object'], 42 | "tags": ['data'], 43 | "action": "url", 44 | }, 45 | { 46 | "elements": ['script', 'link'], 47 | "tags": ['integrity'], 48 | "action": "rewrite", 49 | "new": "nointegrity", 50 | }, 51 | { 52 | "elements": ['script', 'link'], 53 | "tags": ['nonce'], 54 | "action": "rewrite", 55 | "new": "nononce", 56 | }, 57 | { 58 | "elements": ['meta'], 59 | "tags": ['http-equiv'], 60 | "action": "http-equiv", 61 | }, 62 | { 63 | "elements": ['iframe'], 64 | "tags": ['srcdoc'], 65 | "action": "html", 66 | }, 67 | { 68 | "elements": ['link'], 69 | "tags": ["imagesrcset"], 70 | "action": "srcset", 71 | }, 72 | { 73 | "elements": 'all', 74 | "tags": ['onclick'], 75 | "action": "js", 76 | } 77 | ]; 78 | 79 | constructor(ctx:any) { 80 | this.ctx = ctx.ctx; 81 | } 82 | 83 | generateRedirect(url:any) { 84 | return ` 85 | 86 | 301 Moved 87 |

301 Moved

88 | The document has moved 89 | here. 90 | 91 | ` 92 | } 93 | 94 | iterate(_dom: any, cb: any) { 95 | function it(dom: any = _dom) { 96 | for (var i = 0; i]*>/g) && src.match(/<\!DOCTYPE[^>]*>/gi)) return src; 118 | 119 | var ast = parse5.parse(src, {}); 120 | 121 | var nodes: Array = []; 122 | 123 | this.iterate(ast, (node: Element) => nodes.push(node)); 124 | 125 | nodes = nodes.map((e: any) => (e.attribs = {}, e.attrs?e.attrs.map(({name, value}: any)=>e.attribs[name]=value):null, e)); 126 | 127 | if (nodes.find(e=>e.nodeName=='base')) { 128 | var base: URL | string = new URL(nodes.find(e=>e.nodeName=='base').attribs['href'], new URL(meta.href)).href; 129 | } else { 130 | var base: URL | string = meta.href; 131 | } 132 | 133 | base = new URL(base); 134 | 135 | for (var node of nodes) { 136 | var rewritten = new Node(node, that.ctx); 137 | 138 | if (node.nodeName == 'base') { 139 | rewritten.setAttribute('data-dynamic_href', rewritten.getAttribute('href')); 140 | rewritten.setAttribute('href', this.ctx.url.encode(rewritten.getAttribute('href'), meta)); 141 | } 142 | 143 | if (node.nodeName == 'script') { 144 | if (meta.href == 'about:blank') node.attribs.defer = "true"; 145 | 146 | if (!rewritten.getAttribute('src') && (rewritten.getAttribute('type') !== 'application/json')) { 147 | node.childNodes.forEach(( script: Element & { value: string } ) => { 148 | if (script.nodeName!=='#text') return script; 149 | if (rewritten.getAttribute('type') && rewritten.getAttribute('type')!=='application/javascript' && rewritten.getAttribute('type')!=='text/javascript' && rewritten.getAttribute('type')!=='module') return e; 150 | 151 | script.value = that.ctx.rewrite.js.rewrite(script.value, {type: 'script'}, false, that.ctx); 152 | }); 153 | } 154 | } 155 | 156 | if (node.nodeName == 'style') { 157 | node.childNodes.forEach(( style: Element & { value: string } )=>{ 158 | if (style.nodeName !== '#text') return e; 159 | 160 | style.value = that.ctx.rewrite.css.rewrite(style.value, base); 161 | }); 162 | } 163 | 164 | for (var config of that.config) { 165 | if (config.elements === 'all' || config.elements.indexOf(node.nodeName) > -1) { 166 | for (var tag of config.tags) { 167 | if (!rewritten.hasAttribute(tag) || !rewritten.getAttribute(tag)) continue; 168 | 169 | if (node.tagName == 'link' && (rewritten.getAttribute('rel') == 'icon' || rewritten.getAttribute('rel') == 'shortcut icon') && this.ctx.config.tab?.icon) { 170 | rewritten.setAttribute(`data-dynamic_${tag}`, rewritten.getAttribute(tag)); 171 | rewritten.setAttribute('href', this.ctx.url.encode(this.ctx.config.tab.icon, base)); 172 | 173 | continue; 174 | } 175 | 176 | if (config.action === 'url') { 177 | rewritten.setAttribute(`data-dynamic_${tag}`, rewritten.getAttribute(tag)); 178 | if (!rewritten.getAttribute(tag).match(that.ctx.regex.ProtocolRegex) && rewritten.getAttribute(tag).match(/^([a-zA-Z0-9\-]+)\:\/\//g)) continue; 179 | rewritten.setAttribute(tag, that.ctx.url.encode(rewritten.getAttribute(tag), base)); 180 | } else if (config.action === 'srcset') { 181 | rewritten.setAttribute(`data-dynamic_${tag}`, rewritten.getAttribute(tag)); 182 | rewritten.setAttribute(tag, Srcset.encode(rewritten.getAttribute(tag), that.ctx)); 183 | } else if (config.action === 'rewrite') { 184 | rewritten.setAttribute(config.new as any, rewritten.getAttribute(tag)); 185 | rewritten.removeAttribute(tag); 186 | } else if (config.action === 'html') { 187 | rewritten.setAttribute(`data-dynamic_${tag}`, rewritten.getAttribute(tag)); 188 | rewritten.removeAttribute(tag); 189 | 190 | const blob = new Blob([that.ctx.rewrite.html.rewrite(rewritten.getAttribute(tag), base)], {type: 'text/html'}); 191 | rewritten.setAttribute('src', URL.createObjectURL(blob)); 192 | } else if (config.action === 'http-equiv') { 193 | const content = rewritten.getAttribute('content'); 194 | const name = rewritten.getAttribute('http-equiv'); 195 | 196 | switch(name.toLowerCase()) { 197 | case "refresh": 198 | var time = content.split('url=')[0].split(';')[0], value = content.split('url=')[1]; 199 | 200 | rewritten.setAttribute('content', `${time};url=${that.ctx.url.encode(value, base)}`); 201 | break; 202 | case "content-security-policy": 203 | rewritten.removeAttribute('content'); 204 | rewritten.removeAttribute('http-equiv'); 205 | break; 206 | default: 207 | break; 208 | } 209 | } else if (config.action === 'css') { 210 | rewritten.setAttribute(`data-dynamic_${tag}`, rewritten.getAttribute(tag)); 211 | rewritten.setAttribute(tag, that.ctx.rewrite.css.rewrite(rewritten.getAttribute(tag), base)); 212 | } else if (config.action === 'delete') { 213 | rewritten.removeAttribute(tag); 214 | } else if (config.action === 'js') { 215 | rewritten.setAttribute(tag, that.ctx.rewrite.js.rewrite(rewritten.getAttribute(tag), {type: 'script'}, false, that.ctx)); 216 | } 217 | } 218 | } 219 | }; 220 | } 221 | 222 | if (head && ast.childNodes.length && head.length) { 223 | var html: any = ast.childNodes.find((e: any) => e.nodeName == 'html'); 224 | 225 | for (var e = 0; e < head.length; e++) { 226 | if (html) { 227 | html.childNodes.unshift(head[e]); 228 | continue; 229 | } 230 | 231 | ast.childNodes.unshift(head[e]); 232 | } 233 | } 234 | 235 | src = parse5.serialize(ast as any) as string; 236 | 237 | return src; 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /lib/types.d.ts: -------------------------------------------------------------------------------- 1 | declare module '@dynamic-pkg/bare-client'; 2 | declare module '@dynamic-pkg/acorn'; 3 | declare module '@dynamic-pkg/astring'; 4 | declare module '@dynamic-pkg/cookie'; 5 | declare module '@dynamic-pkg/mime'; 6 | declare module '@dynamic-pkg/base64'; 7 | declare module '@dynamic-pkg/mutation'; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@nebula-services/dynamic", 3 | "version": "0.7.2-patch.2", 4 | "description": "The new generation of interception proxies.", 5 | "main": "./bin/index.cjs", 6 | "types": "./bin/index.d.ts", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/NebulaServices/Dynamic.git" 10 | }, 11 | "scripts": { 12 | "start": "node --max-http-header-size=50000 index", 13 | "build:dev": "node esbuild.dev.js", 14 | "build:prod": "node esbuild.prod.js", 15 | "build": "node esbuild.prod.js", 16 | "webpack": "echo 'Webpack building is no longer a supported build utility.'", 17 | "release": "npm run build && npm publish --access public" 18 | }, 19 | "keywords": [], 20 | "author": "", 21 | "license": "LGPL-2.0-only", 22 | "dependencies": { 23 | "@dynamic-pkg/mime": "^1.0.1", 24 | "@dynamic-pkg/mutation": "^1.0.0", 25 | "@fastify/compress": "^6.4.0", 26 | "@fastify/static": "^6.10.2", 27 | "@tomphttp/bare-client": "^2.2.0-alpha", 28 | "@tomphttp/bare-server-node": "^2.0.1", 29 | "acorn": "^8.10.0", 30 | "astring": "^1.8.6", 31 | "chalk": "^5.3.0", 32 | "cookie": "^0.5.0", 33 | "crypto-js": "^4.2.0", 34 | "domhandler": "^5.0.3", 35 | "esbuild": "^0.19.0", 36 | "fastify": "^4.21.0", 37 | "git-commit-info": "^2.0.2", 38 | "idb": "^7.0.2", 39 | "open": "^9.1.0", 40 | "parse5": "^7.1.2", 41 | "path-browserify": "^1.0.1", 42 | "set-cookie-parser": "^2.6.0" 43 | }, 44 | "type": "module", 45 | "devDependencies": { 46 | "@types/cookie": "^0.5.1", 47 | "@types/crypto-js": "^4.1.1", 48 | "@types/mime-db": "^1.43.1", 49 | "@types/path-browserify": "^1.0.0", 50 | "@types/set-cookie-parser": "^2.4.2", 51 | "execa": "^8.0.1", 52 | "ts-node": "^10.8.1", 53 | "typescript": "^5.1.6" 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dynamic 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 32 | 33 | 34 | 35 |

Dynamic

36 |
37 | 38 |
39 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /static/resources/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NebulaServices/Dynamic/0783cd628049089dae3fd773e93bc36a816d0f96/static/resources/img/logo.png -------------------------------------------------------------------------------- /static/resources/scripts/index.js: -------------------------------------------------------------------------------- 1 | let workerLoaded; 2 | 3 | async function worker() { 4 | return await navigator.serviceWorker.register("/sw.js", { 5 | scope: "/service", 6 | }); 7 | } 8 | 9 | document.addEventListener('DOMContentLoaded', async function(){ 10 | await worker(); 11 | workerLoaded = true; 12 | }) 13 | 14 | function prependHttps(url) { 15 | if (!url.startsWith('http://') && !url.startsWith('https://')) { 16 | return 'https://' + url; 17 | } 18 | return url; 19 | } 20 | 21 | function isUrl(val = "") { 22 | const urlPattern = /^(http(s)?:\/\/)?([\w-]+\.)+[\w]{2,}(\/.*)?$/; 23 | return urlPattern.test(val); 24 | } 25 | 26 | const inpbox = document.getElementById("uform"); 27 | inpbox.addEventListener("submit", async (event) => { 28 | event.preventDefault(); 29 | console.log("Connecting to service -> loading"); 30 | if (typeof navigator.serviceWorker === "undefined") { 31 | alert( 32 | "An error occurred registering your service worker. Please contact support - discord.gg/unblocker" 33 | ); 34 | } 35 | if (!workerLoaded) { 36 | await worker(); 37 | } 38 | 39 | const form = document.querySelector("form"); 40 | const formValue = document.querySelector("form input").value; 41 | const url = isUrl(formValue) ? prependHttps(formValue) : 'https://www.google.com/search?q=' + encodeURIComponent(formValue); 42 | 43 | location.href = form.action + "?url=" + encodeURIComponent(url); 44 | }); 45 | -------------------------------------------------------------------------------- /static/resources/scripts/notice.js: -------------------------------------------------------------------------------- 1 | const delay = ms => new Promise(res => setTimeout(res, ms)); 2 | 3 | 4 | async function greet(){ 5 | const style = 'background-color: black; color: white; font-style: italic; border: 5px solid red; font-size: 2em; margin-top: -12px;' 6 | let visited = localStorage.getItem('visited') 7 | await delay(500); 8 | console.log("%cPlease, do not put anything in this developer console. You risk your data.", style) 9 | await delay(500); 10 | if (!visited) { 11 | console.log('showing warning') 12 | alert('Hello! Thanks for using Dynamic.\nPlease be aware that this is a public beta version of Dynamic. Please report bugs to our GitHub issues page :)\n\n(we will only show you this announcement once.)') 13 | } 14 | localStorage.setItem("visited", "true") 15 | } 16 | greet() -------------------------------------------------------------------------------- /static/resources/scripts/settings.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | class Modal { 3 | 4 | constructor() { 5 | this.triggers = document.querySelectorAll('.js-modal'); 6 | this.close = document.querySelectorAll('.js-close-modal'); 7 | this.modals = document.querySelectorAll('.modal'); 8 | this.modalInners = document.querySelectorAll('.modal-inner'); 9 | 10 | this.listeners(); 11 | } 12 | 13 | listeners() { 14 | window.addEventListener('keydown', this.keyDown); 15 | 16 | this.triggers.forEach(el => { 17 | el.addEventListener('click', this.openModal, false); 18 | }); 19 | 20 | this.modals.forEach(el => { 21 | el.addEventListener('transitionend', this.revealModal, false); 22 | el.addEventListener('click', this.backdropClose, false); 23 | }); 24 | 25 | this.close.forEach(el => { 26 | el.addEventListener('click', Modal.hideModal, false); 27 | }); 28 | 29 | this.modalInners.forEach(el => { 30 | el.addEventListener('transitionend', this.closeModal, false); 31 | }); 32 | } 33 | 34 | keyDown(e) { 35 | if (27 === e.keyCode && document.body.classList.contains('modal-body')) { 36 | Modal.hideModal(); 37 | } 38 | } 39 | 40 | backdropClose(el) { 41 | if (!el.target.classList.contains('modal-visible')) { 42 | return; 43 | } 44 | 45 | let backdrop = el.currentTarget.dataset.backdrop !== undefined ? el.currentTarget.dataset.backdrop : true; 46 | 47 | if (backdrop === true) { 48 | Modal.hideModal(); 49 | } 50 | } 51 | 52 | static hideModal() { 53 | let modalOpen = document.querySelector('.modal.modal-visible'); 54 | 55 | modalOpen.querySelector('.modal-inner').classList.remove('modal-reveal'); 56 | document.querySelector('.modal-body').addEventListener('transitionend', Modal.modalBody, false); 57 | document.body.classList.add('modal-fadeOut'); 58 | } 59 | 60 | closeModal(el) { 61 | if ('opacity' === el.propertyName && !el.target.classList.contains('modal-reveal')) { 62 | document.querySelector('.modal.modal-visible').classList.remove('modal-visible'); 63 | } 64 | } 65 | 66 | openModal(el) { 67 | if (!el.currentTarget.dataset.modal) { 68 | console.error('No data-modal attribute defined!'); 69 | return; 70 | } 71 | 72 | let modalID = el.currentTarget.dataset.modal; 73 | let modal = document.getElementById(modalID); 74 | 75 | document.body.classList.add('modal-body'); 76 | modal.classList.add('modal-visible'); 77 | } 78 | 79 | revealModal(el) { 80 | if ('opacity' === el.propertyName && el.target.classList.contains('modal-visible')) { 81 | el.target.querySelector('.modal-inner').classList.add('modal-reveal'); 82 | } 83 | } 84 | 85 | static modalBody(el) { 86 | if ('opacity' === el.propertyName && el.target.classList.contains('modal') && !el.target.classList.contains('modal-visible')) { 87 | document.body.classList.remove('modal-body', 'modal-fadeOut'); 88 | } 89 | }} 90 | new Modal(); 91 | 92 | window.addEventListener('DOMContentLoaded', function (){ 93 | 94 | const versionInd = document.getElementById('settings-version') 95 | const xhr = new XMLHttpRequest(); 96 | xhr.open("GET", '/info'); 97 | xhr.send(); 98 | xhr.responseType = "json"; 99 | xhr.onload = () => { 100 | if (xhr.readyState == 4 && xhr.status == 200) { 101 | const response = xhr.response; 102 | versionInd.innerHTML = `Dynamic v${response.version} (${response.hashShort}) ` 103 | const hashHover = document.getElementById('hashHover') 104 | hashHover.onclick = function displayFullHash(){ 105 | console.log('cool') 106 | hashHover.innerText = `(${response.hash})` 107 | hashHover.style.fontSize = `10px` 108 | } 109 | } else { 110 | versionInd.innerText = 'Unable to get version' 111 | } 112 | }; 113 | 114 | }) 115 | 116 | -------------------------------------------------------------------------------- /static/resources/style.css: -------------------------------------------------------------------------------- 1 | html { 2 | width: 100%; 3 | height: 100%; 4 | } 5 | body { 6 | background-color: #080808; 7 | color: #ffffff; 8 | font-family: 'Roboto', sans-serif; 9 | font-size: 16px; 10 | line-height: 1.5; 11 | margin: 0; 12 | padding: 0; 13 | width: 100%; 14 | height: 100%; 15 | display: flex; 16 | align-items: center; 17 | justify-content: center; 18 | align-content: center; 19 | flex-direction: column; 20 | position: absolute; 21 | z-index: 1; 22 | } 23 | h1 { 24 | font-size: 72px; 25 | font-weight: 700; 26 | margin: 0 0 -43px 0; 27 | font-style: italic; 28 | pointer-events: none; 29 | color: white; 30 | /* backdrop-filter: invert(1); */ 31 | } 32 | form { 33 | display: flex; 34 | flex-direction: row; 35 | align-items: flex-start; 36 | margin: 72px auto; 37 | max-width: 477px; 38 | width: 100%; 39 | justify-content: center; 40 | align-content: center; 41 | background: #000000ad; 42 | backdrop-filter: invert(1); 43 | height: 52px; 44 | border-radius: 9px; 45 | } 46 | input[name="url"] { 47 | background-color: #0f0f0fbf; 48 | border: 1px solid #ffffff24; 49 | color: #ffffff; 50 | font-size: 16px; 51 | border-radius: 9px; 52 | margin: 0 0 16px 0; 53 | font-family: 'Roboto', sans-serif; 54 | padding: 16px; 55 | text-align: center; 56 | width: 100%; 57 | outline: transparent; 58 | } 59 | input[name="url"]::placeholder { 60 | color: #bfbfbf; 61 | } 62 | input[type="submit"] { 63 | background-color: #daff46; 64 | color: black; 65 | border: none; 66 | font-size: 16px; 67 | font-weight: 700; 68 | padding: 16px; 69 | text-align: center; 70 | text-transform: uppercase; 71 | transition: background-color 0.2s ease-in-out; 72 | width: 100%; 73 | } 74 | input[type="submit"]:hover { 75 | background-color: #00c853; 76 | cursor: pointer; 77 | } 78 | 79 | 80 | svg { 81 | position: absolute; 82 | top: 0; 83 | left: 0; 84 | z-index: -1; 85 | filter: blur(97px); 86 | } 87 | 88 | 89 | .footer { 90 | display: flex; 91 | align-items: flex-end; 92 | justify-content: center; 93 | flex-direction: row; 94 | align-content: center; 95 | flex-wrap: nowrap; 96 | position: absolute; 97 | bottom: 0; 98 | width: 100%; 99 | 100 | } 101 | 102 | .copyright { 103 | position: absolute; 104 | left: 17px; 105 | } 106 | 107 | canvas { 108 | width: 100%; 109 | height: 100%; 110 | position: absolute; 111 | z-index: -2; 112 | } 113 | @-webkit-keyframes fadeIn { 114 | 0% { 115 | opacity: 0; 116 | } 117 | 100% { 118 | opacity: 1; 119 | } 120 | } 121 | @keyframes fadeIn { 122 | 0% { 123 | opacity: 0; 124 | } 125 | 100% { 126 | opacity: 1; 127 | } 128 | } 129 | @-webkit-keyframes fadeOut { 130 | 0% { 131 | opacity: 1; 132 | } 133 | 100% { 134 | opacity: 0; 135 | } 136 | } 137 | @keyframes fadeOut { 138 | 0% { 139 | opacity: 1; 140 | } 141 | 100% { 142 | opacity: 0; 143 | } 144 | } 145 | .modal-body { 146 | overflow: hidden; 147 | position: relative; 148 | } 149 | .modal-body:before { 150 | position: fixed; 151 | display: block; 152 | content: ""; 153 | top: 0px; 154 | bottom: 0px; 155 | right: 0px; 156 | left: 0px; 157 | background-color: rgba(0, 0, 0, 0.75); 158 | z-index: 10; 159 | } 160 | .modal-body:before { 161 | -webkit-animation: fadeIn 320ms ease; 162 | animation: fadeIn 320ms ease; 163 | transition: opacity ease 320ms; 164 | } 165 | .modal-body.modal-fadeOut:before { 166 | opacity: 0; 167 | } 168 | 169 | .modal { 170 | transition: all ease 0.01s; 171 | display: block; 172 | opacity: 0; 173 | height: 0; 174 | position: fixed; 175 | content: ""; 176 | top: 0; 177 | left: 0; 178 | right: 0; 179 | z-index: 999; 180 | text-align: center; 181 | overflow: hidden; 182 | overflow-y: auto; 183 | -webkit-overflow-scrolling: touch; 184 | } 185 | .modal.modal-visible { 186 | opacity: 1; 187 | height: auto; 188 | bottom: 0; 189 | } 190 | 191 | .modal-inner { 192 | transition: all ease 320ms; 193 | transform: translateY(-50px); 194 | position: relative; 195 | display: inline-block; 196 | background-color: #1a1a1a; 197 | width: 90%; 198 | max-width: 625px; 199 | opacity: 0; 200 | margin: 40px 0; 201 | border-radius: 4px; 202 | box-shadow: 0 30px 18px -20px #020202; 203 | } 204 | .modal-inner.modal-reveal { 205 | transform: translateY(0); 206 | opacity: 1; 207 | } 208 | 209 | .js-close-modal { 210 | transition: color 320ms ease; 211 | color: #9e9e9e; 212 | opacity: 0.75; 213 | position: absolute; 214 | z-index: 2; 215 | right: 0px; 216 | top: 0px; 217 | width: 30px; 218 | height: 30px; 219 | line-height: 30px; 220 | font-size: 20px; 221 | cursor: pointer; 222 | text-align: center; 223 | } 224 | 225 | .js-close-modal:hover { 226 | color: #000; 227 | } 228 | 229 | #settings-version { 230 | position: absolute; 231 | left: 0; 232 | bottom: 0; 233 | margin-left: 11px; 234 | margin-bottom: 5px; 235 | color: #b4b4b482; 236 | } 237 | .settings-connected { 238 | position: absolute; 239 | right: 0; 240 | bottom: 0; 241 | margin-right: 13px; 242 | margin-bottom: 5px; 243 | color: #b4b4b482; 244 | display: flex; 245 | } 246 | 247 | .connectedindicator { 248 | width: 20px; 249 | height: 20px; 250 | background: #30ff30; 251 | border-radius: 53px; 252 | margin-right: 13px; 253 | margin-top: 2px; 254 | } 255 | 256 | button { 257 | position: absolute; 258 | right: 4px; 259 | top: 4px; 260 | background: transparent; 261 | border: transparent; 262 | color: #ffffff30; 263 | } -------------------------------------------------------------------------------- /static/sw.js: -------------------------------------------------------------------------------- 1 | importScripts('/dynamic/dynamic.config.js'); 2 | importScripts('/dynamic/dynamic.worker.js'); 3 | 4 | const dynamic = new Dynamic(); 5 | 6 | self.dynamic = dynamic; 7 | 8 | self.addEventListener('fetch', 9 | event => { 10 | event.respondWith( 11 | (async function() { 12 | if (await dynamic.route(event)) { 13 | return await dynamic.fetch(event); 14 | } 15 | 16 | return await fetch(event.request); 17 | })() 18 | ); 19 | } 20 | ); -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "./dist/", 4 | "noImplicitAny": true, 5 | "module": "ESNext", 6 | "target": "es6", 7 | "forceConsistentCasingInFileNames": true, 8 | "jsx": "react", 9 | "moduleResolution": "node", 10 | "strict": true 11 | }, 12 | "include": ["./lib/**/*"], 13 | "exclude": ["node_modules"] 14 | } --------------------------------------------------------------------------------