代码之家  ›  专栏  ›  技术社区  ›  J.C

你是如何使用Chrome扩展程序在一个月内更改网站的CSS的?

  •  0
  • J.C  · 技术社区  · 2 年前

    我想更改一个网站的css样式,但只有在月份,我怎么能做到这一点?

    这是我只想在死亡月份包括的css。我如何在content.js或manifest.json中做到这一点

    .Tile-module_tile__UWEHN[data-state=absent] {
        background-color: #b20000  !important;
    }
    
    .Key-module_key__kchQI[data-state=absent] {
        background-color: #b20000  !important;
    }
    
    .Key-module_key__kchQI[data-state=present] {
        background-color: #f1c232  !important;
    }
    
    .Tile-module_tile__UWEHN[data-state=present] {
        background-color: #f1c232  !important;
    }
    
    .Key-module_key__kchQI[data-state=correct] {
        background-color: #008000  !important;
    }
    
    .Tile-module_tile__UWEHN[data-state=correct] {
        background-color: #008000  !important;
    }
    
    1 回复  |  直到 2 年前
        1
  •  1
  •   PassingThru    2 年前

    要检查当前月份是否为12月(月份为零)。。。快速测试:

    if(new Date().getMonth()==11){ alert('It must be december'); } else { alert('some other month'); }
    

    要将CSS添加到文档中。。。

    var S=document.createElement('style');
    
    S.innerText=''; // <-- Place all your Xmas CSS in this string
    
    document.head.appendChild(S); // <-- If this doesn't work for you use the next line instead
    
    // document.getElementsByTagName('head')[0].appendChild(S);
    

    把它们放在一起。。。

    if(new Date().getMonth()==11){ // If December proceed...
    
     var S=document.createElement('style');
    
     S.innerText=''; // <-- Place all your Xmas CSS from above in this string
    
     document.head.appendChild(S);
    
    }
    

    NB :使用。。。

    Window_ID.contentWindow.document.
    

    如果不是你的网站和使用脚本。