Kawiesh

CSS-BOOKMARKLET

Jan 30th, 2021 (edited)
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let icon=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
  2. <path stroke="red" stroke-width="2.5"d="M6.44,6.58L17.76,17.15"/>
  3. <path fill="none" stroke="red" stroke-width="2"
  4. d="M1.71,1.61L22.50,1.61L22.50,22.12L1.71,22.12z"/>
  5. <path stroke="red" stroke-width="2.5"d="M6.14,17.48L18.07,6.25"/>
  6. </svg>`;
  7.  
  8. let def=`#cssdiv{z-index:99999; top:0px; left:0px;
  9. height:300px; width:400px;}`;
  10.  
  11. //border
  12. let border=`{
  13. animation:kd 1s infinite alternate;
  14. }
  15. @keyframes kd{
  16. 100%{box-shadow: 0 0 10px 2px red}
  17. }`;
  18.  
  19. //Styling
  20. let styling=`
  21. #cssdiv#cssdiv{
  22. z-index: 99999;
  23. pointer-events: none;
  24. width: 400px;
  25. height: 300px;
  26. position: fixed;
  27. top: 0; left: 0;
  28. }
  29.  
  30. #cssclose#cssclose,
  31. #cssclose2#cssclose2{
  32. display:inline;
  33. pointer-events: auto;
  34. width: 18px; height: 18px;
  35. position: absolute; left: 0;
  36. background:none;
  37. font:12px Arial;
  38. margin:0; border: none;
  39. }
  40.  
  41. #cssta#cssta,
  42. #cssta2#cssta2{
  43. width: 100%;
  44. background: rgb(0,0,0,0.7);
  45. outline:none;
  46. box-sizing: border-box;
  47. position: absolute;
  48. padding-left: 20px;
  49. border:1px solid gray;
  50. }
  51.  
  52. #cssta#cssta{
  53. display: block;
  54. pointer-events: auto;
  55. height: 90%; top:0;
  56. color: #39FF14;
  57. font: bold 13px 'Courier New';
  58. }
  59.  
  60. #cssta2#cssta2{
  61. display: none;
  62. pointer-events: none;
  63. height: 10%; bottom: 0;
  64. color: #fff;
  65. font: bold 10px 'Courier New';
  66. }`;
  67.  
  68. //Container
  69. let cssdiv= document.createElement('div');
  70. cssdiv.id='cssdiv';
  71. let x= document.querySelector('#cssdiv');
  72. if(x){
  73. x.parentNode.removeChild(x);
  74. document.body.appendChild(cssdiv);
  75. }
  76. else document.body.appendChild(cssdiv);
  77.  
  78. //TA1
  79. let a1= document.createElement('textarea');
  80. a1.id='cssta';
  81. a1.spellcheck= false;
  82. a1.value= localStorage.getItem('css');
  83. cssdiv.appendChild(a1);
  84.  
  85. let a2= document.createElement('style');
  86. document.body.appendChild(a2);
  87. let rgx= /(?<!important\s?);/g;
  88. let imp= '!important\;';
  89. a2.innerHTML= a1.value.replace(rgx,imp)+border;
  90. a1.onkeyup=function(){
  91. a2.innerHTML= a1.value.replace(rgx,imp)+border;
  92. };
  93.  
  94. let a3= document.createElement('span');
  95. a3.id='cssclose';
  96. a3.innerHTML= icon;
  97. a3.style.top= '0';
  98. cssdiv.appendChild(a3);
  99.  
  100. let a3click=true;
  101. a3.onclick=function(){
  102. if(a3click){
  103. a1.style.display='none';
  104. b1.style.display='none';
  105. b3.style.display='none';
  106. cssdiv.style.pointerEvents='none';
  107. a3click=false;
  108. }
  109. else{
  110. cssdiv.style.pointerEvents='auto';
  111. a1.style.display='block';
  112. b3.style.display='block';
  113. a3click=true;
  114. }};
  115.  
  116.  
  117. //TA2
  118. let b1= document.createElement('textarea');
  119. b1.id='cssta2';
  120. b1.spellcheck= false;
  121. b1.value= def;
  122. cssdiv.appendChild(b1);
  123.  
  124. let b2= document.createElement('style');
  125. document.body.appendChild(b2);
  126. b2.innerHTML= styling + b1.value.replace(rgx,imp);
  127. b1.onkeyup=function(){
  128. b2.innerHTML= styling + b1.value.replace(rgx,imp);
  129. };
  130.  
  131. let b3= document.createElement('span');
  132. b3.id='cssclose2';
  133. b3.innerHTML= icon;
  134. b3.style.bottom= '10%';
  135. cssdiv.appendChild(b3);
  136.  
  137. let b3click=true;
  138. b3.onclick=function(){
  139. if(b3click){
  140. b1.style.display='block';
  141. b1.style.pointerEvents='auto';
  142. b3click=false;
  143. }
  144. else{
  145. b1.style.display='none';
  146. b1.style.pointerEvents= 'none';
  147. cssdiv.style.pointerEvents='none';
  148. a1.style.pointerEvents='auto';
  149. b3click=true;
  150. }};
  151.  
  152. //Store CSS
  153. let obu= false;
  154. window.onunload= window.onbeforeunload= function(){
  155. if(!obu){
  156. obu= true;
  157. localStorage.removeItem('css');
  158. localStorage.setItem('css',a1.value);
  159. }};
  160.  
Add Comment
Please, Sign In to add comment