Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <input type="text" id="urlToSite" value="https://youtube.com">
<button id="btn">get color</button>
<div id="output"></div>
<div id="box"></div>
<iframe id="ifr"></iframe>
              
            
!

CSS

              
                iframe {
  display: block;
  border: none; background: none;
  width: 100%; height: 300px;
}
h4 {
  margin: 20px 0 7px 0;
  font: normal normal 400 14px / 20px sans-serif;
}
h5 {
  margin: 15px 0;
  font: normal normal 600 18px / 20px sans-serif;
}
div {
  font: normal normal 400 18px / 20px sans-serif;
}
span {
  text-shadow: 0px -1px white;
  vertical-align: baseline;
  font: normal normal 400 18px / 20px sans-serif;
}
#box {
  margin: 0 0 20px 0;
  font-size: 0;
}
.color {
  margin: 1px;
  display: inline-block;
  width: 24px; height: 24px;
  border: 1px solid lightgray;
  border-radius: 50%;
}
              
            
!

JS

              
                let getColor = {

  /* get api key */
  get _key() {
    const ak = [
      "ak-e85c0-x0xd9-5hxw1-jvd7r-0cvy7",
      "ak-805wx-24tvf-qvqk2-gt4ve-rhyv9",
      "ak-et4bz-78wdq-b98f2-1tn9c-fx4ds",
      "ak-b1172-9ysps-331v1-g9s1v-ngwd1",
      "ak-5748g-tv4v1-dt69j-zbm9a-r2mv7"
    ];
    return ak[Math.floor(Math.random() * ak.length)];
  },

  /* make request */
	ToSite (url) {
  	this._url = url;
    const param = `{url:"${url}",renderType:"html",requestSettings:{resourceModifier:[{regex:".*css.*"}],clearCache:true,loadImages:false}}`;
    const request = `https://phantomjscloud.com/api/browser/v2/${this._key}/?request=${param}`;
    fetch(request)
		  .then((r) => { return r.text(); })
		  .then((source) => {
        const domain = url.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i, "")[0];
        source = source.replace(/href="\/(?!\/)/ig, `href="${domain}\/`); /* href="/ => href="http://domain.com/" */
        source = source.replace(/"file:\/\//ig, "\"http:\/\/"); /* "file:// => "http:// */
        output.innerHTML = `<h5>${url}</h5>Render...`;
        this._cb(source); 
      })
		  .catch((error) => { output.innerHTML = `<h5>${url}</h5>${error}` });
    output.innerHTML = `<h5>${url}</h5>Loading...`;
  },

	_url: null,

  /* getting body color within iframe */
	_cb (textHtml) {
		let win = ifr.contentWindow;
		let doc = win.document;
    
    /* iframe loaded */
		ifr.onload = () => {
			/* get body color */
			const color = win.getComputedStyle(doc.body).backgroundColor;
			output.innerHTML = `<h5>${this._url}</h5>Body color: <span style="background-color: ${color}">${color}</span>`;

			/* get all colors from page */
			const elms = doc.querySelectorAll("*");
			let bgColor = [];
			let textColor = [];
			for( let i = 0; i < elms.length; i++ ) {
				bgColor.push(win.getComputedStyle(elms[i]).backgroundColor);
				textColor.push(win.getComputedStyle(elms[i]).color);
			}

			/* unique array key */
			bgColor = bgColor.filter( (v,i,s) => {return s.indexOf(v) === i} );
			textColor = textColor.filter( (v,i,s) => {return s.indexOf(v) === i} );
			
			/* generate colors */
			box.innerHTML = `<h4>Background colors(${bgColor.length}):</h4>`;
			for( let i = 0; i < bgColor.length; i++ ) this._addColor(bgColor[i]);
			box.innerHTML += `<h4>Text colors(${textColor.length}):</h4>`;
			for( let i = 0; i < textColor.length; i++ ) this._addColor(textColor[i]);
		}
    
    /* fill html */
		doc.open(); doc.write(textHtml); doc.close();
	},
	
  /* Add color */
	_addColor(color) {
		let el = document.createElement("div");
		el.classList.add("color");
		el.style.backgroundColor = color;
		box.appendChild(el)
  }
}



btn.onclick = () => { getColor.ToSite(urlToSite.value || 'https://youtube.com') }


              
            
!
999px

Console