https://github.com/akira-cn/upvote-anywhere
Generate a SVG button that allows you to get upvoted anywhere.
https://github.com/akira-cn/upvote-anywhere
Last synced: 25 days ago
JSON representation
Generate a SVG button that allows you to get upvoted anywhere.
- Host: GitHub
- URL: https://github.com/akira-cn/upvote-anywhere
- Owner: akira-cn
- License: mit
- Created: 2023-08-16T09:04:57.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-08-17T02:29:55.000Z (almost 2 years ago)
- Last Synced: 2025-03-30T00:04:06.907Z (about 2 months ago)
- Language: JavaScript
- Size: 29.3 KB
- Stars: 18
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Upvote Anywhere
Generate a SVG button that allows you to get upvoted anywhere.
**[👁️🗨️ Generate my upvote button ⬆️](https://wp2aqcqkj5.us.aircode.run/create)**
## To be used in GitHub README
Do you like Upvote Anywhere? If you do, please give it an upvote.
## To be used in Any Web App
[Try it in CodePen](https://codepen.io/akira-cn-the-selector/pen/XWorRbL)
```html
Do you like Upvote Anywhere? If you do, please give it an upvote.
upvoteBtn.addEventListener('click', async (event) => {
event.preventDefault();
await fetch('https://wp2aqcqkj5.us.aircode.run/upvote', {
method: 'POST',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({id: '64dc8e2885f13fbcd52be970'}),
});
upvoteBtn.src = "https://wp2aqcqkj5.us.aircode.run/show?id=64dc8e2885f13fbcd52be970&t=" + Date.now();
});```
## Cookie Policy
Since Upvote Anywhere requires using cookies to track upvote status, when it's used on third-party websites and operated through fetch, it relies on the other party's CORS policy. For instance, CodePen's policy doesn't allow cross-site cookies, which means Upvote Anywhere can't record the voted status. However, we can use a GET request to https://wp2aqcqkj5.us.aircode.run/upvote to store the cookie on the original site, then redirect back to the target URL, just as we've done in our GitHub README.
## Distribution
Upvote Anywhere is build on [AirCode](https://aircode.io/).
You can easily get a copy and launch your app on [AirCode](https://aircode.io/) by clicking the button below.
[](https://aircode.io/dashboard?owner=akira-cn&repo=upvote-anywhere&branch=main&path=&appname=upvote)