-
Notifications
You must be signed in to change notification settings - Fork 2
/
stylist.min.js
1 lines (1 loc) · 5.11 KB
/
stylist.min.js
1
(function(a,b,c){function d(a,b){return function d(){if(!d.timer){var e=arguments,f=this;d.timer=setTimeout(function(){a.apply(f,e),d.timer=c},b)}}}function e(a,b,c){for(var d,e=b.split(";"),f=0,g=e.length;f<g;f++)""!=e[f]&&(d=e[f].split(":"),c?a.style.removeProperty(d[0]):a.style.setProperty(d[0],d[1],"important"))}function f(a,c){var d=b.createElement("li");e(d,"color:#555;display:block"),d.appendChild(b.createTextNode(c)),a.appendChild(d)}function g(){function c(){switch(E){case"B":e(x,"top:0;right:0;height:100%;width:300px",!0),e(x,"bottom:0;left:0;height:300px;width:98%",!1),E="L";break;case"L":e(x,"bottom:0;left:0;height:300px;width:98%",!0),e(x,"top:0;left:0;height:100%;width:300px",!1),E="T";break;case"T":e(x,"top:0;left:0;height:100%;width:300px",!0),e(x,"top:0;left:0;height:300px;width:98%",!1),E="R";break;case"R":e(x,"top:0;left:0;height:300px;width:98%",!0),e(x,"top:0;right:0;height:100%;width:300px",!1),E="B";break;default:alert("Unrecognized position")}}function g(){v.innerHTML=G.checked?w.value:"",H()}function q(){var b=new Blob([w.value],{type:"text/plain;charset=UTF-8"});t=a.URL.createObjectURL(b,{oneTimeOnly:!0}),console.log(B),B.href=t,B.download="stylist_"+r()+".css",B.click(),a.URL.revokeObjectURL(t)}function r(){var a=new Date,b=a.getFullYear(),c=a.getMonth()+1,d=a.getDate(),e=a.getHours(),f=a.getMinutes(),g=a.getSeconds(),h="_";return c<10&&(c="0"+c),d<10&&(d="0"+d),e<10&&(e="0"+e),f<10&&(f="0"+f),g<10&&(g="0"+g),b+h+c+d+e+f+g}function s(a){var c=x||b.getElementById("__panel");c&&(c.style.display=a?"block":"none")}if(b.getElementById("stylist:panel"))return void s(!0);var t,u=(b.getElementsByTagName("head")[0],b.body),v=b.createElement("style"),w=b.createElement("textarea"),x=b.createElement("div"),y=b.createElement("h1"),z=b.createElement("ul"),A=b.createElement("label"),B=b.createElement("a"),C=b.createElement("version"),D=b.createElement("button"),E=(b.createElement("button"),"B"),F=!!a.chrome;x.style.display="block",w.spellcheck=!1,w.id="__input",x.id="__panel";var G=b.createElement("input");G.setAttribute("type","checkbox"),A.appendChild(G),A.appendChild(b.createTextNode("Apply CSS")),e(A,"font:12px monospace;vertical-align:middle;text-align:left"),e(G,"vertical-align:middle"),e(x,"position:fixed;top:0;right:0;width:300px;height:100%;z-index:2147483647;overflow:auto;outline:solid 1px #333;padding:0 20px;borderTop:0;borderBottom:0;borderRight:0;borderLeft:1px solid #ccc;color:#222;background:#fcfcfc"),e(w,"font:13px Inconsolata, Consolas, Menlo, Monaco, Lucida Console, Courier New, Courier, monospace;width:100%;height:calc(100% - 140px);direction:ltr;textAlign:left;background:#fcfcfc"),e(B,"display:none"),e(C,"font:9px monospace;color:#aaa;position:absolute;top:10px;right:40px"),C.innerHTML="v"+p,D.id="__close",D.setAttribute("title","Close this panel"),D.appendChild(b.createTextNode("X")),e(D,"position:absolute;top:10px;right:10px;cursor:pointer;transform:scale(0.8)"),v.setAttribute("type","text/css"),y.innerHTML="Stylist",e(y,"color:#555;background-color:#fcfcfc;width:150px;height:1.5em;margin:4px 0 4px 0;font-family:serif;font-size:20px;font-style:oblique;line-height:1.5em;box-shadow:none;text-shadow:none;text-align:left"),e(z,"font:12px monospace;list-style:none;margin-top:0px"),f(z,"CTRL+M: toggle this panel"),f(z,"CTRL+Y: change dock position"),f(z,"ALT+click: target element"),x.appendChild(y),x.appendChild(z),x.appendChild(A),x.appendChild(w),x.appendChild(C),x.appendChild(D),u.appendChild(x),u.appendChild(v),F&&(f(z,"CTRL+S: save CSS to file"),x.appendChild(B)),G.checked="true"===(localStorage.applyStyles||"true"),w.value=localStorage.siteStyle||"",w.placeholder="/* Enter your styles here. */",v.innerHTML=G.checked?w.value:"",u.addEventListener("click",function(a){if(-1===w.style.display.indexOf("none")&&a.target.id!==w.id&&a.altKey){var b,c,d=0,e=a.target,f=e.className.split(" ")||"",g=[],h="",i="";for(i+=e.tagName.toLowerCase(),e.id&&(i+="#"+e.id),d=0;d<f.length;d++)n.test(f[d])||(i+="."+f[d]);if(e.getAttribute("style"))for(g=e.getAttribute("style").split(";"),d=0;d<g.length;d++)b=g[d].split(o).join(" ").trim(),n.test(b)||(h+=l+b.toLowerCase()+";\n");i&&(h=h?"{\n"+h+"}":"{\n\n}",c="\n"+i+" "+h,w.value+=c,w.focus(),w.setSelectionRange(w.value.length-c.length,w.value.length)),a.preventDefault()}});var H=d(function(){localStorage.siteStyle=w.value,localStorage.applyStyles=G.checked?"true":"false",console.log("applyStyles :"+localStorage.applyStyles)},500);G.addEventListener("click",function(a){g()}),D.addEventListener("click",function(a){s(!1)}),w.addEventListener("keyup",g),w.addEventListener("change",g),w.addEventListener("keydown",function(a){var b=w.value,c=w.selectionStart;a.keyCode===h&&(w.value=b.substring(0,c)+l+b.substring(c),w.setSelectionRange(c+m,c+m),a.preventDefault())}),a.addEventListener("keydown",function(a){if(a.ctrlKey)switch(console.log(a.keyCode),a.keyCode){case j:s("none"===x.style.display);break;case i:c();break;case k:if(F)try{a.preventDefault(),q()}catch(a){console.log(a),alert("Unable to save your file.")}}})}var h=9,i=89,j=77,k=83,l=" ",m=l.length,n=/^\s*$/,o=/\s+$/g,p="1.7";String.prototype.trim=function(){return this.replace(/(^\s+|\s+$)/g,"")},g()})(this,this.document);