-
-
Notifications
You must be signed in to change notification settings - Fork 30
Browser Extension Beta #5
Changes from all 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,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; | ||
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){ | ||
// 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) | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
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); | ||
} | ||
|
||
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){ | ||
|
@@ -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(){ | ||
|
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!