Browse Source

Show releases count in releases tab and persist it

Follow-up to https://github.com/sindresorhus/refined-github/pull/12#issuecomment-185583858
master
Haralan Dobrev 9 years ago
parent
commit
3799af8354
  1. 28
      extension/content.js
  2. 3
      extension/manifest.json
  3. 3
      package.json

28
extension/content.js

@ -4,6 +4,7 @@ const path = location.pathname;
const ownerName = path.split('/')[1];
const repoName = path.split('/')[2];
const repoUrl = `${ownerName}/${repoName}`;
const releasesCountCacheKey = `${repoUrl}-releases-count`;
const isDashboard = () => location.pathname === '/' || /(^\/(dashboard))/.test(location.pathname) || /(^\/(orgs)\/)(\w|-)+\/(dashboard)/.test(location.pathname);
const isRepo = () => /^\/[^/]+\/[^/]+/.test(location.pathname);
const isRepoRoot = () => location.pathname.replace(/\/$/, '') === `/${repoUrl}` || (/\/tree\/$/.test(location.href) && $('.repository-meta-content').length);
@ -132,16 +133,35 @@ function moveVotes() {
}
}
function appendReleasesCount(count) {
if (!count) {
return;
}
$('.reponav-releases').append(`<span class="counter">${count}</span>`);
}
function cacheReleasesCount() {
if (isRepoRoot()) {
const releasesCount = $('.numbers-summary a[href$="/releases"] .num').text().trim();
appendReleasesCount(releasesCount);
chrome.storage.local.set({[releasesCountCacheKey]: releasesCount});
} else {
chrome.storage.local.get(releasesCountCacheKey, items => {
appendReleasesCount(items[releasesCountCacheKey]);
});
}
}
function addReleasesTab() {
const $repoNav = $('.js-repo-nav');
let $releasesTab = $repoNav.children('[data-selected-links~="repo_releases"]');
const hasReleases = $releasesTab.length > 0;
if (!hasReleases) {
$releasesTab = $(`<a href="/${repoUrl}/releases" class="reponav-item" data-hotkey="g r" data-selected-links="repo_releases /${repoUrl}/releases">
$releasesTab = $(`<a href="/${repoUrl}/releases" class="reponav-item reponav-releases" data-hotkey="g r" data-selected-links="repo_releases /${repoUrl}/releases">
<svg class="octicon octicon-tag" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path d="M6.73 2.73c-0.47-0.47-1.11-0.73-1.77-0.73H2.5C1.13 2 0 3.13 0 4.5v2.47c0 0.66 0.27 1.3 0.73 1.77l6.06 6.06c0.39 0.39 1.02 0.39 1.41 0l4.59-4.59c0.39-0.39 0.39-1.02 0-1.41L6.73 2.73zM1.38 8.09c-0.31-0.3-0.47-0.7-0.47-1.13V4.5c0-0.88 0.72-1.59 1.59-1.59h2.47c0.42 0 0.83 0.16 1.13 0.47l6.14 6.13-4.73 4.73L1.38 8.09z m0.63-4.09h2v2H2V4z"></path></svg>
Releases
<span>Releases</span>
</a>`);
}
@ -154,6 +174,8 @@ function addReleasesTab() {
if (!hasReleases) {
$repoNav.append($releasesTab);
cacheReleasesCount();
}
}

3
extension/manifest.json

@ -6,7 +6,8 @@
"manifest_version": 2,
"minimum_chrome_version": "48",
"permissions": [
"https://github.com/*"
"https://github.com/*",
"storage"
],
"icons": {
"128": "icon.png"

3
package.json

@ -9,7 +9,8 @@
"esnext": true,
"envs": [
"browser",
"jquery"
"jquery",
"webextensions"
],
"ignores": [
"extension/vendor/**"

Loading…
Cancel
Save