Coder Social home page Coder Social logo

aish's Introduction

Abnormally Injecting Style into HTML

"The promise of love, the pain of loss, the joy of redemption, then give him a puzzle and watch him dance."

How does this work?

There's a tiny parser-like thingy, which parses basic tokens, identifies where they should be grouped into (for example, comment, selector, key or value), and puts them into div elements, which are then pushed into a pre element and a style element. As we modify the style, the browser engine repaints the window accordingly, which is beautiful to watch.

So, we have a payload.css and a js-gen.py. Calling python js-gen.py polls over both the files. Whenever it detects a change to one of the files, it generates a JS file (gen.js), which contains the raw style content packed into a variable (along with optional tags or script contents).

As an additional perk, the parser can callback JS code (i.e.,) whenever it encounters a tilde (~), it calls the corresponding function (if any) declared in the main script. For example, this ends up calling this function.

What good is all this?

I've no idea. This was my gift to my SO. I dunno what good this is gonna do, or how this is gonna be helpful to anyone, but I like it, so I decided to maintain a repo for that.

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.