Add edit button to readme

This commit is contained in:
Shadowfacts 2016-09-09 18:19:16 -04:00
parent b970f0431d
commit dcbbf12d2e
No known key found for this signature in database
GPG Key ID: F802198A7D7F309D
1 changed files with 39 additions and 2 deletions

View File

@ -1,6 +1,10 @@
// utils // utils
let repoUrl = $("div.repohead-details-container > h1.public > strong[itemprop=name] > a").attr("href"); let repoUrl = $("div.repohead-details-container > h1.public > strong[itemprop=name] > a").attr("href");
function addStyle(style) {
$("body").after(`<style>${style}</style>`);
}
// don't use the (ugly) new font // don't use the (ugly) new font
// $("body").css("font-family", $("body").css("font-family").replace("BlinkMacSystemFont,", "")); // $("body").css("font-family", $("body").css("font-family").replace("BlinkMacSystemFont,", ""));
@ -14,7 +18,7 @@ let repoUrl = $("div.repohead-details-container > h1.public > strong[itemprop=na
releasesTab.attr("data-selected-links", releasesUrl); releasesTab.attr("data-selected-links", releasesUrl);
releasesTab.addClass("js-selected-navigation-item reponav-item"); releasesTab.addClass("js-selected-navigation-item reponav-item");
let icon = $("<svg aria-hidden=\"true\" class=\"octicon octicon-tag\" height=\"16\" version=\"1.1\" viewBox=\"0 0 14 16\" width=\"14\"><path d=\"M7.73 1.73C7.26 1.26 6.62 1 5.96 1H3.5C2.13 1 1 2.13 1 3.5v2.47c0 .66.27 1.3.73 1.77l6.06 6.06c.39.39 1.02.39 1.41 0l4.59-4.59a.996.996 0 0 0 0-1.41L7.73 1.73zM2.38 7.09c-.31-.3-.47-.7-.47-1.13V3.5c0-.88.72-1.59 1.59-1.59h2.47c.42 0 .83.16 1.13.47l6.14 6.13-4.73 4.73-6.13-6.15zM3.01 3h2v2H3V3h.01z\"></path></svg>"); let icon = "<svg aria-hidden=\"true\" class=\"octicon octicon-tag\" height=\"16\" version=\"1.1\" viewBox=\"0 0 14 16\" width=\"14\"><path d=\"M7.73 1.73C7.26 1.26 6.62 1 5.96 1H3.5C2.13 1 1 2.13 1 3.5v2.47c0 .66.27 1.3.73 1.77l6.06 6.06c.39.39 1.02.39 1.41 0l4.59-4.59a.996.996 0 0 0 0-1.41L7.73 1.73zM2.38 7.09c-.31-.3-.47-.7-.47-1.13V3.5c0-.88.72-1.59 1.59-1.59h2.47c.42 0 .83.16 1.13.47l6.14 6.13-4.73 4.73-6.13-6.15zM3.01 3h2v2H3V3h.01z\"></path></svg>";
releasesTab.append(icon); releasesTab.append(icon);
releasesTab.append(" Releases"); releasesTab.append(" Releases");
@ -74,7 +78,7 @@ let repoUrl = $("div.repohead-details-container > h1.public > strong[itemprop=na
el.wrap(link); el.wrap(link);
} }
}); });
$("body").after("<style>span.commit-ref:hover, span.commit-ref:hover span { text-decoration: underline; }</style>"); addStyle("span.commit-ref:hover, span.commit-ref:hover span { text-decoration: underline; }");
})(); })();
// linkify issue/pr references in issue titles // linkify issue/pr references in issue titles
@ -84,3 +88,36 @@ let repoUrl = $("div.repohead-details-container > h1.public > strong[itemprop=na
title.html(title.text().replace(/#(\d+)/, `<a href="${repoUrl}/issues/$1">#$1</a>`)); title.html(title.text().replace(/#(\d+)/, `<a href="${repoUrl}/issues/$1">#$1</a>`));
} }
})(); })();
// add edit button to readme
(function() {
let readme = $("#readme");
if (!readme.length) return;
let name = readme.find("h3").text().trim();
let branch = $(".file-navigation > .select-menu.float-left > button > .js-select-button").text();
let editUrl = `/${repoUrl}/edit/${branch}/${name}`;
let div = $("<div></div>");
div.attr("id", "readme-edit-link");
div.css("position", "absolute");
div.css("top", "10px");
div.css("right", "40px");
div.css("opacity", "0.2");
div.css("transform", "opacity 250ms");
let a = $("<a></a>");
a.attr("href", editUrl);
let svg = "<svg class=\"octicon octicon-pencil\" height=\"16\" version=\"1.1\" viewBox=\"0 0 14 16\" width=\"14\"><path d=\"M0 12v3h3l8-8-3-3L0 12z m3 2H1V12h1v1h1v1z m10.3-9.3l-1.3 1.3-3-3 1.3-1.3c0.39-0.39 1.02-0.39 1.41 0l1.59 1.59c0.39 0.39 0.39 1.02 0 1.41z\"></path></svg>";
a.append(svg);
div.append(a);
readme.append(div);
addStyle(`
#readme.blob #readme-edit-link { display: none; }
#readme-edit-link:hover { opacity: 1; }
`);
})();