Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(args) {
- var cookieSS = args.join(' '),
- reWhiteSpace = /\s/g,
- reSemiCol = /;(})/g,
- reGeneral = /(.+?)({([^}]+)})/g,
- selectors = {},
- result = '',
- obj,
- p,
- formatedObj = {};
- function extractSelectors(match, p1, p2, p3) {
- //console.log(p1);
- //console.log(p3);
- p1 = p1.trim();
- if(selectors.hasOwnProperty(p1)){
- selectors[p1] += p3;
- } else {
- selectors[p1] = p3;
- }
- return match;
- }
- function formatObject(obj) {
- var finalObj = {};
- function propValToObj(selector, prop , val){
- if(finalObj.hasOwnProperty(selector)) {
- delete finalObj[selector][prop];
- } else {
- finalObj[selector] = {};
- }
- finalObj[selector][prop] = val;
- }
- function trimSelectors(str){
- var reAllSpace = /\s+/g,
- reFixNesting = /\s*(\W)\s*/g,
- reDot = /([^\W])\./g; //Aperently it also needs space between dots, but not all
- str = str.replace(reAllSpace, ' ');
- str = str.replace(reFixNesting , '$1');
- str = str.replace(reDot , '$1 .');
- str = str.trim();
- return str;
- }
- function trimPropVal(obj) {
- var p,
- reTrimWhite = /\s+/g,
- reNecessaryWhiteSpace = /([(),])\s+([\w\W])/g,
- reCssAndValue = /\s*(\S+)\s*\:\s*(.+?)\s*\;/,
- cycle = true,
- selector,
- str,
- css,
- value;
- function splitCssValue(match, p1 , p2) {
- css = p1.trim();
- // css = css.replace(reTrimWhite, ' ');
- value = p2.trim();
- value = value.replace(reTrimWhite, ' ');
- value = value.replace(reNecessaryWhiteSpace , '$1$2');
- return '';
- }
- //console.log(obj);
- for(p in obj) {
- selector = trimSelectors(p);
- str = obj[p].replace(reTrimWhite , ' '); // Trim all whitespace to single space
- //console.log(selector);
- while(cycle){
- //console.log(str);
- str = str.replace(reCssAndValue , splitCssValue);
- cycle = reCssAndValue.test(str);
- propValToObj(selector, css, value);
- }
- cycle = true;
- }
- }
- trimPropVal(obj);
- return finalObj;
- }
- cookieSS.replace(reGeneral , extractSelectors);
- //console.log(selectors);
- formatedObj = formatObject(selectors);
- //console.log(formatedObj);
- for (obj in formatedObj){
- result += obj + '{';
- for(p in formatedObj[obj]) {
- result += p + ':' + formatedObj[obj][p] + ';';
- }
- result += '}';
- }
- result = result.replace(reSemiCol , '$1' );
- console.log(result);
- }
- console.log('test1');
- solve([
- ' #the-big-b{',
- 'color: yellow;',
- 'size: big;',
- '}',
- '.muppet{',
- 'powers: all;',
- 'skin: fluffy;',
- '}',
- '.water-spirit{powers: water;',
- 'alignment : not-good;',
- '}',
- 'all{',
- 'meant-for: nerdy-children;',
- '}',
- '.muppet {',
- 'powers: everything;',
- '}',
- 'all .muppet {',
- 'alignment : good ;',
- '}',
- '.muppet+ .water-spirit{',
- 'power: everything-a-muppet-can-do-and-water;',
- '}'
- ]);
- console.log('test2');
- solve([
- ' the-big-b .apk',
- ' {',
- 'color: yellow;',
- 'size: big;',
- //'color: crazi',
- 'color:crazi;name:petio; sur-name:dido;',
- '}',
- ]);
- console.log('test3');
- solve([
- ' main {',
- ' width: 50%;',
- ' margin: 0 auto;',
- '}',
- 'main h1 {',
- ' color: #fff;',
- '}',
- 'main p {',
- ' color: #FFE85F;',
- '}',
- 'main p :hover {',
- ' cursor: pointer;',
- ' color: #7374CA;',
- '}'
- ]);
- console.log('test4');
- solve([
- ' #Navigation ul {',
- ' border: 1px solid #000;',
- ' padding: 10px 0;',
- '}'
- ]);
- console.log('test5 Real CSS');
- var x = [
- ' body {',
- 'padding: 10px 0;',
- 'font-size: 16px;',
- 'font-family: Palatino Linotype;',
- ' background: -moz-linear-gradient(45deg, #2b0808 0%, #a86c54 59%, rgba(202, 135, 105, 0.7) 75%, rgba(255, 178, 137, 0) 100%);',
- ' background: -webkit-gradient(linear, left bottom, right top, color-stop(0%, #2b0808), color-stop(59%, #a86c54), color-stop(75%, rgba(202, 135, 105, 0.7)), color-stop(100%, rgba(255, 178, 137, 0)));',
- ' background : -webkit-linear-gradient(45deg, #2b0808 0%, #a86c54 59%, rgba(202, 135, 105, 0.7) 75%, rgba(255, 178, 137, 0) 100%);',
- ' background: -o-linear-gradient(45deg, #2b0808 0%, #a86c54 59%, rgba(202, 135, 105, 0.7) 75%, rgba(255, 178, 137, 0) 100%);',
- ' background: -ms-linear-gradient(45deg, #2b0808 0%, #a86c54 59%, rgba(202, 135, 105, 0.7) 75%, rgba(255, 178, 137, 0) 100%);',
- ' background: linear-gradient(45deg, #2b0808 0%, #a86c54 59%, rgba(202, 135, 105, 0.7) 75%, rgba(255, 178, 137, 0) 100%);',
- " filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#2b0808', endColorstr='#00ffb289', GradientType=1);",
- ' background-attachment: fixed;',
- ' height: \n 100%;',
- '}',
- 'header {',
- ' width: 800px;',
- ' margin: 0 auto;',
- '}',
- 'header h1 {',
- ' text-align: center;',
- ' margin: 10px 0;',
- '\n text-decoration: underline;',
- ' color : transparent;',
- ' text-shadow: -9px 5px 1px #67382d, -10px 5px 2px #000000;',
- ' cursor: default;',
- '}',
- '#Navigation {',
- ' text-align: center;',
- '}',
- '#Navigation ul {',
- ' border: 1px solid #000;',
- ' padding: 10px 0;',
- '}',
- '#Navigation ul li {',
- ' display: inline-block;',
- ' margin: 0 10px;',
- '}',
- '#Navigation ul li a {',
- ' padding: 2px 5px;',
- ' color: #fff;',
- ' border: 1px outset #fff;',
- ' background: #b67d66;',
- '}',
- '#Navigation ul li a:active {',
- ' border-style: inset;',
- '}',
- '#MainContent {',
- ' width: 960px;',
- ' height: 435px;',
- ' margin: 5px auto;',
- '}',
- '#MainContent .Content {',
- ' display: none;',
- ' position: relative;',
- ' width: 90%;',
- ' height: 100%;',
- ' box-sizing: border-box;',
- ' margin: 5px auto;',
- ' border: 1px solid #000;',
- ' padding: 10px;',
- ' background: #DFC9B2;',
- '}',
- '#MainContent .Content:target {',
- ' display: block;',
- '}',
- '#MainContent .Content h2,',
- '#MainContent .Content p,',
- '#MainContent .Content form {',
- ' margin: 0 5px 5px 5px;',
- '}',
- '#MainContent .Content .example {',
- ' background: #ddd;',
- '}',
- '#MainContent .Content .hint {',
- ' font-style: italic;',
- ' margin-bottom: 5px;',
- '}',
- '#MainContent .Content form {',
- ' display: inline-block;',
- ' vertical-align: top;',
- ' width: 46%;',
- ' height: 100%;',
- ' color: #955d49;',
- '}',
- '#MainContent .Content form > p {',
- ' margin: 10px 0;',
- '}',
- '#MainContent .Content form > p em {',
- ' background: #ddd;',
- '}',
- '#MainContent .Content form a {',
- ' color: #7A8AE2;',
- '}',
- '#MainContent .Content form > ul li {',
- ' list-style: circle;',
- ' margin: 5px 0 0 40px;',
- '}',
- '#MainContent .Content form table {',
- ' border-collapse: collapse;',
- '}',
- '#MainContent .Content form th,',
- '#MainContent .Content form td {',
- ' text-align: center;',
- '}',
- '#MainContent .Content form th {',
- ' font-weight: bold;',
- ' padding: 5px;',
- '}',
- '#MainContent .Content form td {',
- ' color: #000;',
- '}',
- '#MainContent .Content form .interface {',
- ' position: relative;',
- ' width: 100%;',
- '}',
- '#MainContent .Content form .interface span {',
- ' font-size: 18px;',
- ' display: block;',
- '}',
- '#MainContent .Content form .interface div {',
- ' width: 100%;',
- ' padding: 2px 0;',
- '}',
- '#MainContent .Content form .interface input {',
- ' color: #fff;',
- ' background: #b67d66;',
- ' font-size: 20px;',
- '}',
- '#MainContent .Content form .interface table {',
- ' width: 75%;',
- '}',
- '#MainContent .Content form .interface table input[type="text"] {',
- ' width: 80px;',
- '}',
- '#MainContent .Content form .interface input[type="number"] {',
- ' width: 100px;',
- '}',
- '#MainContent .Content form .interface input[type="number"]::-webkit-inner-spin-button,',
- '#MainContent .Content form .interface input[type="number"] -webkit-outer-spin-button {',
- ' -webkit-appearance: none;',
- '}',
- '#MainContent .Content form .interface input[type="text"] {',
- ' width: 200px;',
- '}',
- '#MainContent .Content form .interface input[type="text"],',
- '#MainContent .Content form .interface input[type="number"] {',
- 'background: #fff;',
- ' color: #955d49;',
- 'font-style: italic;',
- 'text-align: inherit;',
- '}',
- '#MainContent .Content form .interface input[type="text"]:focus,',
- '#MainContent .Content form .interface input[type="number"]:focus {',
- 'background: #FFFFBE;',
- '}',
- '#MainContent .Content form .interface input[type="text"]:focus + .tooltip,',
- '#MainContent .Content form .interface input[type="number"]:focus + .tooltip {',
- ' display: block;',
- ' opacity: 1;',
- ' cursor: default;',
- ' animation: FadeIn linear 0.2s;',
- '}',
- '#MainContent .Content form .interface .tooltip {',
- ' display: none;',
- ' opacity: 0;',
- ' position: absolute;',
- ' left: -5px;',
- ' bottom: -36px;',
- ' vertical-align: bottom;',
- ' height: 26px;',
- ' width: auto;',
- ' padding: 2px 5px 0 5px;',
- ' text-align: center;',
- ' font-style: italic;',
- ' color: #fff;',
- ' background: #b67d66;',
- ' box-shadow: -2px 4px 15px #67382d, -2px 5px 12px #000000;',
- '}',
- '#MainContent .Content form .interface .tooltip em {',
- ' color: #3a6deb;',
- '}',
- '#MainContent .Content form .interface .tooltip2 {',
- ' position: relative;',
- ' left: 0;',
- ' top: 0;',
- ' width: 90%;',
- '}',
- '#MainContent .Content .Result {',
- ' font-family: Consolas;',
- ' font-style: italic;',
- ' border: 1px solid #000;',
- ' display: inline-block;',
- ' vertical-align: top;',
- ' width: 51%;',
- ' height: 100%;',
- ' overflow: auto;',
- ' background: #000;',
- ' color: #eee;',
- ' box-sizing: border-box;',
- ' padding: 0px 5px;',
- '}',
- '#MainContent .Content .Result em {',
- ' color: #C57F06;',
- '}',
- '#MainContent .Content .Result strong {',
- ' background: #3a6deb;',
- '}',
- '#MainContent .Content .Result ul {',
- ' position: relative;',
- ' top: -5px;',
- ' margin-left: 35px;',
- '}',
- '#MainContent .Content .Result h3 {',
- 'font-style: normal;',
- 'text-align: center;',
- ' margin: 2px;',
- '}',
- '#MainContent .Content .Result h4 {',
- 'margin-bottom: 0;',
- '}',
- '#MainContent .Content .Result p {',
- 'margin-left: 10px;',
- '}',
- '#Navigation ul,',
- '.Content {',
- ' box-shadow: -9px 11px 20px #67382d, -10px 11px 15px #000000;',
- '}'
- ];
- solve(x);
Advertisement
Add Comment
Please, Sign In to add comment