Greasy Fork镜像 还支持 简体中文。

ABPVN Custom CSS

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

目前為 2015-08-26 提交的版本,檢視 最新版本

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址