<|start_filename|>markdownreader.js<|end_filename|>
(function(document) {
	
	//忽略HTML代码
	if (document.doctype) return;

    document.write('<!DOCTYPE html><html><head><body><div id="container" class="viewport-flip"><div id="text-container" class="content flip" style="display:none;"></div><div id="markdown-container" class="content flip"></div></div><div id="markdown-outline"></div><div id="markdown-backTop" onclick="window.scrollTo(0,0);"></div></body></html>');
    document.close();

	var link = document.createElement('link');
	link.rel = 'stylesheet';
	link.href = chrome.extension.getURL('markdownreader.css');
	document.head.appendChild(link);

	link = document.createElement('link');
	link.rel = 'stylesheet';
	link.href = chrome.extension.getURL('hljs.min.css');
	document.head.appendChild(link);

	link = document.createElement('link');
	link.rel = 'stylesheet';
	link.href = chrome.extension.getURL('katex.min.css');
	document.head.appendChild(link);

	window.onresize = showOutline;

	var jTextContainer = $('#text-container');
	var jMarkdownContainer = $('#markdown-container');
	var jOutline = $('#markdown-outline');

	var isMarkdownMode = true;
	$(document).on('dblclick',toggleMode);

	function toggleMode(e){
		// 内容区外点击才会切换模式
		if($(e.target).closest('.content').length === 0){
			if(isMarkdownMode){
				jMarkdownContainer.addClass('out').removeClass('in');
				isMarkdownMode = false;
				jMarkdownContainer.one('webkitAnimationEnd', function(){
					jTextContainer.show().addClass('in').removeClass('out');
					jMarkdownContainer.hide();
				});
			}
			else{
				jTextContainer.addClass('out').removeClass('in');
				jTextContainer.one('webkitAnimationEnd', function(){
					jMarkdownContainer.show().addClass('in').removeClass('out');
					jTextContainer.hide();
					isMarkdownMode = true;
				});
			}
			return false;
		}
	}

	jMarkdownContainer.on('webkitAnimationEnd', function(){
		if(isMarkdownMode){
			showOutline();
		}
		else{
			hideOutline();
		}
	});

	var markdownConverter = new showdown.Converter({
		tables: true,
		strikethrough: true,
		simplifiedAutoLink: true,
		tasklists: true,
		literalMidWordUnderscores: true
	});
	var lastText = null;
	var outlineCount = 0;

	function updateMarkdown(text) {
		if (text !== lastText) {
			lastText = text;
			jTextContainer.text(text.replace(/\r\n?|\r?\n/g, '\r\n'));
			jMarkdownContainer.html(markdownConverter.makeHtml(lastText));
	        $('code').each(function(i, block){
	        	if(this.parentNode && /^pre$/i.test(this.parentNode.tagName)){
	        		hljs.highlightBlock(block);
	        	}
	        	else{
	        		$(this).addClass('inline');
	        	}
	        })
			updateOutline();
		}
	}

	function updateOutline() {
		var arrAllHeader = document.querySelectorAll("h1,h2,h3,h4,h5,h6");
		var arrOutline = ['<ul>'];
		var header, headerText;
		var id = 0;
		var level = 0,
			lastLevel = 1;
		var levelCount = 0;
		for (var i = 0, c = arrAllHeader.length; i < c; i++) {
			header = arrAllHeader[i];
			headerText = header.innerText;

			header.setAttribute('id', id);

			level = header.tagName.match(/^h(\d)$/i)[1];
			levelCount = level - lastLevel;

			if (levelCount > 0) {
				for (var j = 0; j < levelCount; j++) {
					arrOutline.push('<ul>');
				}
			} else if (levelCount < 0) {
				levelCount *= -1;
				for (var j = 0; j < levelCount; j++) {
					arrOutline.push('</ul>');
				}
			};
			arrOutline.push('<li>');
			arrOutline.push('<a href="#' + id + '">' + headerText + '</a>');
			arrOutline.push('</li>');
			lastLevel = level;
			id++;
		}
		arrOutline.push('</ul>')
		outlineCount = id;
		if(outlineCount > 0){
			jOutline.html(arrOutline.join(''));
            jOutline.find('ul').each(function(i,n){
                var jThis = $(this);
                if(jThis.children('li').length === 0){
                    jThis.replaceWith(jThis.children());
                }
            });
			showOutline();
		}
		else{
			hideOutline();
		}
	}

	function showOutline() {
		if(outlineCount > 0){
			var offset = jMarkdownContainer.offset();
			jOutline.css({
				left: offset.left + jMarkdownContainer.outerWidth() + 10 + 'px',
				maxHeight: document.body.clientHeight - 30
			}).show();
		}
	}

	function hideOutline(){
		jOutline.hide();
	}

	var xmlhttp = new XMLHttpRequest();
	var fileurl = location.href,
		bLocalFile = /^file:\/\//i.test(fileurl);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status != 404) {
			updateMarkdown(xmlhttp.responseText);
		}
	};

	function checkUpdate() {
		xmlhttp.abort();
		xmlhttp.open("GET", fileurl + '?rnd=' + new Date().getTime(), true);
		xmlhttp.send(null);
		if (bLocalFile) setTimeout(checkUpdate, 500);
	}

	checkUpdate();

}(document));


