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
20 changes: 16 additions & 4 deletions extension/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ if (window.gitrecContentInitialized) return;
window.gitrecContentInitialized = true;

var itemId = null;
var repositoryDescription = null;
var similarOffset = 0;
var exploreContent = null;
var loaded = false;
Expand All @@ -14,6 +15,15 @@ function getRepositorySidebar() {
return $('[class*="CodeViewSidebar-module__borderGrid"]').first();
}

function getRepositoryDescription() {
const sidebar = getRepositorySidebar();
const description = sidebar.find('p[class*="SidebarAbout-module__description"]').first();
if (description.length) return description.text().trim() || null;
// These elements mean About has rendered without a description.
if (sidebar.find('[class*="SidebarAbout-module__noDescription"], [class*="SidebarAbout-module__websiteRow"]').length) return '';
return null;
}

function placeSimilarPanel() {
const sidebar = getRepositorySidebar();
const languages = sidebar.find('h2').filter(function () {
Expand All @@ -30,6 +40,7 @@ function initialize() {
if (currentPath !== location.pathname) {
currentPath = location.pathname;
loaded = false;
repositoryDescription = null;
similarOffset = 0;
similarPanel = null;
$("#similar-repositories").remove();
Expand All @@ -39,6 +50,8 @@ function initialize() {
const repository = $('meta[name="octolytics-dimension-repository_nwo"]').attr('content');
if (splits.length >= 2 && repository &&
repository.toLowerCase() === splits.slice(0, 2).join('/').toLowerCase() && getRepositorySidebar().length > 0) {
repositoryDescription = getRepositoryDescription();
if (repositoryDescription === null) return;
loaded = true;
itemId = splits[0] + ':' + splits[1];
// mark read
Expand All @@ -57,18 +70,17 @@ function initialize() {
}

$(document).ready(initialize);
// Wait for React to render the sidebar, and handle navigation without a reload.
// Wait for React to render About, and handle navigation without a reload.
new MutationObserver(function () {
clearTimeout(refreshTimer);
refreshTimer = setTimeout(initialize, 100);
}).observe(document.documentElement, { childList: true, subtree: true });
}).observe(document.documentElement, { childList: true, characterData: true, subtree: true });
$(document).on('turbo:load turbo:render', initialize);
$(window).on('popstate', initialize);

function loadSimilarRepos() {
const path = location.pathname;
const description = getRepositorySidebar().find('p[class*="SidebarAbout-module__description"]').first().text().trim();
chrome.runtime.sendMessage({ neighbors: itemId, offset: similarOffset, description: description }, function (result) {
chrome.runtime.sendMessage({ neighbors: itemId, offset: similarOffset, description: repositoryDescription }, function (result) {
if (location.pathname !== path) return;
if (result.is_authenticated) {
renderSimilarDiv(result);
Expand Down
2 changes: 1 addition & 1 deletion 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.9",
"version": "0.11",
"manifest_version": 3,
"permissions": [
"scripting",
Expand Down
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.9",
"version": "0.11",
"manifest_version": 3,
"permissions": [
"scripting",
Expand Down Expand Up @@ -35,4 +35,4 @@
"background": {
"service_worker": "background.js"
}
}
}
Loading