Browse Source

Remove/append theme css to force redraw

simov 11 years ago
parent
commit
cb01238b27
1 changed files with 15 additions and 9 deletions
  1. 15 9
      js/content.js

+ 15 - 9
js/content.js

@@ -1,14 +1,16 @@
 
-$(function () {
-    (function injectCSS () {
-        var link = document.createElement('link');
-        link.rel = 'stylesheet';
-        link.type = 'text/css';
-        link.href = '#';
-        link.id = 'theme';
-        document.head.appendChild(link);
-    }());
+function injectCSS () {
+    var link = document.createElement('link');
+    link.rel = 'stylesheet';
+    link.type = 'text/css';
+    link.href = '#';
+    link.id = 'theme';
+    document.head.appendChild(link);
+};
 
+$(function () {
+    injectCSS();
+    
     $('body').addClass('markdown-body');//github
     $('pre').attr('id', 'markdown').hide();
 
@@ -38,7 +40,11 @@ chrome.extension.onMessage.addListener(function (req, sender, sendResponse) {
             break;
         
         case 'theme':
+            var raw = $('#theme').attr('disabled') == 'disabled';
+            $('#theme').remove();
+            injectCSS();
             $('#theme').attr('href', chrome.extension.getURL('/themes/'+req.theme+'.css'));
+            $('#theme').attr('disabled', raw);
             break;
 
         case 'raw':