Greasy Fork is available in English.

ABPVN Custom CSS

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

ของเมื่อวันที่ 26-08-2015 ดู เวอร์ชันล่าสุด

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