JavaScript で、スタイルシートを作る & 雑記

今日は、がっかりが続く。朝から八戸の親戚の法事があった。「ちょっとした法事だから気さくにどうぞ。」というから、気楽に出かけた。おいおい!みんな黒の礼服じゃん、俺はネクタイだけ黒。あぁ〜1。


終わったら食事にと、ホテル。おぅ〜すげぇ!家族3人で行ったのに、これは1人1万コースだな。仏壇にお供えした2万円じゃ〜少なかったな!ということで、ご先祖様!あとで穴埋めします。あぁ〜2。
(ちなみにお供えしたお線香とローソクは、差額の半値相当です)

今日は携帯電話の充電がやばかった。案の定電池切れ。そういうときに重大な用件が舞い込む!なんと、先日行ってきたばかりの宮城県白石市の社長が、訪問してきたというのだ!なんと20年ぶりか!?それで連絡がとれず、会わずじまいで帰ってしまった!あぁ〜3


細かい事を書き出すと切が無いほど、今日という日は、あぁ〜である。

スクリプトスタイルシートの新規作成したいのだけれど、どうもスマートじゃない気がする

<!DOCTYPE html>
<title>Test</title>


<div id="Header">
  <ul id="">
    <li>
      Small
    <li>
      Normal
    <li>
      Large
  </ul>
</div>
<script type="text/javascript"><!--
//@cc_on
  // StyleSheet の追加 ( this = document にして call )
  var CreateStyleSheet = function ( ) {
    var head = this.getElementsByTagName( 'head' )[0] || this.documentElement;
    var sheet;
    /*@if( @_jscript )
      sheet = this.createStyleSheet( );
    @else@*/
      sheet = this.createElement( 'style' );
      sheet.appendChild( this.createTextNode( '' ) );
      sheet.type = 'text/css';
      head.appendChild( sheet );
      sheet = this.styleSheets[ this.styleSheets.length - 1 ]; // ←ここ
    /*@end@*/
    
    return sheet;
  };
 
  
  // StyleSheet に ルールを追加 ( this = document にして call )
  var addRule = function ( selector, property ) {
    /*@if( @_jscript )
      this.addRule( selector, property );
    @else@*/
      this.insertRule( selector + '{' + property + '}', 
        ( 'undefined' == typeof this.cssRules ? 0: this.cssRules.length ) );
    /*@end@*/
  };

var sheet = CreateStyleSheet.call( document );
addRule.call( sheet, 'ul', 'background:#f8f' );
//-->
</script>
</html>

sheet = this.styleSheets[ this.styleSheets.length - 1 ];
せっかくの sheet をそのまま返すと addRule でエラーになる。
明日への課題。


think49 さん
これ回答に使う?

function lastDay( y, m ){
return (m^m>7|30)+(m==2)*~(y%(y%100>0?4:400)>0);
}