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 11 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
12 changes: 12 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: 100%;
}

</style>

</head>
Expand All @@ -116,6 +127,7 @@ <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..">
<table class="table table-striped" id="openbounties">
<thead>
<tr>
Expand Down
18 changes: 17 additions & 1 deletion script/pageload/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,41 @@ 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){
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) {
console.log('on issues page!!')
injectGetAllBountiesOnIssuesPage();
}
if (isOnIssueBoard) {
console.log('on issues board!!')
setTimeout(function() {
document.addEventListener('DOMNodeInserted', injectGetAllBountiesOnIssueBoard);
}, 5000)

}
}

Expand Down
131 changes: 122 additions & 9 deletions script/pageload/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,140 @@ 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);
}

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 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 (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;
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.setAttribute("style", "position: absolute; top: 3px; right: 155px;");
var text = document.createTextNode("+ Fund Issue");
bounty_anchor.appendChild(text);
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");

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);
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);
}

var addBountyInfoToIssuePage = function(url) {
var all_bounties = getAllBounties();
for (var i = all_bounties.length - 1; i >= 0; i--) {
if (all_bounties[i].github_url === url) {
var bounty_anchor = document.getElementsByClassName('gitcoin_bounty')[0];
var bounty_eth_value = all_bounties[i].value_true;
var bounty_usdt_value = all_bounties[i].value_in_usdt;
var text = document.createTextNode(` $${bounty_usdt_value} · ${bounty_eth_value} ETH`);
bounty_anchor.appendChild(text)
}
}
}

var humanize = function(amount){
Expand Down
63 changes: 63 additions & 0 deletions script/popup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ var web3account = function(){
return localStorage['web3account'];
}

var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();


function timeDifference(current, previous) {

Expand Down Expand Up @@ -56,6 +64,7 @@ function timeDifference(current, previous) {

return amt + ' '+unit+plural+' ago';
};

var addMessage = function(_class, msg, seconds=5000){
var id = Math.floor((Math.random() * 1000000) + 1);
var html = '<li id ="'+id+'" class="'+_class+'">'+msg+'</li>';
Expand All @@ -66,15 +75,69 @@ var addMessage = function(_class, msg, seconds=5000){
setTimeout(callback, seconds);
}

getAllBounties = function(){
Copy link
Contributor

Choose a reason for hiding this comment

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

i wonder if theres a way to DRY here.

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);
}

var limitStr = function(str,len){
if(str.length < len){
return str;
}
return str.substring(0,len) + '...';
}

var appendTableNodes = function(bounties) {
$("#openbounties tbody").empty();
if(bounties.length == 0){
$("#openbounties tbody").append('No Bounties Found');
}
var max_display = 10;
for(var i=0; i<bounties.length && i<max_display; i++){
var bounty = bounties[i];
var val = Math.round(100.0 * bounty['value_in_token']/10**18) / 100;
var newHTML = ' <tr> \
<td>'+timeDifference(new Date(), new Date(bounty['web3_created']))+'</td> \
<td>'+val+' '+bounty['token_name']+'</td> \
<td>'+limitStr(bounty['title'],30)+'</td> \
<td><a target=_blank href="'+bounty['github_url']+'">View >></a></td> \
</tr> \
';
$("#openbounties tbody").append(newHTML);
}
}

var all_bounties = getAllBounties();

var searchBounties = function(keyword) {
keyword = keyword.toLowerCase();
var 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 do_keywords_contain = bounty_keywords.indexOf(keyword) !== -1;
var does_title_contain = bounty_title.indexOf(keyword) !== -1;
if (do_keywords_contain || does_title_contain) {
matching_bounties.push(all_bounties[i])
}
}
appendTableNodes(matching_bounties)
}


$(document).ready(function(){

$('#search_bar').keyup(function() {
delay(function() {
var keyword = document.getElementById('search_bar').value;
searchBounties(keyword);
}, 500)
})

$('input[name=Tip]').click(function(){
var username = $("input[name=username]").val()
if (username == ""){
Expand Down