Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 22 additions & 23 deletions chrome/app/scripts/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var threeBarSvg = '<svg height="16" width="12" xmlns="http://www.w3.org/2000/svg"><path d="M11.41 9H0.59c-0.59 0-0.59-0.41-0.59-1s0-1 0.59-1h10.81c0.59 0 0.59 0.41 0.59 1s0 1-0.59 1z m0-4H0.59c-0.59 0-0.59-0.41-0.59-1s0-1 0.59-1h10.81c0.59 0 0.59 0.41 0.59 1s0 1-0.59 1zM0.59 11h10.81c0.59 0 0.59 0.41 0.59 1s0 1-0.59 1H0.59c-0.59 0-0.59-0.41-0.59-1s0-1 0.59-1z" /></svg>';

var getLinks = function() {
var getLinks = function () {
var header, tag, headerLevelStr, depth;
var headers = document.querySelectorAll('article.markdown-body h1, article.markdown-body h2, article.markdown-body h3, article.markdown-body h4, article.markdown-body h5, article.markdown-body h6');
var links = [];
Expand All @@ -23,17 +23,17 @@ var getLinks = function() {
return links;
};

var openList = function(depth) {
var openList = function (depth) {
var html = '';

while (depth--) {
html += '<li><ul>';
html += '<li><ul style="margin-left:20px;">';
}

return html;
};

var closeList = function(depth) {
var closeList = function (depth) {
var html = '';

while (depth--) {
Expand All @@ -43,7 +43,7 @@ var closeList = function(depth) {
return html;
};

var buildContents = function(links) {
var buildContents = function (links) {
var node;
var contents = '<ul>';
var currentDepth = 1;
Expand All @@ -59,7 +59,7 @@ var buildContents = function(links) {

currentDepth = node.depth;

contents += '<li><a href="' + node.hash + '">' + node.text + '</a></li>';
contents += '<li style="margin-bottom:5px;"><a href="' + node.hash + '">' + node.text + '</a></li>';
}

while (currentDepth--) {
Expand All @@ -69,31 +69,30 @@ var buildContents = function(links) {
return contents;
};

var insertContents = function(contents) {
var insertContents = function (contents) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this pull request I'll setup Prettier so this auto-formats consistently going forward.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok,My code is idea format .
It's different from your way.

var fileView = false;
var readmeTarget = document.querySelectorAll('#readme > .Box-header > h3')[0];
var markdownTarget;

if (!readmeTarget) {
markdownTarget = document.querySelectorAll('.file-actions')[0];
}

if (!readmeTarget && !markdownTarget) {
return false;
}

var oldLink = document.querySelectorAll('.github-markdown-contents')[0];

if (oldLink) {
oldLink.parentNode.removeChild(oldLink);
}

var link = '<span class="github-markdown-contents select-menu js-menu-container js-select-menu"><span class="github-markdown-contents-btn js-select-menu js-menu-target btn btn-sm tooltipped-s' + (markdownTarget ? '' : ' float-right') + '" role="button" aria-label="Show Table of Contents">' + threeBarSvg + '</span><div class="select-menu-modal-holder github-markdown-contents-modal-holder js-menu-content js-navigation-container"><div id="github-markdown-contents-container" class="select-menu-modal">' + contents + '</div></div></span>';
if (readmeTarget) {
readmeTarget.parentNode.innerHTML += link;
} else {
markdownTarget.innerHTML += link;
}
var link = '<span class="github-markdown-contents select-menu js-menu-container js-select-menu"><span class="github-markdown-contents-btn js-select-menu js-menu-target btn btn-sm tooltipped-s' + '" role="button" aria-label="Show Table of Contents">' + threeBarSvg + '</span>' +
'<div class="select-menu-modal-holder github-markdown-contents-modal-holder js-menu-content js-navigation-container" style="width:300px;left:-100px;top:20px;">' +
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making this multiple lines!

'<div id="github-markdown-contents-container" class="select-menu-modal">' + contents + '</div>' +
'</div>' +
'</span>';

var fixDiv = document.createElement('div');
fixDiv.id = 'github-menu';
fixDiv.style.position = 'fixed';
fixDiv.style.zIndex = '99999';
fixDiv.style.left = '50%';
fixDiv.style.top = '0';
document.body.append(fixDiv);

fixDiv.innerHTML = link;
};

var links = getLinks();
Expand Down