Skip to content
This repository has been archived by the owner on Jan 26, 2023. It is now read-only.

simplify the body check flow #26

Merged
merged 1 commit into from
Jan 10, 2018
Merged
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
46 changes: 21 additions & 25 deletions src/script/pageload/body.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@


//injects various information on the page
var body = function(){
var url = document.location.href;
var isOnGitHubcom = url.indexOf('://github.com') != -1 && url.indexOf('://github.com') < 15;
// injects various information on the page
var body = function(url) {
var isOnGitHubcom = url.indexOf('://github.com') !== -1 && url.indexOf('://github.com') < 15;
var isOnGitHubEnterprise = document.getElementsByClassName('enterprise').length >= 1 && document.getElementsByClassName('header-logo-invertocat').length >= 1;
var isOnGitHub = isOnGitHubEnterprise || isOnGitHubcom;

if(!isOnGitHub){
if(!isOnGitHub) {
setThumbnail('');
}

var isOnUserProfile = isOnGitHub && url.match(/.+\/.+\/?/gi) != null && document.getElementById("report-block-modal");
var isOnProfile = isOnGitHub && url.match(/.+\/.+\/.+\/?/gi) != null;
var isOnRepo = isOnGitHub && url.match(/.+\/.+\/.+\/.+\/?/gi) != null;
var isOnIssuePage = isOnGitHub && ( url.indexOf('/pull/') != -1 || url.indexOf('/issue/') != -1 || url.indexOf('/issues/') != -1 );
var isOnIssuesPage = isOnGitHub && url.indexOf('/issues') != -1;
var isOnUserProfile = url.match(/.+\/.+\/?/gi) !== null && document.getElementById("report-block-modal");
var isOnProfile = url.match(/.+\/.+\/.+\/?/gi) !== null;
var isOnRepo = url.match(/.+\/.+\/.+\/.+\/?/gi) !== null;
var isOnIssuePage = url.indexOf('/pull/') !== -1 || url.indexOf('/issue/') !== -1 || url.indexOf('/issues/') !== -1;
var isOnIssuesPage = url.indexOf('/issues') !== -1;
var isAlreadyGitcoinBounty = document.getElementsByClassName('gitcoin_bounty').length >= 1;
var isOnIssueBoard = isOnGitHub && url.indexOf('boards') != -1;
var isOnIssueBoard = url.indexOf('boards') !== -1;


// Location | User Profile
if(isOnUserProfile && !isAlreadyGitcoinBounty ){
if(isOnUserProfile && !isAlreadyGitcoinBounty ) {
addButtonToUserPage();
}

// Location | Issue Page
if (isOnIssuePage){
addButtonToIssuePage();
addBountyInfoToIssuePage(url);
injectGetBountyAmount();
} else if (isOnRepo){
if (isOnIssuePage) {
addButtonToIssuePage();
addBountyInfoToIssuePage(url);
injectGetBountyAmount();
} else if (isOnRepo) {
var repoUrl = document.location.href.split('issues')[0].split('pulls')[0];
injectGetNumberBounties(repoUrl);
} else if (isOnGitHub){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

} else {
injectGetTotalBounties();
}
}

if (isOnIssuesPage) {
injectGetAllBountiesOnIssuesPage();
}
Expand All @@ -49,9 +47,7 @@ var hasRun = false;
setInterval(function() {
if (url !== window.location.href || !hasRun) {
url = window.location.href;
body();
body(url);
}
hasRun = true;
}, 1000);