<|start_filename|>manifest.json<|end_filename|>
{
	"manifest_version": 2,
	"name": "Markdown Reader",
	"version": "1.0.15",
	"description": "Read markdown file in Chrome.",
	"icons": {
		"128": "images/icon.png",
		"16": "images/icon.png",
		"48": "images/icon.png"
	},
	"permissions": ["tabs", "\u003Call_urls\u003E"],
	"content_scripts": [{
		"js": ["jquery-1.8.3.min.js", "highlight.min.js", "katex.min.js", "showdown.js", "markdownreader.js"],
		"matches": ["*://*/*.md", "file://*/*.md", "*://*/*.markdown", "file://*/*.markdown", "*://*/*.mdown", "file://*/*.mdown", "*://*/*.mkdn", "file://*/*.mkdn", "*://*/*.mkd", "file://*/*.mkd", "*://*/*.text", "file://*/*.text", "*://*/*.mdtext", "file://*/*.mdtext", "*://*/*.mdtxt", "file://*/*.mdtxt"],
		"run_at": "document_end"
	}],
	"web_accessible_resources": [
		"markdownreader.css",
		"images/backtop.gif",
		"katex.min.css",
		"hljs.min.css",
		"fonts/KaTeX_AMS-Regular.eot",
		"fonts/KaTeX_AMS-Regular.ttf",
		"fonts/KaTeX_AMS-Regular.woff",
		"fonts/KaTeX_AMS-Regular.woff2",
		"fonts/KaTeX_Caligraphic-Bold.eot",
		"fonts/KaTeX_Caligraphic-Bold.ttf",
		"fonts/KaTeX_Caligraphic-Bold.woff",
		"fonts/KaTeX_Caligraphic-Bold.woff2",
		"fonts/KaTeX_Caligraphic-Regular.eot",
		"fonts/KaTeX_Caligraphic-Regular.ttf",
		"fonts/KaTeX_Caligraphic-Regular.woff",
		"fonts/KaTeX_Caligraphic-Regular.woff2",
		"fonts/KaTeX_Fraktur-Bold.eot",
		"fonts/KaTeX_Fraktur-Bold.ttf",
		"fonts/KaTeX_Fraktur-Bold.woff",
		"fonts/KaTeX_Fraktur-Bold.woff2",
		"fonts/KaTeX_Fraktur-Regular.eot",
		"fonts/KaTeX_Fraktur-Regular.ttf",
		"fonts/KaTeX_Fraktur-Regular.woff",
		"fonts/KaTeX_Fraktur-Regular.woff2",
		"fonts/KaTeX_Main-Bold.eot",
		"fonts/KaTeX_Main-Bold.ttf",
		"fonts/KaTeX_Main-Bold.woff",
		"fonts/KaTeX_Main-Bold.woff2",
		"fonts/KaTeX_Main-Italic.eot",
		"fonts/KaTeX_Main-Italic.ttf",
		"fonts/KaTeX_Main-Italic.woff",
		"fonts/KaTeX_Main-Italic.woff2",
		"fonts/KaTeX_Main-Regular.eot",
		"fonts/KaTeX_Main-Regular.ttf",
		"fonts/KaTeX_Main-Regular.woff",
		"fonts/KaTeX_Main-Regular.woff2",
		"fonts/KaTeX_Math-BoldItalic.eot",
		"fonts/KaTeX_Math-BoldItalic.ttf",
		"fonts/KaTeX_Math-BoldItalic.woff",
		"fonts/KaTeX_Math-BoldItalic.woff2",
		"fonts/KaTeX_Math-Italic.eot",
		"fonts/KaTeX_Math-Italic.ttf",
		"fonts/KaTeX_Math-Italic.woff",
		"fonts/KaTeX_Math-Italic.woff2",
		"fonts/KaTeX_Math-Regular.eot",
		"fonts/KaTeX_Math-Regular.ttf",
		"fonts/KaTeX_Math-Regular.woff",
		"fonts/KaTeX_Math-Regular.woff2",
		"fonts/KaTeX_SansSerif-Bold.eot",
		"fonts/KaTeX_SansSerif-Bold.ttf",
		"fonts/KaTeX_SansSerif-Bold.woff",
		"fonts/KaTeX_SansSerif-Bold.woff2",
		"fonts/KaTeX_SansSerif-Italic.eot",
		"fonts/KaTeX_SansSerif-Italic.ttf",
		"fonts/KaTeX_SansSerif-Italic.woff",
		"fonts/KaTeX_SansSerif-Italic.woff2",
		"fonts/KaTeX_SansSerif-Regular.eot",
		"fonts/KaTeX_SansSerif-Regular.ttf",
		"fonts/KaTeX_SansSerif-Regular.woff",
		"fonts/KaTeX_SansSerif-Regular.woff2",
		"fonts/KaTeX_Script-Regular.eot",
		"fonts/KaTeX_Script-Regular.ttf",
		"fonts/KaTeX_Script-Regular.woff",
		"fonts/KaTeX_Script-Regular.woff2",
		"fonts/KaTeX_Size1-Regular.eot",
		"fonts/KaTeX_Size1-Regular.ttf",
		"fonts/KaTeX_Size1-Regular.woff",
		"fonts/KaTeX_Size1-Regular.woff2",
		"fonts/KaTeX_Size2-Regular.eot",
		"fonts/KaTeX_Size2-Regular.ttf",
		"fonts/KaTeX_Size2-Regular.woff",
		"fonts/KaTeX_Size2-Regular.woff2",
		"fonts/KaTeX_Size3-Regular.eot",
		"fonts/KaTeX_Size3-Regular.ttf",
		"fonts/KaTeX_Size3-Regular.woff",
		"fonts/KaTeX_Size3-Regular.woff2",
		"fonts/KaTeX_Size4-Regular.eot",
		"fonts/KaTeX_Size4-Regular.ttf",
		"fonts/KaTeX_Size4-Regular.woff",
		"fonts/KaTeX_Size4-Regular.woff2",
		"fonts/KaTeX_Typewriter-Regular.eot",
		"fonts/KaTeX_Typewriter-Regular.ttf",
		"fonts/KaTeX_Typewriter-Regular.woff",
		"fonts/KaTeX_Typewriter-Regular.woff2"
	]
}

