ABPVN Custom CSS

Tùy chỉnh CSS trang web theo ý bạn

Versión del día 26/08/2015. Echa un vistazo a la versión más reciente.

  1. // ==UserScript==
  2. // @name ABPVN Custom CSS
  3. // @description Tùy chỉnh CSS trang web theo ý bạn
  4. // @namespace ABPVN
  5. // @author Hoàng Rio
  6. // @include *
  7. // @icon https://www.webanh.tk/full/aBINKD.png
  8. // @version 1.1.2
  9. // @grant none
  10. // @run-at document-end
  11. // @noframes
  12. // ==/UserScript==
  13. var html='<div id="abpvn-custom-css" style="display: none;">';
  14. html+='<div style="z-index: 999; background: rgba(0, 0, 0, 0.57) none repeat scroll 0% 0%; position: fixed; top: 0px; left: 0px; height: 100%; width: 100%;"></div>';
  15. html+='<div style="position: fixed; top: 30%; left: 30%; width: auto; height: auto; text-align: left; background: rgba(0, 128, 0, 0.69) none repeat scroll 0% 0%; padding: 10px; z-index: 1000; font-size: 15px; font-family: Tahoma; color: White; border-radius: 15px;" id="custom-css">';
  16. html+='<h3 style="text-align: center; padding: 0px; height: 10px; margin-top: -10px;">Thêm quy tắc CSS mới</h3>';
  17. html+='<label for="type" style="color: white;">Thiết lập cho</label><br>';
  18. html+='<select id="type" name="type" style="padding: 5px; color: black;">';
  19. html+='<option value="hostname">Tên miền hiện tại</option>';
  20. html+='<option value="url">Đường dẫn hiện tại</option>';
  21. html+='</select><br>';
  22. html+='<label for="url" style="color: white;">Địa chỉ thiết lập</label><br>';
  23. html+='<input size="50" disabled style="padding: 5px; color: black; background: white;" name="url" id="url"><br>';
  24. html+='<label for="css" style="color: white;">Thông tin css</label><br>';
  25. html+='<textarea style="width: 569px; height: 142px; color: black; background: white; border-radius: 10px;" id="css" name="css"></textarea><br>';
  26. html+='<div style="margin-left: 40%; position: abusolute;"><button id="btn-save" style="width: 50px;padding: 3px; font-size: 15px; color: white; background: blue; border-radius: 15px;">Lưu</button><button id="btn-cancel" style="width: 50px;padding: 3px; font-size: 15px; color: white; background: red;border-radius: 15px;">Hủy</button></div>';
  27. html+='</div>';
  28. html+='</div>';
  29. var add_html='<div id="btn-add" style="position: fixed; top: 0; left: 0; padding: 5px; font-weight: 800; color: white; border-radius: 50%; cursor: pointer;background: rgba(0, 255, 48, 0.53) none repeat scroll 0% 0%; z-index: 99999;" title="Thêm quy tắc css mới">+</div>';
  30. function create(htmlStr) {
  31. var frag = document.createDocumentFragment(),
  32. temp = document.createElement('div');
  33. temp.innerHTML = htmlStr;
  34. while (temp.firstChild) {
  35. frag.appendChild(temp.firstChild);
  36. }
  37. return frag;
  38. }
  39.  
  40. function ApplyStyle(css){
  41. if(css!==''){
  42. style=document.createElement('style');
  43. style.type = 'text/css';
  44. if (style.styleSheet){
  45. style.styleSheet.cssText = css;
  46. } else {
  47. style.appendChild(document.createTextNode(css));
  48. }
  49. document.body.insertBefore(style, document.body.childNodes[0]);
  50. }
  51. }
  52. var setting={};
  53. setting.show=function(){
  54. var dom=document.getElementById('abpvn-custom-css');
  55. dom.style.display='block';
  56. }
  57. setting.hide=function(){
  58. var dom=document.getElementById('abpvn-custom-css');
  59. dom.style.display='none';
  60. }
  61. setting.save=function(){
  62. key=document.getElementById('url').value;
  63. type=document.getElementById('type').value;
  64. value=document.getElementById('css').value;
  65. localStorage.setItem(type+':'+key,value);
  66. alert('Đã lưu thiết lập!');
  67. location.reload();
  68. }
  69. setting.switchtype=function(){
  70. type=document.getElementById('type').value;
  71. url=document.getElementById('url');
  72. switch(type){
  73. case 'hostname':
  74. url.disabled=true;
  75. url.value=location.hostname;
  76. css_hostname=localStorage.getItem('hostname:'+location.hostname)===null?'':localStorage.getItem('hostname:'+location.hostname);
  77. document.getElementById('css').value=css_hostname;
  78. break;
  79. default:
  80. url.disabled=true;
  81. url.value=location.href;
  82. css_url=localStorage.getItem('url:'+location.href)==null?'':localStorage.getItem('url:'+location.href);
  83. document.getElementById('css').value=css_url;
  84. break;
  85. }
  86. }
  87. function init(){
  88. var button=create(add_html);
  89. var fragment = create(html);
  90. // You can use native DOM methods to insert the fragment:
  91. document.body.insertBefore(fragment, document.body.childNodes[0]);
  92. document.body.insertBefore(button, document.body.childNodes[0]);
  93. document.getElementById('btn-add').addEventListener('click',setting.show,true);
  94. document.getElementById('btn-cancel').addEventListener('click',setting.hide,true);
  95. document.getElementById('btn-save').addEventListener('click',setting.save,true);
  96. document.getElementById('type').addEventListener('change',setting.switchtype,true);
  97. url=document.getElementById('url').value=location.hostname;
  98. css_hostname=localStorage.getItem('hostname:'+location.hostname)===null?'':localStorage.getItem('hostname:'+location.hostname);
  99. css_url=localStorage.getItem('url:'+location.href)===null?'':localStorage.getItem('url:'+location.href);
  100. document.getElementById('css').value=css_hostname;
  101. ApplyStyle(css_hostname+css_url);
  102. }
  103. window.addEventListener('DOMContentLoaded',function(){
  104. init();
  105. });