-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
905 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
node_modules | ||
|
||
.vercel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const http = require('http'); | ||
const httpie = require('httpie'); | ||
const JSDOM = require('jsdom').JSDOM; | ||
|
||
module.exports = async (request, response) => { | ||
const username = request.query.username; | ||
const type = request.query.type; | ||
const suffix = request.query.suffix; | ||
|
||
if (!username) { | ||
return response | ||
.status(500) | ||
.send({ error: "'username' must be set" }); | ||
} | ||
|
||
const { data } = await httpie.get('https://patreon.com/' + username); | ||
const { document } = (new JSDOM(data)).window; | ||
|
||
const message = (type === "pledges") | ||
? document.querySelector('[data-tag="CampaignPatronEarningStats-earnings"] h2').innerHTML + (suffix || "/mo") | ||
: document.querySelector('[data-tag="CampaignPatronEarningStats-patron-count"] h2').innerHTML + " " + (suffix || "patrons"); | ||
|
||
response.send({ | ||
schemaVersion: 1, | ||
label: "patreon", | ||
namedLogo: "patreon", | ||
message: message, | ||
color: "ff5441", | ||
cacheSeconds: 60 * 60 * 8 // 8 hours | ||
}); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<html> | ||
<title>shields.io patreon badge</title> | ||
<head> | ||
</head> | ||
<body> | ||
<h1><a href="https://github.com/endel/shieldsio-patreon">shieldsio-patreon</a></h1> | ||
<p> | ||
Custom endpoint to allow displaying Patreon's number of patrons or amount of pledges. | ||
</p> | ||
|
||
<input id="username" name="username" placeholder="username" value="endel" onchange="rebuild();" /> | ||
<br /> | ||
|
||
<label for="type_pledges">Show pledges $</label> | ||
<input id="type_pledges" name="type" type="radio" value="pledges" onchange="rebuild();"> | ||
|
||
<label for="type_patrons">Show amount of patrons</label> | ||
<input id="type_patrons" name="type" type="radio" value="patrons" checked="checked" onchange="rebuild();"> | ||
<input name="suffix" placeholder="suffix (optional)" value="" onchange="rebuild();"/> | ||
|
||
<div> | ||
<h2>shields.io endpoint / preview</h2> | ||
<img id="preview" src="" alt="preview" /> | ||
|
||
<br /> | ||
<h3>Markdown image</h3> | ||
<textarea id="markdown" cols="60" rows="6"></textarea> | ||
|
||
<p>You may override some configurations for this badge. Check out the <a href="https://shields.io/#/endpoint">shields.io's Endpoint feature</a> documentation.</p> | ||
</div> | ||
|
||
<script type="text/javascript"> | ||
function rebuild() { | ||
var img = document.querySelector('img#preview'); | ||
var textarea = document.querySelector('textarea#markdown'); | ||
img.src = "https://img.shields.io/badge/%20loading-brightgreen.svg?style=for-the-badge&colorB=000000"; | ||
|
||
var username = document.querySelector('input[name=username]').value; | ||
var type = document.querySelector('input[type=radio]:checked').value; | ||
var suffix = document.querySelector('input[name=suffix]').value; | ||
|
||
var endpointUrl = `https://shieldsio-patreon.vercel.app/api?username=${username}&type=${type}`; | ||
if (suffix) { endpointUrl += `&suffix=${encodeURIComponent(suffix)}`; } | ||
|
||
var imageSrc = `https://img.shields.io/endpoint.svg?url=${encodeURIComponent(endpointUrl)}&style=for-the-badge`; | ||
img.src = imageSrc; | ||
textarea.innerHTML = `[![Support me on Patreon](${imageSrc})](https://patreon.com/${username})`; | ||
} | ||
|
||
rebuild(); | ||
</script> | ||
|
||
</body> | ||
</html> |
Oops, something went wrong.
0bce843
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.
Successfully deployed to the following URLs: