Showing 1 changed files with 20 additions and 7 deletions
+20 -7
index.php
... ...
@@ -30,20 +30,29 @@ function NewsSection($sourceHTML) {
30 30
     <link rel="shortcut icon" href="favicon.png">
31 31
     <link href="css/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
32 32
     <link rel="stylesheet" type="text/css" href="css/style.css" />
33
+    <link rel="alternate stylesheet" type="text/css" id="style-dynamic" href="" />
33 34
     <script>
35
+    function changeCSS(cssFile, cssLinkIndex) {
36
+      var oldlink = document.getElementsByTagName("link").item(cssLinkIndex);
37
+      var newlink = document.createElement("link");
38
+      newlink.setAttribute("rel", "stylesheet");
39
+      newlink.setAttribute("type", "text/css");
40
+      newlink.setAttribute("href", cssFile);
41
+      document.getElementsByTagName("head").item(0).replaceChild(newlink, oldlink);
42
+    }
34 43
     function getStylesheet() {
35
-      var x = document.getElementById("style-active");
36
-      var btn = document.getElementById("style-btn");
37 44
       var currentTime = new Date().getHours();
38 45
       if (0 <= currentTime && currentTime < 8) {
39
-        document.write("<link rel='stylesheet' href='css/style-night.css' type='text/css'>");
46
+        //document.write("<link rel='stylesheet' href='css/style-night.css' type='text/css'>");
47
+        changeCSS('css/style-night.css',3);
40 48
       } else if (8 <= currentTime && currentTime < 19) {
41
-        document.write("<link rel='stylesheet' href='css/style-day.css' type='text/css'>");
49
+        changeCSS('css/style-day.css',3);
42 50
       } else if (19 <= currentTime && currentTime < 24) {
43
-        document.write("<link rel='stylesheet' href='css/style-night.css' type='text/css'>");
51
+        changeCSS('css/style-night.css',3);
44 52
       }
45 53
     }
46 54
     getStylesheet();
55
+
47 56
     </script>
48 57
     <script>
49 58
     function onArticle(index) {
... ...
@@ -71,14 +80,15 @@ function NewsSection($sourceHTML) {
71 80
     function forceStylesheet() {
72 81
       var x = document.getElementById("style-active");
73 82
       var btn = document.getElementById("style-btn");
83
+
74 84
       if (x.className === "night") {
75 85
         x.className = "day";
76 86
         btn.innerHTML = '<i class="fa fa-sun-o fa-fw"></i>';
77
-        //document.write("<link rel='stylesheet' href='css/style-night.css' type='text/css'>");
87
+        changeCSS('css/style-day.css',3);
78 88
       } else {
79 89
         x.className = "night";
80 90
         btn.innerHTML = '<i class="fa fa-moon-o fa-fw"></i>';
81
-        //document.write("<link rel='stylesheet' href='css/style-day.css' type='text/css'>");
91
+        changeCSS('css/style-night.css',3);
82 92
       }
83 93
     }
84 94
 
... ...
@@ -90,12 +100,15 @@ function NewsSection($sourceHTML) {
90 100
       if (0 <= currentTime && currentTime < 8) {
91 101
         x.className = "night";
92 102
         btn.innerHTML = '<i class="fa fa-moon-o fa-fw"></i>';
103
+        changeCSS('css/style-night.css',3);
93 104
       } else if (8 <= currentTime && currentTime < 19) {
94 105
         x.className = "day";
95 106
         btn.innerHTML = '<i class="fa fa-sun-o fa-fw"></i>';
107
+        changeCSS('css/style-day.css',3);
96 108
       } else if (19 <= currentTime && currentTime < 24) {
97 109
         x.className = "night";
98 110
         btn.innerHTML = '<i class="fa fa-moon-o fa-fw"></i>';
111
+        changeCSS('css/style-night.css',3);
99 112
       }
100 113
     }
101 114
     </script>