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

Browser Extension Beta #5

Merged
merged 22 commits into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4b8adb5
adding issue amounts to issue pages
jclancy93 Nov 22, 2017
a3d72ac
search implentation v1 working
jclancy93 Nov 22, 2017
3fd2f27
improved search, now doing string matching on raw_data.issueKeywords …
jclancy93 Nov 23, 2017
0bfbbd7
fixing get all bounties url to return claimed bounties as well
jclancy93 Nov 23, 2017
c057845
beginning work on adding issue state/amount icons to all issues on is…
jclancy93 Nov 24, 2017
8220d08
adding more robust check for isOnUserProfile
jclancy93 Nov 24, 2017
a797c4d
funded issue state and amount for open issues
jclancy93 Nov 24, 2017
c6b0927
updating search styles and allowing searches for already claimed issues
jclancy93 Nov 24, 2017
82f671e
prototype code to add issues to issue board page
jclancy93 Nov 24, 2017
5551ca7
updating button styles
jclancy93 Nov 24, 2017
2be831c
adding buttons to issue board (WIP) and updating user tip button styles
jclancy93 Nov 24, 2017
3559062
code for issue boards that doesn't cause crash
jclancy93 Nov 27, 2017
0e80101
add set timeout so issue boards injection works
jclancy93 Nov 27, 2017
11473b5
typo
jclancy93 Nov 27, 2017
3610842
fixed issue detail page positioning + text and v1 of issue board
jclancy93 Dec 7, 2017
febeebe
persistent search keyword
jclancy93 Dec 13, 2017
f097c3a
autofilling repo keyword when on github repo
jclancy93 Dec 13, 2017
bb2e24f
correctly setting thumbnail number
jclancy93 Dec 14, 2017
c212407
exact match between thumbnail number and issues listed in search
jclancy93 Dec 14, 2017
cf8d1f5
final fixes for setThumbnail
jclancy93 Dec 14, 2017
ab410fa
Merge branch 'master' into revamp
owocki Dec 19, 2017
a563aed
Merge branch 'master' into revamp
owocki Dec 19, 2017
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
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");
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!

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

this reminds me, i should refactor isOnIssuePage to be more descriptive of where the user actually is

Copy link
Contributor Author

Choose a reason for hiding this comment

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

definitely, this is something I can add too. A simple "check if element on page" should suffice, unless you have something else in mind

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';
Copy link
Contributor

Choose a reason for hiding this comment

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

if you wanted to be more performant/selective, you could search bounties by keyword here (so that you don't have to match inside the for loop on line 28).

Here's an example: https://gitcoin.co/api/v0.1/bounties/?raw_data=python

Copy link
Contributor

Choose a reason for hiding this comment

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

itd also be good to only show mainnet bounties that are open

https://gitcoin.co/api/v0.1/bounties/?&idx_status=open&network=mainnet

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, thanks for this

Copy link
Contributor

Choose a reason for hiding this comment

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

mind making this change

itd also be good to only show mainnet bounties that are open

https://gitcoin.co/api/v0.1/bounties/?&idx_status=open&network=mainnet

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