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

Commit

Permalink
Merge pull request #5 from jclancy93/revamp
Browse files Browse the repository at this point in the history
(WIP) Browser Extension Revamp
  • Loading branch information
owocki authored Dec 19, 2017
2 parents eaeafbc + a563aed commit 23a91eb
Show file tree
Hide file tree
Showing 5 changed files with 314 additions and 43 deletions.
13 changes: 13 additions & 0 deletions popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@
background-position: cover;
}

#search_bar {
border-radius: 16px;
height: 32px;
border: 1px solid #eee;
outline: none;
padding-left: 10px;
font-weight: 300;
border: 1px solid black !important;
width: 80%;
}

</style>

</head>
Expand All @@ -116,6 +127,8 @@ <h4 id="username"></h4>
<a target=_blank href="https://gitcoin.co/funding/new" class="btn btn-sm btn-primary js-details-target gitcoin_button">+ Fund Issue</a>
</div>
<h5>Funded Issues</h5>
<input type="text" id="search_bar" placeholder="Search for keywords..">
<a class="btn btn-sm btn-primary js-details-target gitcoin_button search-button">Search</a>
<table class="table table-striped" id="openbounties">
<thead>
<tr>
Expand Down
19 changes: 16 additions & 3 deletions script/pageload/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,38 @@ var body = function(){
setThumbnail('');
}

var isOnUserProfile = isOnGitHub && url.match(/.+\/.+\/?/gi) != null;
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 isAlreadyGitcoinBountyD = document.getElementsByClassName('gitcoin_bounty').length >= 1;
var isOnIssueBoard = isOnGitHub && url.indexOf('boards') != -1;

console.log(url, "HERE IS THE PAGE URL!!", isOnIssuesPage, isOnRepo, isOnGitHub)

if(isOnUserProfile){
addButtonToUserPage();
}
if (isOnIssuePage){
if (!isAlreadyGitcoinBountyD){
// if (!isAlreadyGitcoinBountyD){
addButtonToIssuePage();
}
addBountyInfoToIssuePage(url);
// }
injectGetBountyAmount();
} else if (isOnRepo){
var repoUrl = document.location.href.split('issues')[0].split('pulls')[0];
injectGetNumberBounties(repoUrl);
} else if (isOnGitHub){
injectGetTotalBounties();
}
if (isOnIssuesPage) {
injectGetAllBountiesOnIssuesPage();
}
if (isOnIssueBoard) {
setInterval(function() {
injectGetAllBountiesOnIssueBoard();
}, 2500)
}
}

