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

Fixing script loading #20

Open
wants to merge 3 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
36 changes: 25 additions & 11 deletions Extension Files/assets/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,10 @@ window.iTraceChrome = {
} else {
// user is looking in the html viewport
// need to check which website the user is looking at
chrome.tabs.query({ 'active': true }, function (tabs) {
var url = iTraceChrome.tab.url;
if (url.includes('stackoverflow.com/questions/')) {
chrome.tabs.query({active: true}, function (tabs) { // Alterado
var url = tabs[0].url;
id = tabs[0].id;
if ((new RegExp('stackoverflow.com/questions/.*')).test(url)) {
chrome.tabs.sendMessage(iTraceChrome.id, { text: 'get_so_coordinate', x: coords.x, y: coords.y, time: timeStamp, url: url }, iTraceChrome.printResults);
}
if (url.includes('https://bug')) { // NOTE: This include may be incorect, will need to do some more research
Expand All @@ -212,18 +213,19 @@ window.iTraceChrome = {
if (url.includes('google.com')) {
chrome.tabs.sendMessage(iTraceChrome.id, { text: 'get_google_coordinate', x: coords.x, y: coords.y, time: timeStamp, url: url }, iTraceChrome.printResults);
}
if (url.includes('github.com/*/* /issues')) {
if ((new RegExp('github.com/.*/.*/issues')).test(url)) { // Alterado
chrome.tabs.sendMessage(iTraceChrome.id, { text: 'get_github_issues_coordinate', x: coords.x, y: coords.y, time: timeStamp, url: url }, iTraceChrome.printResults);
}
if (url.includes('github.com/*/*/pulls')) {
if ((new RegExp('github.com/.*/.*/pulls')).test(url)) { // Alterado
chrome.tabs.sendMessage(iTraceChrome.id, { text: 'get_github_prlist_coordinate', x: coords.x, y: coords.y, time: timeStamp, url: url }, iTraceChrome.printResults);
}
if (url.includes('github.com/*/*/pull')) {
chrome.tabs.sendMessage(iTraceChrome.id, { text: 'get_github_pr_coordinate', x: coords.x, y: coords.y, time: timeStamp, url: url }, iTraceChrome.printResults);
}
if (url.includes('github.com') && url.includes('pull')) {
if ((new RegExp('github.com/.*/.*/pull/.*')).test(url)) { // Alterado
chrome.tabs.sendMessage(iTraceChrome.id, { text: 'get_github_pr_coordinate', x: coords.x, y: coords.y, time: timeStamp, url: url }, iTraceChrome.printResults);
}
//if (url.includes('github.com') && url.includes('pull')) {
// console.log("Git PR");
// chrome.tabs.sendMessage(iTraceChrome.id, { text: 'get_github_pr_coordinate', x: coords.x, y: coords.y, time: timeStamp, url: url }, iTraceChrome.printResults);
//}
if (url.includes('github.com/')) {
chrome.tabs.sendMessage(iTraceChrome.id, { text: 'get_github_dev_profile_coordinate', x: coords.x, y: coords.y, time: timeStamp, url: url }, iTraceChrome.printResults);
}
Expand All @@ -249,8 +251,20 @@ window.iTraceChrome = {
// binds new websocket, sets status to active then listens for eye gaze data from the server
startSession: function (tabs, callback) {
iTraceChrome.tab = tabs[0];
console.log('START SESSION');

console.log('START SESSION');

// Created a listener to inject these javascripts codes, acording to the page

chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if(message.injectSpecific){
chrome.tabs.executeScript(sender.tab.id, {file: message.file}, function() {
sendResponse({ done: true });
});
return true; // Required for async sendResponse()
};
});


chrome.tabs.executeScript({
'code': 'window.innerHeight'
}, iTraceChrome.getBrowserX.bind(iTraceChrome));
Expand Down
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
}
});
Loading