Bläddra i källkod

Migrate to space indentation

simov 10 år sedan
förälder
incheckning
cf512eb7ac
6 ändrade filer med 316 tillägg och 316 borttagningar
  1. 46 46
      chrome/background.js
  2. 29 29
      chrome/markdown.js
  3. 55 55
      js/content.js
  4. 63 63
      js/mdviewer.js
  5. 98 98
      manifest.json
  6. 25 25
      views/popup.html

+ 46 - 46
chrome/background.js

@@ -1,61 +1,61 @@
 // chrome.storage.sync.clear()
 chrome.storage.sync.get(function (sync) {
-    if (!sync.options)
-        chrome.storage.sync.set({options: md.defaults})
-    if (!sync.theme)
-        chrome.storage.sync.set({theme: 'github'})
-    if (sync.raw === undefined)
-        chrome.storage.sync.set({raw: false})
+  if (!sync.options)
+    chrome.storage.sync.set({options: md.defaults})
+  if (!sync.theme)
+    chrome.storage.sync.set({theme: 'github'})
+  if (sync.raw === undefined)
+    chrome.storage.sync.set({raw: false})
 })
 
 chrome.tabs.onUpdated.addListener(function (id, info, tab) {
-    if (info.status === 'complete') return
-    if (/.*\/.*\.(?:markdown|mdown|mkdn|md|mkd|mdwn|mdtxt|mdtext|text)(?:#.*)?$/
-        .test(tab.url)) {
-        chrome.pageAction.show(id)
-    }
+  if (info.status === 'complete') return
+  if (/.*\/.*\.(?:markdown|mdown|mkdn|md|mkd|mdwn|mdtxt|mdtext|text)(?:#.*)?$/
+    .test(tab.url)) {
+    chrome.pageAction.show(id)
+  }
 })
 
 chrome.extension.onMessage.addListener(function (req, sender, sendResponse) {
-    switch (req.message) {
-        case 'markdown':
-            md.compile(req.markdown, sendResponse)
-            break
-        
-        case 'settings':
-            chrome.storage.sync.get(['options', 'theme', 'raw'], function (data) {
-                delete data.options.langPrefix
-                sendResponse(data)
-            })
-            break
+  switch (req.message) {
+    case 'markdown':
+      md.compile(req.markdown, sendResponse)
+      break
+    
+    case 'settings':
+      chrome.storage.sync.get(['options', 'theme', 'raw'], function (data) {
+        delete data.options.langPrefix
+        sendResponse(data)
+      })
+      break
 
-        case 'options':
-            req.options.langPrefix = 'language-'//prism
-            chrome.storage.sync.set({options: req.options}, sendResponse)
-            sendMessage({message: 'reload'})
-            break
-        case 'defaults':
-            chrome.storage.sync.set({options: md.defaults}, sendResponse)
-            chrome.storage.sync.set({theme: 'github'})
-            chrome.storage.sync.set({raw: false})
-            sendMessage({message: 'reload'})
-            break
+    case 'options':
+      req.options.langPrefix = 'language-'//prism
+      chrome.storage.sync.set({options: req.options}, sendResponse)
+      sendMessage({message: 'reload'})
+      break
+    case 'defaults':
+      chrome.storage.sync.set({options: md.defaults}, sendResponse)
+      chrome.storage.sync.set({theme: 'github'})
+      chrome.storage.sync.set({raw: false})
+      sendMessage({message: 'reload'})
+      break
 
-        case 'theme':
-            chrome.storage.sync.set({theme: req.theme}, sendResponse)
-            sendMessage({message: 'theme', theme: req.theme})
-            break
+    case 'theme':
+      chrome.storage.sync.set({theme: req.theme}, sendResponse)
+      sendMessage({message: 'theme', theme: req.theme})
+      break
 
-        case 'raw':
-            chrome.storage.sync.set({raw: req.raw}, sendResponse)
-            sendMessage({message: 'raw'})
-            break
-    }
-    return true
+    case 'raw':
+      chrome.storage.sync.set({raw: req.raw}, sendResponse)
+      sendMessage({message: 'raw'})
+      break
+  }
+  return true
 })
 
 function sendMessage (obj) {
-    chrome.tabs.query({active: true, currentWindow: true}, function (tabs) {
-        chrome.tabs.sendMessage(tabs[0].id, obj)
-    })
+  chrome.tabs.query({active: true, currentWindow: true}, function (tabs) {
+    chrome.tabs.sendMessage(tabs[0].id, obj)
+  })
 }

+ 29 - 29
chrome/markdown.js

@@ -1,35 +1,35 @@
 
 var md = (function () {
-    // marked
-    var defaults = {
-        gfm: true,
-        // highlight: null,
-        tables: true,
-        breaks: false,
-        pedantic: false,
-        sanitize: true,
-        smartLists: true,
-        smartypants: false,
-        langPrefix: 'language-'//prism
-    }
+  // marked
+  var defaults = {
+    gfm: true,
+    // highlight: null,
+    tables: true,
+    breaks: false,
+    pedantic: false,
+    sanitize: true,
+    smartLists: true,
+    smartypants: false,
+    langPrefix: 'language-'//prism
+  }
 
-    function compile (markdown, sendResponse) {
-        chrome.storage.sync.get(function (sync) {
-            marked.setOptions(sync.options)
+  function compile (markdown, sendResponse) {
+    chrome.storage.sync.get(function (sync) {
+      marked.setOptions(sync.options)
 
-            marked(markdown, function (err, html) {
-                if (err) throw err
-                // prism fix
-                html = html.replace(/language-html/g, 'language-markup')
-                html = html.replace(/language-js/g, 'language-javascript')
-                
-                sendResponse({message: 'marked', marked: html})
-            })
-        })
-    }
+      marked(markdown, function (err, html) {
+        if (err) throw err
+        // prism fix
+        html = html.replace(/language-html/g, 'language-markup')
+        html = html.replace(/language-js/g, 'language-javascript')
+        
+        sendResponse({message: 'marked', marked: html})
+      })
+    })
+  }
 
-    return {
-        defaults: defaults,
-        compile: compile
-    }
+  return {
+    defaults: defaults,
+    compile: compile
+  }
 }())

+ 55 - 55
js/content.js

@@ -1,69 +1,69 @@
 
 function injectCSS () {
-    var link = document.createElement('link')
-    link.rel = 'stylesheet'
-    link.type = 'text/css'
-    link.href = '#'
-    link.id = 'theme'
-    document.head.appendChild(link)
+  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()
-
-    chrome.extension.sendMessage({
-        message: 'markdown',
-        markdown: $('#markdown').text()
-    }, function (res) {
-        $('body').append('<div id="html">').find('#html').append(res.marked)
-        Prism.highlightAll()
-    })
+  injectCSS()
+  
+  $('body').addClass('markdown-body')//github
+  $('pre').attr('id', 'markdown').hide()
 
-    chrome.extension.sendMessage({
-        message: 'settings',
-    }, function (data) {
-        $('#theme').attr('href', chrome.extension.getURL('/themes/'+data.theme+'.css'))
-        
-        $('#theme').attr('disabled', data.raw)
-        $('#markdown')[data.raw?'show':'hide']()
-        $('#html')[data.raw?'hide':'show']()
-    })
+  chrome.extension.sendMessage({
+    message: 'markdown',
+    markdown: $('#markdown').text()
+  }, function (res) {
+    $('body').append('<div id="html">').find('#html').append(res.marked)
+    Prism.highlightAll()
+  })
 
-    $(window).on('load', function (e) {
-        setTimeout(function () {
-            var timeout = null
-            $(window).on('scroll', function (e) {
-                clearTimeout(timeout)
-                timeout = setTimeout(function () {
-                    localStorage.setItem('scrolltop', $(window).scrollTop())
-                }, 100)
-            })
+  chrome.extension.sendMessage({
+    message: 'settings',
+  }, function (data) {
+    $('#theme').attr('href', chrome.extension.getURL('/themes/'+data.theme+'.css'))
+    
+    $('#theme').attr('disabled', data.raw)
+    $('#markdown')[data.raw?'show':'hide']()
+    $('#html')[data.raw?'hide':'show']()
+  })
 
-            $(window).scrollTop(localStorage.getItem('scrolltop'))
+  $(window).on('load', function (e) {
+    setTimeout(function () {
+      var timeout = null
+      $(window).on('scroll', function (e) {
+        clearTimeout(timeout)
+        timeout = setTimeout(function () {
+          localStorage.setItem('scrolltop', $(window).scrollTop())
         }, 100)
-    })
+      })
+
+      $(window).scrollTop(localStorage.getItem('scrolltop'))
+    }, 100)
+  })
 })
 
 chrome.extension.onMessage.addListener(function (req, sender, sendResponse) {
-    switch (req.message) {
-        case 'reload':
-            window.location.reload(true)
-            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
+  switch (req.message) {
+    case 'reload':
+      window.location.reload(true)
+      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':
-            $('#theme').attr('disabled', !($('#theme').attr('disabled') == 'disabled'))
-            $('#markdown, #html').toggle()
-            break
-    }
+    case 'raw':
+      $('#theme').attr('disabled', !($('#theme').attr('disabled') == 'disabled'))
+      $('#markdown, #html').toggle()
+      break
+  }
 })

+ 63 - 63
js/mdviewer.js

@@ -3,75 +3,75 @@
 var mdviewer = angular.module('mdviewer', [])
 
 function toArray (obj, key, value) {
-    var arr = []
-    for (var k in obj) {
-        var tmp = {}
-        tmp[key] = k
-        tmp[value] = obj[k]
-        arr.push(tmp)
-    }
-    return arr
+  var arr = []
+  for (var k in obj) {
+    var tmp = {}
+    tmp[key] = k
+    tmp[value] = obj[k]
+    arr.push(tmp)
+  }
+  return arr
 }
 
 function toObject (arr, key, value) {
-    var obj = {}
-    for (var i=0; i < arr.length; i++) {
-        obj[arr[i][key]] = arr[i][value]
-    }
-    return obj
+  var obj = {}
+  for (var i=0; i < arr.length; i++) {
+    obj[arr[i][key]] = arr[i][value]
+  }
+  return obj
 }
 
 mdviewer.controller('popup', ['$scope', function ($scope) {
-    function init () {
-        chrome.extension.sendMessage({
-            message: 'settings'
-        }, function (res) {
-            $scope.options = toArray(res.options, 'name', 'enabled')
-            
-            $scope.themes = chrome.runtime.getManifest().web_accessible_resources
-                .filter(function (file) {return file.indexOf('/themes/') == 0})
-                .map(function (file) {
-                    var name = file.replace(/\/themes\/(.*)\.css/,'$1')
-                    if (name == res.theme) $scope.theme = {name: name}
-                    return {name: name}
-                })
-
-            $scope.raw = res.raw
-            $scope.$digest()
-        })
-    }
-    init()
-    
-    $scope.onOptions = function () {
-        chrome.extension.sendMessage({
-            message: 'options',
-            options: toObject(JSON.parse(angular.toJson($scope.options)), 'name', 'enabled')
-        }, function (res) {
-            
+  function init () {
+    chrome.extension.sendMessage({
+      message: 'settings'
+    }, function (res) {
+      $scope.options = toArray(res.options, 'name', 'enabled')
+      
+      $scope.themes = chrome.runtime.getManifest().web_accessible_resources
+        .filter(function (file) {return file.indexOf('/themes/') == 0})
+        .map(function (file) {
+          var name = file.replace(/\/themes\/(.*)\.css/,'$1')
+          if (name == res.theme) $scope.theme = {name: name}
+          return {name: name}
         })
-    }
-    $scope.onTheme = function () {
-        chrome.extension.sendMessage({
-            message: 'theme',
-            theme: $scope.theme.name
-        }, function (res) {
 
-        })
-    }
-    $scope.onRaw = function () {
-        $scope.raw = !$scope.raw
-        chrome.extension.sendMessage({
-            message: 'raw',
-            raw: $scope.raw
-        }, function (res) {
-            
-        })
-    }
-    $scope.onDefaults = function () {
-        chrome.extension.sendMessage({
-            message: 'defaults'
-        }, function (res) {
-            init()
-        })
-    }
+      $scope.raw = res.raw
+      $scope.$digest()
+    })
+  }
+  init()
+  
+  $scope.onOptions = function () {
+    chrome.extension.sendMessage({
+      message: 'options',
+      options: toObject(JSON.parse(angular.toJson($scope.options)), 'name', 'enabled')
+    }, function (res) {
+      
+    })
+  }
+  $scope.onTheme = function () {
+    chrome.extension.sendMessage({
+      message: 'theme',
+      theme: $scope.theme.name
+    }, function (res) {
+
+    })
+  }
+  $scope.onRaw = function () {
+    $scope.raw = !$scope.raw
+    chrome.extension.sendMessage({
+      message: 'raw',
+      raw: $scope.raw
+    }, function (res) {
+      
+    })
+  }
+  $scope.onDefaults = function () {
+    chrome.extension.sendMessage({
+      message: 'defaults'
+    }, function (res) {
+      init()
+    })
+  }
 }])

+ 98 - 98
manifest.json

@@ -1,108 +1,108 @@
 {
-    "manifest_version": 2,
-    "name"            : "Markdown Viewer",
-    "version"         : "1.6",
-    "description"     : "Markdown Viewer",
+  "manifest_version": 2,
+  "name"            : "Markdown Viewer",
+  "version"         : "1.6",
+  "description"     : "Markdown Viewer",
 
-    "page_action": {
-        "default_icon": {
-            "19" : "/images/icon19.png",
-            "38" : "/images/icon38.png"
-        },
-        "default_title": "Markdown Viewer",
-        "default_popup": "/views/popup.html"
+  "page_action": {
+    "default_icon": {
+      "19" : "/images/icon19.png",
+      "38" : "/images/icon38.png"
     },
-    
-    "background" : {
-        "scripts": [
-            "/jslib/marked.js",
-            "/chrome/markdown.js",
-            "/chrome/background.js"
-        ],
-        "persistent": false
-    },
-
-    "content_scripts": [
-        {
-            "matches": [
-                "*://*/*.markdown",
-                "*://*/*.mdown",
-                "*://*/*.mkdn",
-                "*://*/*.md",
-                "*://*/*.mkd",
-                "*://*/*.mdwn",
-                "*://*/*.mdtxt",
-                "*://*/*.mdtext",
-                "*://*/*.text",
-                "file:///*/*.markdown",
-                "file:///*/*.mdown",
-                "file:///*/*.mkdn",
-                "file:///*/*.md",
-                "file:///*/*.mkd",
-                "file:///*/*.mdwn",
-                "file:///*/*.mdtxt",
-                "file:///*/*.mdtext",
-                "file:///*/*.text"
-            ],
-            "exclude_matches": [
-                "*://github.com/*",
-                "*://bitbucket.org/*",
-                "*://gitlab.com/*"
-            ],
-            "css": [
-                "/css/prism.css"
-            ],
-            "js": [
-                "/jslib/jquery-2.0.3.min.js",
-                "/jslib/prism.js",
-                "/js/content.js"
-            ],
-            "run_at": "document_start",
-            "all_frames": true
-        }
+    "default_title": "Markdown Viewer",
+    "default_popup": "/views/popup.html"
+  },
+  
+  "background" : {
+    "scripts": [
+      "/jslib/marked.js",
+      "/chrome/markdown.js",
+      "/chrome/background.js"
     ],
+    "persistent": false
+  },
 
-    "web_accessible_resources": [
-        "/jslib/jquery-2.0.3.min.map",
+  "content_scripts": [
+    {
+      "matches": [
+        "*://*/*.markdown",
+        "*://*/*.mdown",
+        "*://*/*.mkdn",
+        "*://*/*.md",
+        "*://*/*.mkd",
+        "*://*/*.mdwn",
+        "*://*/*.mdtxt",
+        "*://*/*.mdtext",
+        "*://*/*.text",
+        "file:///*/*.markdown",
+        "file:///*/*.mdown",
+        "file:///*/*.mkdn",
+        "file:///*/*.md",
+        "file:///*/*.mkd",
+        "file:///*/*.mdwn",
+        "file:///*/*.mdtxt",
+        "file:///*/*.mdtext",
+        "file:///*/*.text"
+      ],
+      "exclude_matches": [
+        "*://github.com/*",
+        "*://bitbucket.org/*",
+        "*://gitlab.com/*"
+      ],
+      "css": [
+        "/css/prism.css"
+      ],
+      "js": [
+        "/jslib/jquery-2.0.3.min.js",
+        "/jslib/prism.js",
+        "/js/content.js"
+      ],
+      "run_at": "document_start",
+      "all_frames": true
+    }
+  ],
 
-        "/themes/github.css",
-         
-        "/themes/avenir-white.css",
-        "/themes/foghorn.css",
-        "/themes/jasonm23-dark.css",
-        "/themes/jasonm23-foghorn.css",
-        "/themes/jasonm23-markdown.css",
-        "/themes/jasonm23-swiss.css",
-        "/themes/markdown10.css",
-        "/themes/markdown1.css",
-        "/themes/markdown2.css",
-        "/themes/markdown3.css",
-        "/themes/markdown4.css",
-        "/themes/markdown5.css",
-        "/themes/markdown6.css",
-        "/themes/markdown7.css",
-        "/themes/markdown8.css",
-        "/themes/markdown9.css",
-        "/themes/markdown-alt.css",
-        "/themes/markdown.css",
-        "/themes/markedapp-byword.css",
-        "/themes/screen.css",
-        "/themes/swiss.css",
-        "/themes/thomasf-solarizedcssdark.css",
-        "/themes/thomasf-solarizedcsslight.css"
-    ],
+  "web_accessible_resources": [
+    "/jslib/jquery-2.0.3.min.map",
 
-    "icons": {
-        "16" : "/images/icon16.png",
-        "48" : "/images/icon48.png",
-        "128": "/images/icon128.png"
-    },
-    "homepage_url": "https://chrome.google.com/webstore/detail/markdown-viewer/ckkdlimhmcjmikdlpkmbgfkaikojcbjk",
+    "/themes/github.css",
+     
+    "/themes/avenir-white.css",
+    "/themes/foghorn.css",
+    "/themes/jasonm23-dark.css",
+    "/themes/jasonm23-foghorn.css",
+    "/themes/jasonm23-markdown.css",
+    "/themes/jasonm23-swiss.css",
+    "/themes/markdown10.css",
+    "/themes/markdown1.css",
+    "/themes/markdown2.css",
+    "/themes/markdown3.css",
+    "/themes/markdown4.css",
+    "/themes/markdown5.css",
+    "/themes/markdown6.css",
+    "/themes/markdown7.css",
+    "/themes/markdown8.css",
+    "/themes/markdown9.css",
+    "/themes/markdown-alt.css",
+    "/themes/markdown.css",
+    "/themes/markedapp-byword.css",
+    "/themes/screen.css",
+    "/themes/swiss.css",
+    "/themes/thomasf-solarizedcssdark.css",
+    "/themes/thomasf-solarizedcsslight.css"
+  ],
 
-    "permissions": [
-        "tabs",
-        "storage"
-    ],
+  "icons": {
+    "16" : "/images/icon16.png",
+    "48" : "/images/icon48.png",
+    "128": "/images/icon128.png"
+  },
+  "homepage_url": "https://chrome.google.com/webstore/detail/markdown-viewer/ckkdlimhmcjmikdlpkmbgfkaikojcbjk",
+
+  "permissions": [
+    "tabs",
+    "storage"
+  ],
 
-    "content_security_policy": "script-src 'unsafe-eval'; object-src 'self'"
+  "content_security_policy": "script-src 'unsafe-eval'; object-src 'self'"
 }

+ 25 - 25
views/popup.html

@@ -1,36 +1,36 @@
 <!DOCTYPE html>
 <html ng-app="mdviewer">
 <head>
-    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
-    <title>Markdown Viewer</title>
+  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+  <title>Markdown Viewer</title>
 
-    <link href="/css/mdviewer.css" rel="stylesheet" type="text/css" media="all" />
+  <link href="/css/mdviewer.css" rel="stylesheet" type="text/css" media="all" />
 
-    <script src="/jslib/angular.min.js" type="text/javascript" charset="utf-8"></script>
-    <script src="/js/mdviewer.js" type="text/javascript" charset="utf-8"></script>
+  <script src="/jslib/angular.min.js" type="text/javascript" charset="utf-8"></script>
+  <script src="/js/mdviewer.js" type="text/javascript" charset="utf-8"></script>
 </head>
 <body ng-controller="popup">
-    
-    <a href="" ng-click="onRaw()">{{raw ? 'Html' : 'Markdown'}}</a>
-    <a href="" ng-click="onDefaults()">Defaults</a>
-    
-    <h4>Theme</h4>
-    <select
-        ng-model="theme"
-        ng-change="onTheme()"
-        ng-options="theme.name for theme in themes track by theme.name">
-    </select>
+  
+  <a href="" ng-click="onRaw()">{{raw ? 'Html' : 'Markdown'}}</a>
+  <a href="" ng-click="onDefaults()">Defaults</a>
+  
+  <h4>Theme</h4>
+  <select
+    ng-model="theme"
+    ng-change="onTheme()"
+    ng-options="theme.name for theme in themes track by theme.name">
+  </select>
 
-    <h4>Compiler Options</h4>
-    <ul>
-        <li ng-repeat="option in options">
-            <label>
-                <input type="checkbox" ng-model="option.enabled" ng-change="onOptions()" />
-                {{option.name}}
-            </label>
-            
-        </li>
-    </ul>
+  <h4>Compiler Options</h4>
+  <ul>
+    <li ng-repeat="option in options">
+      <label>
+        <input type="checkbox" ng-model="option.enabled" ng-change="onOptions()" />
+        {{option.name}}
+      </label>
+      
+    </li>
+  </ul>
 
 </body>
 </html>