jQuery CssDynamic

A dinamic system to customize style css. It append the rules in the end of body

Script này sẽ không được không được cài đặt trực tiếp. Nó là một thư viện cho các script khác để bao gồm các chỉ thị meta // @require https://update.greatest.deepsurf.us/scripts/26587/169714/jQuery%20CssDynamic.js

  1. // ==UserScript==
  2. // @author Matteo Burbui @maxeo90
  3. // @name jQuery CssDynamic
  4. // @description A dinamic system to customize style css. It append the rules in the end of body
  5. // @license https://creativecommons.org/licenses/by-sa/4.0/
  6. // @version 1.1.1
  7. // @grant none
  8. // ==/UserScript==
  9. (function( $ ){
  10. $.fn.cssDynamic = function(prop) {
  11. var selector=$(this).selector;
  12. var data,fval,action,idStyle,newName;
  13. if(typeof(prop)=='object'){
  14. fval=1,data='';
  15. for (var k in prop){
  16. if (prop.hasOwnProperty(k)) {
  17. data+=k+':'+prop[k]+';'
  18. }
  19. }
  20. }else if(prop=='rename' && arguments[2]!=undefined ){
  21. fval=0;
  22. newName=arguments[2];
  23. }else if(arguments[1]!=undefined){
  24. fval=2;
  25. data=arguments[0]+':'+arguments[1]
  26. }else if(prop=='remove'){
  27. fval=0;
  28. } else{return 'error'}
  29. action=(arguments[fval]==undefined)?'add':arguments[fval];
  30. idStyle=(arguments[fval+1]==undefined)?'cssDynamic':arguments[fval+1];
  31. switch(action) {
  32. case 'new':
  33. actNew()
  34. break;
  35. case 'add':
  36. actAdd()
  37. break;
  38. case 'remove':
  39. actRemove()
  40. break;
  41. case 'renew':
  42. actRemove()
  43. actNew()
  44. break;
  45. case 'rename':
  46. actRename()
  47. break;
  48. }
  49. function chData(){
  50. data=selector+'{'+data+'}'
  51. }
  52. function actNew(){
  53. chData();
  54. $('body').append('<style id="'+idStyle+'">'+data+'</style>')
  55. }
  56. function actAdd(){
  57. if(!$('#'+idStyle).length){
  58. actNew()
  59. }else{
  60. chData();
  61. $('style#'+idStyle).append(data)
  62. }
  63. }
  64. function actRemove(){
  65. $('style#'+idStyle).remove();
  66. }
  67. function actRename(){
  68. $('style#'+idStyle).attr('id',newName);
  69. }
  70. return this;
  71. };
  72. })( jQuery );