ABPVN Custom CSS

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

  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.3.1
  9. // @grant none
  10. // @run-at document-end
  11. // @exclude http://abpvn.com/*
  12. // @exclude http://sinhvienit.net/*
  13. // @exclude *.js
  14. // @exclude *.txt
  15. // @exclude *.css
  16. // @exclude *.cs
  17. // @exclude *.cpp
  18. // @exclude *.py
  19. // @noframes
  20. // ==/UserScript==
  21. var html='<div id="abpvn-custom-css" style="display: none;">';
  22. 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>';
  23. 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">';
  24. html+='<h3 style="text-align: center; padding: 0px; height: 10px; margin-top: -10px;">Thêm quy tắc CSS mới</h3>';
  25. html+='<label for="type" style="color: white;">Thiết lập cho</label><br>';
  26. html+='<select id="type" name="type" style="padding: 5px; color: black;">';
  27. html+='<option value="hostname">Tên miền hiện tại</option>';
  28. html+='<option value="url">Đường dẫn hiện tại</option>';
  29. html+='</select><br>';
  30. html+='<label for="url" style="color: white;">Địa chỉ thiết lập</label><br>';
  31. html+='<input size="50" disabled style="padding: 5px; color: black; background: white;" name="url" id="url"><br>';
  32. html+='<label for="css" style="color: white;">Thông tin css</label><br>';
  33. html+='<textarea style="width: 569px; height: 142px; background: white none repeat scroll 0% 0%; border-radius: 10px; font-family: Courier new; color: rgb(0, 48, 255);" id="css" name="css"></textarea><br>';
  34. 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>';
  35. html+='</div>';
  36. html+='</div>';
  37. 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>';
  38. function create(htmlStr) {
  39. var frag = document.createDocumentFragment(),
  40. temp = document.createElement('div');
  41. temp.innerHTML = htmlStr;
  42. while (temp.firstChild) {
  43. frag.appendChild(temp.firstChild);
  44. }
  45. return frag;
  46. }
  47.  
  48. function ApplyStyle(){
  49. css_hostname=localStorage.getItem('hostname:'+location.hostname)===null?'':localStorage.getItem('hostname:'+location.hostname);
  50. css_url=localStorage.getItem('url:'+location.href)===null?'':localStorage.getItem('url:'+location.href);
  51. document.getElementById('css').value=css_hostname;
  52. css=css_hostname+css_url;
  53. if(css!==''){
  54. style=document.createElement('style');
  55. style.type = 'text/css';
  56. if (style.styleSheet){
  57. style.styleSheet.cssText = css;
  58. } else {
  59. style.appendChild(document.createTextNode(css));
  60. }
  61. document.body.insertBefore(style, document.body.childNodes[0]);
  62. }
  63. }
  64. var setting={};
  65. setting.show=function(){
  66. var dom=document.getElementById('abpvn-custom-css');
  67. dom.style.display='block';
  68. type=document.getElementById('type').value;
  69. url=document.getElementById('url');
  70. switch(type){
  71. case 'hostname':
  72. url.disabled=true;
  73. url.value=location.hostname;
  74. css_hostname=localStorage.getItem('hostname:'+location.hostname)===null?'':localStorage.getItem('hostname:'+location.hostname);
  75. document.getElementById('css').value=css_hostname;
  76. break;
  77. default:
  78. url.disabled=true;
  79. url.value=location.href;
  80. css_url=localStorage.getItem('url:'+location.href)==null?'':localStorage.getItem('url:'+location.href);
  81. document.getElementById('css').value=css_url;
  82. break;
  83. }
  84. }
  85. setting.hide=function(){
  86. var dom=document.getElementById('abpvn-custom-css');
  87. dom.style.display='none';
  88. }
  89. setting.save=function(){
  90. key=document.getElementById('url').value;
  91. type=document.getElementById('type').value;
  92. value=document.getElementById('css').value;
  93. localStorage.setItem(type+':'+key,value);
  94. if(document.body.childNodes[0].nodeName=='STYLE') document.body.removeChild(document.body.childNodes[0]);
  95. ApplyStyle();
  96. setting.hide();
  97. }
  98. setting.switchtype=function(){
  99. type=document.getElementById('type').value;
  100. url=document.getElementById('url');
  101. switch(type){
  102. case 'hostname':
  103. url.disabled=true;
  104. url.value=location.hostname;
  105. css_hostname=localStorage.getItem('hostname:'+location.hostname)===null?'':localStorage.getItem('hostname:'+location.hostname);
  106. document.getElementById('css').value=css_hostname;
  107. break;
  108. default:
  109. url.disabled=true;
  110. url.value=location.href;
  111. css_url=localStorage.getItem('url:'+location.href)==null?'':localStorage.getItem('url:'+location.href);
  112. document.getElementById('css').value=css_url;
  113. break;
  114. }
  115. }
  116. function init(){
  117. var button=create(add_html);
  118. var fragment = create(html);
  119. // You can use native DOM methods to insert the fragment:
  120. document.body.insertBefore(fragment, document.body.childNodes[0]);
  121. document.body.insertBefore(button, document.body.childNodes[0]);
  122. document.getElementById('btn-add').addEventListener('click',setting.show,true);
  123. document.getElementById('btn-cancel').addEventListener('click',setting.hide,true);
  124. document.getElementById('btn-save').addEventListener('click',setting.save,true);
  125. document.getElementById('type').addEventListener('change',setting.switchtype,true);
  126. url=document.getElementById('url').value=location.hostname;
  127. ApplyStyle();
  128. }
  129. init();