Code Monkey home page Code Monkey logo

chemical's Introduction

Chemical

Create your own web proxy using Ultraviolet fast, easy, and no experience required.

Setup

A simple example can be found in /example/.

Server

Create a new Node.js project and create a script file for the server.

  1. Install Chemical npm install chemicaljs.

  2. Import ChemicalServer and create a new server.

import { ChemicalServer } from "chemicaljs";

const chemical = new ChemicalServer();
  1. Use chemical.app which is an express app. You may need to import express for certain APIs.
chemical.app.get("/", function(req, res){
    res.send("Hello World");
});
  1. Use chemical.server and listen on a port of your choosing.
chemical.server.listen(3000);

Below is an example of a simple backend. This example will setup Chemical and serve the "public" folder along with the index.html file as / and .html files without the extension.

import { ChemicalServer } from "chemicaljs";
import express from "express";

const chemical = new ChemicalServer();
const port = process.env.PORT || 3000;

chemical.app.use(express.static("public", {
    index: "index.html",
    extensions: ["html"]
}));

chemical.server.listen(port, () => {
    console.log(`Chemical demo listening on port ${port}`);
});

Client

In your project create a folder to store your static assets. Create an index.html file which will be the homepage of your website.

  1. Add the Chemical script to the top of your page. This will load all needed scripts for Ultraviolet and Chemical.
<script src="/chemical.js"></script>
  1. In a inline script or javascript file, encode a URL with Chemical using window.chemicalEncode.
window.chemicalEncode("https://example.com")
  1. You may want to check if Chemical has loaded before encoding a URL.
if (window.chemicalLoaded) {
    //Chemical is loaded
}
window.addEventListener("chemicalLoaded", function(e) {
    //Chemical has loaded
});

Below is a simple example of a simple input that redirects to the encoded URL when the user presses enter. It checks if there is any input and if Chemical has loaded before loading.

<h1>Chemical Example</h1>
<input id="search" placeholder="Enter URL">

<script src="/chemical.js"></script>
<script>
    const search = document.getElementById("search");

    search.addEventListener("keydown", function (e) {
        if (e.key == "Enter" && window.chemicalLoaded && e.target.value) {
            window.location = window.chemicalEncode(e.target.value)
        }
    })
</script>

Future Addition

Some features that may come in the future are:

  • More proxy services.
  • Easy client components.
  • Easy tab cloaking components.

License

Chemical Uses the MIT license.

chemical's People

Contributors

nebelung-dev avatar avad3 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.