GithubHelp home page GithubHelp logo

johnny13 / css-overlay-snippet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tomhodgins/css-overlay-snippet

0.0 1.0 0.0 8 KB

A live CSS debugging stylesheet you can copy/paste into the browser's JS console

License: MIT License

JavaScript 28.88% HTML 71.12%

css-overlay-snippet's Introduction

css-overlay-snippet

A live CSS debugging stylesheet

This is a code snippet that can be pasted into the web browser after loading any site that will add an overlay where you can type CSS styles that will also be applied to the page loaded in the browser.

About

This is intended for people debugging or troubleshooting CSS on live websites who may not have access to experiment with the CSS on the site they are troubleshooting.

This snippet also saves your current text to the browser's localStorage, so the styles you have written on one page will persist even after a reload (and pasting the snippet back into the console to bring the overlay back).

How to use

This snippet works by copying the JavaScript code from index.js and entering it into your browser's JavaScript Console. A small, transparent overlay will appear at the bottom of the browser's viewport. Moving the mouse over this overlay will enlarge it, and if you click inside the overlay you are able to type to edit the text.

// CSS Overlay Snippet
(() => {
  let overlay_styles = document.createElement('style')
  let virtual_stylesheet = document.createElement('style')
  let textarea = document.createElement('textarea');

  overlay_styles.textContent = `
    [data-css=overlay] {
      box-sizing: border-box;
      margin: 0;
      padding: 1em;
      width: 100%;
      height: 100px;
      position: fixed;
      bottom: 0;
      right: 0;
      font-size: 18pt;
      font-family: 'Fira Code', monospace;
      color: black !important;
      background: white !important;
      opacity: .3;
      z-index: 99999;
      transition: height .2s ease-in-out, opacity .2s ease-in-out;
    }
    [data-css=overlay]:hover {
      opacity: .8;
      height: 80%;
    }
  `
  textarea.addEventListener(
    'input', 
    e => localStorage.css_overlay = virtual_stylesheet.innerHTML = textarea.value
  )
  if (localStorage.css_overlay) {
    textarea.value = localStorage.css_overlay
  }
  textarea.dataset.css = 'overlay'

  document.head.appendChild(overlay_styles)
  document.head.appendChild(virtual_stylesheet)
  document.body.appendChild(textarea)
})()

TIP: Once you have pasted a snippet into your browser's JS console, you can press the up arrow on your keyboard to view the history of past commands you have entered.

css-overlay-snippet's People

Contributors

chocolateboy avatar tomhodgins avatar

Watchers

 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.