-
-
Notifications
You must be signed in to change notification settings - Fork 30
Browser Extension Beta #5
Changes from 11 commits
4b8adb5
a3d72ac
3fd2f27
0bfbbd7
c057845
8220d08
a797c4d
c6b0927
82f671e
5551ca7
2be831c
3559062
0e80101
11473b5
3610842
febeebe
f097c3a
bb2e24f
c212407
cf8d1f5
ab410fa
a563aed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this reminds me, i should refactor There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, thanks for this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mind making this change
|
||
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){ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
|
||
|
@@ -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>'; | ||
|
@@ -66,15 +75,69 @@ var addMessage = function(_class, msg, seconds=5000){ | |
setTimeout(callback, seconds); | ||
} | ||
|
||
getAllBounties = function(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 == ""){ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!