<|start_filename|>markdownreader.css<|end_filename|>
*{
	margin:0;
	padding:0;
}

body{
	width: 100%;
}

.viewport-flip {
	-webkit-perspective: 1000;
	perspective: 1000;
	position: absolute;
}
.flip {
	-webkit-backface-visibility: hidden;
	-webkit-transform: translateX(0); /* Needed to work around an iOS 3.1 bug that causes listview thumbs to disappear when -webkit-visibility:hidden is used. */
	backface-visibility: hidden;
	transform: translateX(0);
}
.flip.out {
	-webkit-transform: rotateY(-90deg);
	-webkit-animation-name: flipouttoleft;
	-webkit-animation-duration: 175ms;
	transform: rotateY(-90deg);
	animation-name: flipouttoleft;
	animation-duration: 175ms;
}
.flip.in {
	-webkit-animation-name: flipintoright;
	-webkit-animation-duration: 225ms;
	animation-name: flipintoright;
	animation-duration: 225ms;
}

@-webkit-keyframes flipouttoleft {
    from { -webkit-transform: rotateY(0); }
    to { -webkit-transform: rotateY(-90deg); }
}
@keyframes flipouttoleft {
    from { transform: rotateY(0); }
    to { transform: rotateY(-90deg); }
}
@-webkit-keyframes flipouttoright {
    from { -webkit-transform: rotateY(0) ; }
    to { -webkit-transform: rotateY(90deg); }
}
@keyframes flipouttoright {
    from { transform: rotateY(0); }
    to { transform: rotateY(90deg); }
}
@-webkit-keyframes flipintoleft {
    from { -webkit-transform: rotateY(-90deg); }
    to { -webkit-transform: rotateY(0); }
}
@keyframes flipintoleft {
    from { transform: rotateY(-90deg); }
    to { transform: rotateY(0); }
}
@-webkit-keyframes flipintoright {
    from { -webkit-transform: rotateY(90deg); }
    to { -webkit-transform: rotateY(0); }
}
@keyframes flipintoright {
    from { transform: rotateY(90deg); }
    to { transform: rotateY(0); }
}

