Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Corrected Handling of Observed Elements on GitHub Pages #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
150 changes: 76 additions & 74 deletions Extension Files/assets/js/getGithubDevProfileCoordinate.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,81 +22,83 @@ console.log('Developer Profile Script Started');

// listens for data from different GitHub profile attributes then sends a response based on its results
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
const elements = document.elementsFromPoint(msg.x, msg.y);
let sentResult = false;
for (element of elements) {
if (element.classList.contains("avatar") && element.tagName === 'IMG') {
console.log('avatar image');
sentResult = true;
sendResponse({ result: `AvatarImage-`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
if (msg.text == 'get_github_dev_profile_coordinate'){
const elements = document.elementsFromPoint(msg.x, msg.y);
let sentResult = false;
for (element of elements) {
if (element.classList.contains("avatar") && element.tagName === 'IMG') {
console.log('avatar image');
sentResult = true;
sendResponse({ result: `AvatarImage-`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
if (element.classList.contains("js-activity-overview-graph-container") && element.attributes.getNamedItem('data-percentages')) {
console.log("activity overview");
let activityOverview = element.attributes.getNamedItem('data-percentages').value;
activityOverview = JSON.parse(activityOverview);
const percentCommits = activityOverview["Commits"];
const percentCodeReview = activityOverview["Code review"];
const percentPullRequests = activityOverview["Pull requests"];
sentResult = true;
sendResponse({ result: `ActivityOverview-Commit:${percentCommits}%,CodeReview:${percentCodeReview}%,PullRequest:${percentPullRequests}%`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
if (element.tagName === 'DIV' && element.classList.contains("graph-before-activity-overview")) {
console.log('contribution heat map')
sentResult = true;
sendResponse({ result: `ContributionHeatMap`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
if (element.id.includes("year-link")) {
console.log('Year Link')
const year = element.id;
sentResult = true;
sendResponse({ result: `Year-${year}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
if (element.tagName === 'SPAN' && element.classList.contains("label")) {
console.log('profile label')
const labelName = element.innerHTML;
sentResult = true;
sendResponse({ result: `ProfileLabel-${labelName}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
if (element.tagName === 'A' && element.attributes.getNamedItem("data-hovercard-type") && element.attributes.getNamedItem("data-hovercard-type").value === "organization"
&& element.classList.contains("avatar-group-item")) {
console.log('Organization')
console.log(element);
const organizationName = element.attributes.getNamedItem("aria-label").value;
sentResult = true;
sendResponse({ result: `Organization-${organizationName}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
if (element.tagName === 'A' && element.attributes.getNamedItem("itemprop") && element.attributes.getNamedItem("itemprop").value.includes("codeRepository")) {
console.log('Contributed repositories')
const repoName = element.innerHTML;
sentResult = true;
sendResponse({ result: `Repository-${repoName}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
if (element.classList.contains("Counter")) {
console.log("tab Counter")
const tab = element.parentElement.innerHTML;
const number = element.innerHTML
sentResult = true;
sendResponse({ result: `Num${tab}-${number}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
if (element.classList.contains("Profile-rollup-wrapper")) {
console.log("Contribution Acitivty Entry")
// Need more info on the contribution
sentResult = true;
sendResponse({ result: `ContributionActivity-`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
}
if (element.classList.contains("js-activity-overview-graph-container") && element.attributes.getNamedItem('data-percentages')) {
console.log("activity overview");
let activityOverview = element.attributes.getNamedItem('data-percentages').value;
activityOverview = JSON.parse(activityOverview);
const percentCommits = activityOverview["Commits"];
const percentCodeReview = activityOverview["Code review"];
const percentPullRequests = activityOverview["Pull requests"];
sentResult = true;
sendResponse({ result: `ActivityOverview-Commit:${percentCommits}%,CodeReview:${percentCodeReview}%,PullRequest:${percentPullRequests}%`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
if (!sentResult) {
sendResponse(null);
}
if (element.tagName === 'DIV' && element.classList.contains("graph-before-activity-overview")) {
console.log('contribution heat map')
sentResult = true;
sendResponse({ result: `ContributionHeatMap`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
if (element.id.includes("year-link")) {
console.log('Year Link')
const year = element.id;
sentResult = true;
sendResponse({ result: `Year-${year}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
if (element.tagName === 'SPAN' && element.classList.contains("label")) {
console.log('profile label')
const labelName = element.innerHTML;
sentResult = true;
sendResponse({ result: `ProfileLabel-${labelName}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
if (element.tagName === 'A' && element.attributes.getNamedItem("data-hovercard-type") && element.attributes.getNamedItem("data-hovercard-type").value === "organization"
&& element.classList.contains("avatar-group-item")) {
console.log('Organization')
console.log(element);
const organizationName = element.attributes.getNamedItem("aria-label").value;
sentResult = true;
sendResponse({ result: `Organization-${organizationName}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
if (element.tagName === 'A' && element.attributes.getNamedItem("itemprop") && element.attributes.getNamedItem("itemprop").value.includes("codeRepository")) {
console.log('Contributed repositories')
const repoName = element.innerHTML;
sentResult = true;
sendResponse({ result: `Repository-${repoName}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
if (element.classList.contains("Counter")) {
console.log("tab Counter")
const tab = element.parentElement.innerHTML;
const number = element.innerHTML
sentResult = true;
sendResponse({ result: `Num${tab}-${number}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
if (element.classList.contains("Profile-rollup-wrapper")) {
console.log("Contribution Acitivty Entry")
// Need more info on the contribution
sentResult = true;
sendResponse({ result: `ContributionActivity-`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
}
if (!sentResult) {
sendResponse(null);
}

// Still need to check: Profile label, URL pattern matching, contribution activity entry, organizations, counters
// Still need to check: Profile label, URL pattern matching, contribution activity entry, organizations, counters
}
});
168 changes: 84 additions & 84 deletions Extension Files/assets/js/getGithubIssueListCoordinate.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,106 +18,106 @@
************************************************************************************************************************
********************************/

console.log('Github Issuees Script Started');

console.log('Github Issues Script Started');
// listens for the different GitHub issue coordinates and data associated with it, then sends
// response based on its results
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
const elements = document.elementsFromPoint(msg.x, msg.y);
let sentResult = false;
for (element of elements) {
console.log("looping");
if (element.classList.contains('btn-link') && element.innerHTML.includes('Open') && element.tagName === 'A') {
console.log("Number of issues open");
const numberOpen = element.innerHTML;
sentResult = true;
sendResponse({ result: `NumIssuesOpen-${numberOpen}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
if (element.classList.contains('social-count') && element.tagName === 'A') {
const ariaLabel = element.attributes.getNamedItem('aria-label').value;
if (ariaLabel.includes('forked')) {
console.log('Number of users who have forked repository');
const numberForked = element.innerHTML;
sentResult = true;
sendResponse({ result: `NumOfForked-${numberForked}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;

} else if (ariaLabel.includes('watching')) {
console.log('Number of users who are watching repository');
const numberWatching = element.innerHTML;
if (msg.text == 'get_github_issues_coordinate'){
const elements = document.elementsFromPoint(msg.x, msg.y);
let sentResult = false;
for (element of elements) {
if (element.classList.contains('btn-link') && element.innerHTML.includes('Open') && element.tagName === 'A') {
console.log("Number of issues open");
const numberOpen = element.innerHTML;
sentResult = true;
sendResponse({ result: `NumOfWatching- ${numberWatching}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
} else if (ariaLabel.includes('starred')) {
console.log('Number of users who starred repository');
const numberStarred= element.innerHTML;
sentResult = true;
sendResponse({ result: `NumOfStarred-${numberStarred}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
sendResponse({ result: `NumIssuesOpen-${numberOpen}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
}
if (element.classList.contains('url') && element.classList.contains('fn') && element.tagName === 'A') {
if (!element.attributes.getNamedItem('data-hovercard-type')) {
return;
}
if (element.attributes.getNamedItem('data-hovercard-type') === 'organization') {
console.log("Project/Organization Name");
const organization = element.innerHTML;
sentResult = true;
sendResponse({ result: `ProjectName-${organization}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
if (element.classList.contains('social-count') && element.tagName === 'A') {
const ariaLabel = element.attributes.getNamedItem('aria-label').value;
if (ariaLabel.includes('forked')) {
console.log('Number of users who have forked repository');
const numberForked = element.innerHTML;
sentResult = true;
sendResponse({ result: `NumOfForked-${numberForked}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;

} else if (ariaLabel.includes('watching')) {
console.log('Number of users who are watching repository');
const numberWatching = element.innerHTML;
sentResult = true;
sendResponse({ result: `NumOfWatching- ${numberWatching}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
} else if (ariaLabel.includes('starred')) {
console.log('Number of users who starred repository');
const numberStarred= element.innerHTML;
sentResult = true;
sendResponse({ result: `NumOfStarred-${numberStarred}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
}
}
if (element.classList.contains('IssueLabel')) {
console.log('Issue label')
const labelTitle = element.innerHTML;
sentResult = true;
sendResponse({ result: `IssueLabel-${labelTitle}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
if (element.classList.contains('muted-link')) {
if (!element.attributes.getNamedItem('data-hovercard-type')) {
return;
if (element.classList.contains('url') && element.classList.contains('fn') && element.tagName === 'A') {
if (!element.attributes.getNamedItem('data-hovercard-type')) {
return;
}
if (element.attributes.getNamedItem('data-hovercard-type') === 'organization') {
console.log("Project/Organization Name");
const organization = element.innerHTML;
sentResult = true;
sendResponse({ result: `ProjectName-${organization}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
}
const linkType = element.attributes.getNamedItem('data-hovercard-type').value
if (linkType === 'user') {
console.log('user link')
const user = element.innerHTML;
if (element.classList.contains('IssueLabel')) {
console.log('Issue label')
const labelTitle = element.textContent;
sentResult = true;
sendResponse({ result: `Username-${user}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
sendResponse({ result: `IssueLabel-${labelTitle}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
} else if (linkType === 'issue') {
console.log('issue link')
const issue = element.innerHTML;
}
if (element.classList.contains('muted-link')) {
if (!element.attributes.getNamedItem('data-hovercard-type')) {
return;
}
const linkType = element.attributes.getNamedItem('data-hovercard-type').value
if (linkType === 'user') {
console.log('user link')
const user = element.innerHTML;
sentResult = true;
sendResponse({ result: `Username-${user}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
} else if (linkType === 'issue') {
console.log('issue link')
const issue = element.innerHTML;
sentResult = true;
sendResponse({ result: `Issue-${issue}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
} else if (linkType.includes
("comments")) {
const numberOfComments = element.attributes.getNamedItem('aria-label').value;
sentResult = true;
sendResponse({ result: `NumOfComments-${numberOfComments}`, x: msg.x, y: msg.y, time: msg.time, url: msg.url });
return;
}
}
if (element.tagName === 'RELATIVE-TIME') {
console.log('Time open')
const opened = element.innerHTML;
const timestamp = element.attributes.getNamedItem('title').value;
sentResult = true;
sendResponse({ result: `Issue-${issue}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
sendResponse({ result: `IssueOpened-${opened} on ${timestamp}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
} else if (linkType.includes
("comments")) {
const numberOfComments = element.attributes.getNamedItem('aria-label').value;
}
if (element.classList.contains('task-progress-counts')) {
console.log('Task progress bar')
const taskProgress = element.innerHTML;
sentResult = true;
sendResponse({ result: `NumOfComments-${numberOfComments}`, x: msg.x, y: msg.y, time: msg.time, url: msg.url });
sendResponse({ result: `TaskCompletion-${taskProgress}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
}
if (element.tagName === 'RELATIVE-TIME') {
console.log('Time open')
const opened = element.innerHTML;
const timestamp = element.attributes.getNamedItem('title').value;
sentResult = true;
sendResponse({ result: `IssueOpened-${opened} on ${timestamp}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
if (!sentResult) {
sendResponse(null);
}
if (element.classList.contains('task-progress-counts')) {
console.log('Task progress bar')
const taskProgress = element.innerHTML;
sentResult = true;
sendResponse({ result: `TaskCompletion-${taskProgress}`, x: msg.x, y: msg.y, time: msg.time, id: element.id, url: msg.url });
return;
}
}
if (!sentResult) {
sendResponse(null);
}
});
Loading