Skip to content
Merged
Show file tree
Hide file tree
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
33 changes: 20 additions & 13 deletions extension/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ var currentPath = null;
var similarPanel = null;
var refreshTimer = null;

// API responses and GitHub page text must remain text inside HTML templates.
function escapeHTML(value) {
return String(value ?? '').replace(/[&<>"']/g, function (character) {
return { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[character];
});
}

function getRepositorySidebar() {
return $('[class*="CodeViewSidebar-module__borderGrid"]').first();
}
Expand Down Expand Up @@ -117,7 +124,7 @@ async function renderSimilarDiv(result) {
if (result.message.startsWith('API rate limit exceeded')) {
errorMessage = `API rate limit exceeded. Login <a href="https://gitrec.gorse.io" target="_blank">GitRec</a> to get a higher rate limit.`
} else {
errorMessage = result.message;
errorMessage = escapeHTML(result.message);
}
rows = `<div class="text-small color-fg-muted">${errorMessage}</div>`
} else if (result.repos.length > 0) {
Expand All @@ -130,14 +137,14 @@ async function renderSimilarDiv(result) {
count++;
rows += `
<div class="py-2 my-2 color-border-muted">
<a class="f6 text-bold Link--primary d-flex no-underline wb-break-all d-inline-block" href="/${repo.full_name}">${repo.full_name}</a>
<p class="f6 color-fg-muted mb-2" itemprop="description">${repo.description ? repo.description : ''}</p>
<a class="f6 text-bold Link--primary d-flex no-underline wb-break-all d-inline-block" href="/${escapeHTML(repo.full_name)}">${escapeHTML(repo.full_name)}</a>
<p class="f6 color-fg-muted mb-2" itemprop="description">${escapeHTML(repo.description)}</p>
${renderLanguageSpan(repo.language)}
<span class="f6 color-fg-muted text-normal">
<svg aria-label="star" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-star">
<path fill-rule="evenodd" d="M8 .25a.75.75 0 01.673.418l1.882 3.815 4.21.612a.75.75 0 01.416 1.279l-3.046 2.97.719 4.192a.75.75 0 01-1.088.791L8 12.347l-3.766 1.98a.75.75 0 01-1.088-.79l.72-4.194L.818 6.374a.75.75 0 01.416-1.28l4.21-.611L7.327.668A.75.75 0 018 .25zm0 2.445L6.615 5.5a.75.75 0 01-.564.41l-3.097.45 2.24 2.184a.75.75 0 01.216.664l-.528 3.084 2.769-1.456a.75.75 0 01.698 0l2.77 1.456-.53-3.084a.75.75 0 01.216-.664l2.24-2.183-3.096-.45a.75.75 0 01-.564-.41L8 2.694v.001z"></path>
</svg>
${repo.stargazers_count}
${escapeHTML(repo.stargazers_count)}
</span>
</div>`
}
Expand All @@ -157,7 +164,7 @@ async function renderSimilarDiv(result) {
} else {
rows = '<div class="text-small color-fg-muted">No similar repositories found</div>'
}
template = `
const template = `
<div class="border-top color-border-muted pt-3 mt-3" id="similar-repositories">
<div>
<h2 class="h4 mb-3">Related repositories</h2>
Expand All @@ -167,14 +174,14 @@ async function renderSimilarDiv(result) {
$("#similar-repositories").remove();
similarPanel = $($.parseHTML(template));
placeSimilarPanel();
similarPanel.find("a#previous-button").click(function () {
similarPanel.find("a#previous-button").on('click', function () {
$("#previous-button").remove();
$("#next-button").remove();
similarOffset -= 3;
loadSimilarRepos();
return false;
});
similarPanel.find("a#next-button").click(function () {
similarPanel.find("a#next-button").on('click', function () {
$("#previous-button").remove();
$("#next-button").remove();
similarOffset += 3;
Expand Down Expand Up @@ -228,21 +235,21 @@ async function showRecommend(result) {
if (result.message.startsWith('API rate limit exceeded')) {
errorMessage = `API rate limit exceeded. Login <a href="https://gitrec.gorse.io" target="_blank">GitRec</a> to get a higher rate limit.`
} else {
errorMessage = result.message;
errorMessage = escapeHTML(result.message);
}
template += `<div class="d-block no-underline f6 mb-3" id="error-message">${errorMessage}</div>`
} else if (result.repos.length > 0) {
for (const [i, repo] of result.repos.entries()) {
template += `
<div class="py-2 my-2${i == result.repos.length - 1 ? '' : ' border-bottom color-border-muted'}">
<a class="f6 text-bold Link--primary d-flex no-underline wb-break-all d-inline-block" href="/${repo.full_name}">${repo.full_name}</a>
<p class="f6 color-fg-muted mb-2" itemprop="description">${repo.description ? repo.description : ''}</p>
<a class="f6 text-bold Link--primary d-flex no-underline wb-break-all d-inline-block" href="/${escapeHTML(repo.full_name)}">${escapeHTML(repo.full_name)}</a>
<p class="f6 color-fg-muted mb-2" itemprop="description">${escapeHTML(repo.description)}</p>
${renderLanguageSpan(repo.language)}
<span class="f6 color-fg-muted text-normal">
<svg aria-label="star" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-star">
<path fill-rule="evenodd" d="M8 .25a.75.75 0 01.673.418l1.882 3.815 4.21.612a.75.75 0 01.416 1.279l-3.046 2.97.719 4.192a.75.75 0 01-1.088.791L8 12.347l-3.766 1.98a.75.75 0 01-1.088-.79l.72-4.194L.818 6.374a.75.75 0 01.416-1.28l4.21-.611L7.327.668A.75.75 0 018 .25zm0 2.445L6.615 5.5a.75.75 0 01-.564.41l-3.097.45 2.24 2.184a.75.75 0 01.216.664l-.528 3.084 2.769-1.456a.75.75 0 01.698 0l2.77 1.456-.53-3.084a.75.75 0 01.216-.664l2.24-2.183-3.096-.45a.75.75 0 01-.564-.41L8 2.694v.001z"></path>
</svg>
${repo.stargazers_count}
${escapeHTML(repo.stargazers_count)}
</span>
</div>`;
}
Expand All @@ -260,7 +267,7 @@ async function showRecommend(result) {
}
template += `</div>`;
exploreDiv.append($($.parseHTML(template)));
$("a#renew-button").click(function () {
$("a#renew-button").on('click', function () {
$("#renew-button").remove();
chrome.runtime.sendMessage({ read: result.items }, () => {
chrome.runtime.sendMessage({ recommend: [] }, function (result) {
Expand All @@ -282,7 +289,7 @@ function renderLanguageSpan(language) {
<span class="mr-2 f6 color-fg-muted text-normal">
<span class="">
<span class="repo-language-color" style="background-color: ${renderLanguageColor(language)}"></span>
<span itemprop="programmingLanguage">${language}</span>
<span itemprop="programmingLanguage">${escapeHTML(language)}</span>
</span>
</span>`;
} else {
Expand Down
2 changes: 0 additions & 2 deletions extension/jquery-3.6.1.min.js

This file was deleted.

2 changes: 2 additions & 0 deletions extension/jquery-4.0.0.min.js

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions extension/manifest-firefox.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "GitRec",
"description": "A recommender system for GitHub repositories based on Gorse",
"version": "0.11",
"version": "0.12",
"manifest_version": 3,
"permissions": [
"scripting",
Expand All @@ -25,7 +25,7 @@
"*://github.com/*"
],
"js": [
"jquery-3.6.1.min.js",
"jquery-4.0.0.min.js",
"colors.js",
"content.js"
],
Expand All @@ -37,7 +37,17 @@
},
"browser_specific_settings": {
"gecko": {
"id": "zhangzhenghao@hotmail.com"
"id": "zhangzhenghao@hotmail.com",
"strict_min_version": "142.0",
"data_collection_permissions": {
"required": [
"authenticationInfo",
"personallyIdentifyingInfo",
"browsingActivity",
"websiteActivity",
"websiteContent"
]
}
}
}
}
}
4 changes: 2 additions & 2 deletions extension/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "GitRec",
"description": "A recommender system for GitHub repositories based on Gorse",
"version": "0.11",
"version": "0.12",
"manifest_version": 3,
"permissions": [
"scripting",
Expand All @@ -25,7 +25,7 @@
"*://github.com/*"
],
"js": [
"jquery-3.6.1.min.js",
"jquery-4.0.0.min.js",
"colors.js",
"content.js"
],
Expand Down
Loading