| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 | 
							
- var $ = document.querySelector.bind(document)
 
- var state = {
 
-   theme: window['theme'] || '',
 
-   html: '',
 
-   markdown: '',
 
-   raw: window['raw'] || false,
 
-   getURL: () => chrome.runtime.getURL('/themes/' + state.theme + '.css')
 
- }
 
- chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
 
-   if (req.message === 'reload') {
 
-     window.location.reload(true)
 
-   }
 
-   else if (req.message === 'theme') {
 
-     state.theme = req.theme
 
-     m.redraw()
 
-   }
 
-   else if (req.message === 'raw') {
 
-     state.raw = req.raw
 
-     m.redraw()
 
-   }
 
- })
 
- var oncreate = {
 
-   markdown: () => {
 
-     document.body.scrollTop = parseInt(localStorage.getItem('md-' + location.href))
 
-   },
 
-   html: () => {
 
-     document.body.scrollTop = parseInt(localStorage.getItem('md-' + location.href))
 
-     setTimeout(() => Prism.highlightAll(), 20)
 
-   }
 
- }
 
- function mount () {
 
-   $('pre').style.display = 'none'
 
-   var md = $('pre').innerText
 
-   m.mount($('body'), {
 
-     oninit: () => {
 
-       ;((done) => {
 
-         if (document.charset === 'UTF-8') {
 
-           done()
 
-           return
 
-         }
 
-         m.request({method: 'GET', url: window.location.href,
 
-           deserialize: (body) => {
 
-             done(body)
 
-             return body
 
-           }
 
-         })
 
-       })((data) => {
 
-         state.markdown = data || md
 
-         chrome.runtime.sendMessage({
 
-           message: 'markdown',
 
-           markdown: state.markdown
 
-         }, (res) => {
 
-           state.html = res.marked
 
-           m.redraw()
 
-         })
 
-       })
 
-     },
 
-     view: () => {
 
-       var dom = []
 
-       if (state.raw) {
 
-         updateStyles()
 
-         dom.push(m('pre#markdown', {oncreate: oncreate.markdown}, state.markdown))
 
-       }
 
-       if (state.theme && !state.raw) {
 
-         updateStyles()
 
-         dom.push(m('link#theme [rel="stylesheet"] [type="text/css"]', {
 
-           href: state.getURL()
 
-         }))
 
-       }
 
-       if (state.html && !state.raw) {
 
-         dom.push(m('#html', {oncreate: oncreate.html}, m.trust(state.html)))
 
-       }
 
-       return (dom.length ? dom : m('div'))
 
-     }
 
-   })
 
- }
 
- function scroll () {
 
-   setTimeout(() => {
 
-     var timeout = null
 
-     window.addEventListener('scroll', () => {
 
-       clearTimeout(timeout)
 
-       timeout = setTimeout(() => {
 
-         localStorage.setItem('md-' + location.href, document.body.scrollTop)
 
-       }, 100)
 
-     })
 
-     document.body.scrollTop = parseInt(localStorage.getItem('md-' + location.href))
 
-   }, 100)
 
- }
 
- if (document.readyState === 'complete') {
 
-   mount()
 
-   scroll()
 
- }
 
- else {
 
-   window.addEventListener('DOMContentLoaded', mount)
 
-   window.addEventListener('load', scroll)
 
- }
 
- function updateStyles () {
 
-   if (state.raw) {
 
-     $('html').classList.remove('markdown-theme-html')
 
-     $('body').classList.remove('markdown-theme')
 
-     $('html').classList.remove('markdown-body-html')
 
-     $('body').classList.remove('markdown-body')
 
-   }
 
-   else if (/github(-dark)?/.test(state.theme)) {
 
-     $('html').classList.remove('markdown-theme-html')
 
-     $('body').classList.remove('markdown-theme')
 
-     $('html').classList.add('markdown-body-html')
 
-     $('body').classList.add('markdown-body')
 
-   }
 
-   else {
 
-     $('html').classList.remove('markdown-body-html')
 
-     $('body').classList.remove('markdown-body')
 
-     $('html').classList.add('markdown-theme-html')
 
-     $('body').classList.add('markdown-theme')
 
-   }
 
- }
 
 
  |