Expand Down
2 changes: 1 addition & 1 deletion script/pageload/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ injectScript('function respond_to_ext(type, response) { window.postMessage({ typ
//inject listening callbacks
callbacks = [
function(event){
//console.log("Stored " + event.data.type + ', ' + event.data.text);
console.log("Stored " + event.data.type + ', ' + event.data.text);
},
function(event){
document[event.data.type] = event.data.text;
Expand Down
226 changes: 199 additions & 27 deletions script/pageload/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,185 @@ var setThumbnail = function(text){
chrome.extension.sendMessage(text);
};

var insertAfter = function(newNode, referenceNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}

getAllBounties = function(){
var bounties_api_url = 'https://gitcoin.co/api/v0.1/bounties/?order_by=-web3_created';
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", bounties_api_url, false ); // false for synchronous request
xmlHttp.send( null );
console.log('all Bounties', JSON.parse(xmlHttp.responseText))
return JSON.parse(xmlHttp.responseText);
}

getBountiesForRepo = function(github_url) {
var bounties_api_url = "https://gitcoin.co/api/v0.1/bounties/?github_url=" + github_url;
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", bounties_api_url, false ); // false for synchronous request
xmlHttp.send( null );
return JSON.parse(xmlHttp.responseText);
}

getBountiesForKeyword = function(keyword) {
var bounties_api_url = "https://gitcoin.co/api/v0.1/bounties/?order_by=web3_created&network=mainnet&idx_status=open";
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", bounties_api_url, false ); // false for synchronous request
xmlHttp.send( null );
var all_bounties = JSON.parse(xmlHttp.responseText);
matching_bounties = [];
for (var i = all_bounties.length - 1; i >= 0; i--) {
var bounty_keywords = JSON.parse(all_bounties[i].raw_data[8]).issueKeywords.toLowerCase();
var bounty_title = all_bounties[i].title.toLowerCase();
var does_title_contain = bounty_title.indexOf(keyword) !== -1;
var do_keywords_contain = bounty_keywords.indexOf(keyword) !== -1;
if (do_keywords_contain || does_title_contain) {
matching_bounties.push(all_bounties[i])
}
}
return matching_bounties;
}

injectGetAllBountiesOnIssuesPage = function(){
var issue_nodes = document.getElementsByClassName('link-gray-dark');
var all_bounties = getAllBounties();
for (var i = issue_nodes.length - 1; i >= 0; i--) {
var issue_name = issue_nodes[i].innerHTML.trim()
for (var j = all_bounties.length - 1; j >= 0; j--) {
var bounty_name = all_bounties[j].title
var bounty_value = all_bounties[j].value_in_usdt
var github_url = issue_nodes[i].href
var bounty_url = "https://gitcoin.co/funding/details?url=" + github_url
var bounty_status = all_bounties[j].status;

if (issue_name == bounty_name) {
var bounty_badge = document.createElement("a");
var bounty_badge_text = document.createElement("span");
var gitcoin_logo = document.createElement("img");
bounty_badge.href = bounty_url;
gitcoin_logo.src = "https://avatars1.githubusercontent.com/u/30044474?v=4";
gitcoin_logo.setAttribute("style", "width: 16px;")
bounty_badge.setAttribute("style", `background: green;color: white; top: 9 right: 155px; display: inline-block; padding: 3px 4px;
font-size: 12px; font-weight: 600; line-height: 1; color: #fff; border-radius: 2px; display: inline-flex;
box-shadow: inset 0 -1px 0 rgba(27,31,35,0.12); flex-direction: row; flex-wrap: wrap; height: 22px; align-items: center;
justify-content: center; cursor: pointer`);
if (bounty_status === "open") {
var text = document.createTextNode("Open · $" + bounty_value);
} else if (bounty_status === "claimed") {
var text = document.createTextNode("Claimed · $" + bounty_value);
} else {
var text = document.createTextNode("Fulfilled · $" + bounty_value);
}

bounty_badge_text.appendChild(text);
insertAfter(bounty_badge, issue_nodes[i])
bounty_badge.prepend(gitcoin_logo)
bounty_badge.append(bounty_badge_text)
}
}
}
}

injectGetAllBountiesOnIssueBoard = function() {
var issue_nodes = document.getElementsByClassName('zhc-issue-card__issue-title');
var issue_parent_nodes = document.getElementsByClassName('zhc-issue-card');
var all_bounties = getAllBounties();
console.log(issue_nodes);
for (var i = issue_nodes.length - 1; i >= 0; i--) {
var issue_name = issue_nodes[i].innerHTML.trim()
for (var j = all_bounties.length - 1; j >= 0; j--) {
var bounty_name = all_bounties[j].title;
var bounty_value = all_bounties[j].value_in_usdt;
var bounty_status = all_bounties[j].status;
var bounty_url = "https://gitcoin.co" + all_bounties[i].url;

if (issue_name == bounty_name) {
console.log('found match')
var bounty_badge = document.createElement("a");
var bounty_badge_text = document.createElement("span");
var gitcoin_logo = document.createElement("img");
bounty_badge.href = bounty_url;
gitcoin_logo.src = "https://avatars1.githubusercontent.com/u/30044474?v=4";
gitcoin_logo.setAttribute("style", "width: 16px;")
bounty_badge.setAttribute("style", `background: green;color: white; top: 9 right: 155px; display: inline-block; padding: 3px 4px;
font-size: 12px; font-weight: 600; line-height: 1; color: #fff; border-radius: 2px; display: inline-flex;
box-shadow: inset 0 -1px 0 rgba(27,31,35,0.12); flex-direction: row; flex-wrap: wrap; height: 22px; align-items: center;
justify-content: center; cursor: pointer`);
if (issue_nodes[i].nextSibling === null) {
if (bounty_status === "open") {
var text = document.createTextNode("Open · $" + bounty_value);
} else if (bounty_status === "claimed") {
var text = document.createTextNode("Claimed · $" + bounty_value);
} else {
var text = document.createTextNode("Fulfilled · $" + bounty_value);
}

bounty_badge_text.appendChild(text);
insertAfter(bounty_badge, issue_nodes[i])
bounty_badge.prepend(gitcoin_logo)
bounty_badge.append(bounty_badge_text)
}
}
}
}
}

var addButtonToIssuePage = function(){
var element = document.getElementsByClassName('issues-listing')[0];
var bounty_anchor = document.createElement("A");
bounty_anchor.href = "https://gitcoin.co/funding/new?source=" + document.location.href + "&user=" + document.getElementsByName('user-login')[0].content;
var gitcoin_logo = document.createElement("img");
gitcoin_logo.src = "https://avatars1.githubusercontent.com/u/30044474?v=4";
gitcoin_logo.setAttribute("style", "width: 22px; vertical-align: middle; margin-top: -5px;");
bounty_anchor.className += "btn btn-sm btn-primary js-details-target gitcoin_bounty";
bounty_anchor.setAttribute("style", "position: absolute; top: -55px; right: 0px; background-color: #15003e; color: #25e899; background-image: linear-gradient(-180deg, #15003e 0%, #190032 90%)");
var text = document.createTextNode("+Fund Issue");
bounty_anchor.appendChild(text);
bounty_anchor.setAttribute("style", "position: absolute; top: 40px; right: 0;");
bounty_anchor.append(gitcoin_logo);
element.appendChild(bounty_anchor);
}

var addButtonToUserPage = function(){
var element = document.getElementsByClassName('vcard-names')[0];
var bounty_anchor = document.createElement("A");
var tip_anchor = document.createElement("A");
var tip_anchor_text = document.createElement("span");
tip_anchor.href = "https://gitcoin.co/tip?username=" + document.getElementsByClassName('p-nickname')[0].innerHTML;
tip_anchor.className += "btn btn-block btn-primary js-details-target gitcoin_bounty";
tip_anchor.setAttribute("style", "display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; height: 34px; justify-content: center; align-content: center;");
var gitcoin_logo = document.createElement("img");
gitcoin_logo.src = "https://avatars1.githubusercontent.com/u/30044474?v=4";
gitcoin_logo.setAttribute("style", "width: 22px;")
var text = document.createTextNode("Tip User");
tip_anchor.appendChild(gitcoin_logo);
tip_anchor_text.appendChild(text);
tip_anchor.appendChild(tip_anchor_text);
element.appendChild(tip_anchor);
}

bounty_anchor.href = "https://gitcoin.co/tip?username=" + document.getElementsByClassName('p-nickname')[0].innerHTML;
bounty_anchor.className += "btn btn-sm btn-primary js-details-target gitcoin_bounty";
bounty_anchor.setAttribute("style", "background-color: #15003e; color: #25e899; background-image: linear-gradient(-180deg, #15003e 0%, #190032 90%)");
var text = document.createTextNode("+Tip");
bounty_anchor.appendChild(text);
element.appendChild(bounty_anchor);
var addBountyInfoToIssuePage = function(url) {
var all_bounties = getBountiesForRepo(url);
console.log('all bounties', all_bounties)
var bounty_anchor = document.getElementsByClassName('gitcoin_bounty')[0];
// bounty_anchor = "https://gitcoin.co/funding/details?url=" + url;
var bounty_text = document.createElement("span");
bounty_anchor.href = "https://gitcoin.co/funding/details?url=" + url;
if (all_bounties.length > 0) {
var bounty_eth_value = all_bounties[0].value_true;
var bounty_usdt_value = all_bounties[0].value_in_usdt;
var bounty_status = all_bounties[0].status;
if (bounty_status === "open") {
var text = document.createTextNode(`Claim issue · $${bounty_usdt_value}`);
bounty_text.appendChild(text);
} else if (bounty_status === "fulfilled") {
var text = document.createTextNode(`Fulfilled issue · $${bounty_usdt_value}`);
bounty_text.appendChild(text);
} else {
var text = document.createTextNode(`Claimed issue · $${bounty_usdt_value}`);
bounty_text.appendChild(text);
}
} else {
var text = document.createTextNode(`Fund issue`);
bounty_text.appendChild(text);
}
bounty_anchor.appendChild(bounty_text)
}

var humanize = function(amount){
Expand Down Expand Up @@ -104,23 +262,37 @@ var injectGetBountyAmount = function(){
injectScript(injectGetBalance);
}, 1000);
}
var injectGetNumberBounties = function(repoURL){
setTimeout(function(){
var injectThisCode = ' \
var bounty_abi = '+bountyABI+' \
var bounty_address = "'+bountyAddress+'"; \
var callback = function(error, result){\
var numBounties = result.toNumber(); \
respond_to_ext("numBounties", numBounties);\
};\
if(typeof web3 != "undefined"){ \
var bounty = web3.eth.contract(bounty_abi).at(bounty_address);\
bounty.getNumberBounties.call("'+encodeURI(repoURL)+'", callback);\
} \
';
// var injectGetNumberBounties = function(repoURL){
// setTimeout(function(){
// var injectThisCode = ' \
// var bounty_abi = '+bountyABI+' \
// var bounty_address = "'+bountyAddress+'"; \
// var callback = function(error, result){\
// var numBounties = result.toNumber(); \
// respond_to_ext("numBounties", numBounties);\
// };\
// if(typeof web3 != "undefined"){ \
// var bounty = web3.eth.contract(bounty_abi).at(bounty_address);\
// bounty.getNumberBounties.call("'+repoURL+'", callback);\
// } \
// ';

injectScript(injectThisCode);
}, 1000);

// injectScript(injectThisCode);
// }, 1000);
// }

var injectGetNumberBounties = function(repoURL) {
var repoKeyword = window.location.href.split('/')[4]
var bounties = getBountiesForKeyword(repoKeyword);
var numBounties = bounties.length;
setTimeout(function() {
var injectThisCode = `
numBounties =` + numBounties + `
respond_to_ext("numBounties", numBounties);
`;
injectScript(injectThisCode);
}, 1000);
}

var injectGetTotalBounties = function(){
Expand Down
Loading

0 comments on commit 23a91eb

Please sign in to comment.