#container{
	width: 100%;
}
.content{
	position: absolute;
	left: 50%;
	width: 748px;
	margin:10px auto;
	margin-left: -374px;
	background-color: #F8F8F8;
	border:1px solid #ccc;
	box-shadow:0 0 10px #999;
	padding:2em;
	line-height:1.4em;
    font:13.34px helvetica,arial,freesans,clean,sans-serif;
    color:black;
}
#text-container{
	white-space: pre-wrap;
	line-height: 150%;
	font-size: 14px;
}
#markdown-container table{
	font:13.34px helvetica,arial,freesans,clean,sans-serif;
	color:black;
}
p {
    margin:1em 0;
    line-height:1.5em;
}

input[type=text],input[type=password],input[type=image],textarea{font:99% helvetica,arial,freesans,sans-serif;}
select,option{padding:0 .25em;}
optgroup{margin-top:.5em;}

img{border:0;max-width:100%;}
abbr{border-bottom:none;}
a{color:#4183c4;text-decoration:none;}
a:hover{text-decoration:underline;}
a code,a:link code,a:visited code{color:#4183c4;}
h2,h3{margin:1em 0;}
h1,h2,h3,h4,h5,h6{border:0;}
h1{font-size:170%;border-bottom:4px solid #aaa;padding-bottom:.5em;margin-top:1.5em;}
h1:first-child{margin-top:0;padding-top:.25em;border-top:none;}
h2{font-size:150%;margin-top:1.5em;border-bottom:4px solid #e0e0e0;padding-bottom:.5em;}
h3{margin-top:1em;}
hr{border:1px solid #ddd;margin: 10px 0;}
ul{margin:1em 0 1em 2em;}
ol{margin:1em 0 1em 2em;}
ul li,ol li{margin-top:.5em;margin-bottom:.5em;}
ul ul,ul ol,ol ol,ol ul{margin-top:0;margin-bottom:0;}
blockquote{margin:1em 0;border-left:5px solid #ddd;padding-left:.6em;color:#555;}
dt{font-weight:bold;margin-left:1em;}
dd{margin-left:2em;margin-bottom:1em;}

#markdown-outline{
	display:none;
	position:fixed;
	top:10px;
	left:-999px;
	border:1px solid #ccc;
	box-shadow:5px 5px 2px #ccc;
	padding: 5px 10px;
	background-color: #fff;
	overflow-y: auto;
}
#markdown-outline ul{
	margin:5px 0 5px 0;
	padding-left:30px;
	font-size:12px;
	border-left:1px dotted #ccc;
}
#markdown-outline ul:first-child{
	border:none;
}
#markdown-outline li{
	list-style-type:decimal;
	margin:3px 0;
}

#markdown-backTop{
	position: fixed;
	right:5px;
	bottom:5px;
	padding:5px;
	width:50px;
	height:20px;
	background:url(images/backtop.gif) no-repeat 5px 5px #fff;
	border:1px solid #ccc;
	cursor:pointer;
}

/*table style*/

table {
    border-collapse:collapse !important;
}
table th, table td{
	border:1px solid #ddd !important;
	padding: 5px;
	line-height: 1.5;
	vertical-align: top;
	border-top: 1px solid #dddddd;

}
table th{
	background: #EEE;
}
table p{
	margin: 0;
}
table tr:nth-child(odd){background:#FFF;}
table tr:nth-child(even){background:#FAFAFA;}
.katex-inline{
	padding: 0 5px;
}
.katex-block{
	margin: 20px 0;
	text-align: center;
	font-size: 16px;
}

pre{
    padding:5px 0;
}

code.inline {
	padding: 1px 3px;
	font-size: .72rem;
	line-height: 1.12rem;
	color: #c25;
	background-color: #f7f7f9;
	-webkit-border-radius: 3px;
	-moz-border-radius: 3px;
	border-radius: 3px;
	font-family: Menlo,Monaco,Consolas,"Courier New",monospace;
	border: 1px solid #e1e2e8;
}

@media only print{
    #markdown-outline, #markdown-backTop {
        display: none !important;
    }
    .content {
        left: 0 !important;
        width: auto !important;
        margin-left: auto !important;
        background-color: white !important;
        border: 0 !important;
        box-shadow: 0 !important;
    }
}
