vote.wdgt

Free Proof-of-Work API for fancy Vote Counting widgets.

Demonstration

Click the button below:

Embedding

<button class="votewdgt">?</button>
<script src="https://vote.wdgt.io/cdn/snippet-v2.js" async></script>

Use-cases

vote.wdgt widgets are completely free of use (see Availability below). When embedded on the website they will show vote count for the current page. Widgets can be inserted into:

Styles

No styling is provided by default. However the widget has rich set of classes, each describing particular state of it:

A collection of user-supplied styles is available on this wiki page.

Proof-of-Work

The backend API for these widgets uses proof-of-work JavaScript module for generating/verifying nonces to prevent vote spamming. When user casts the vote - a nonce will be brute-forced, until particular SHA256 hash will match requested server’s complexity.

Availability

Since this project is absolutely free to use author can provide only limited availability guarantees. If widgets stop working - please file an issue here.

Programmatic API

Widget may be created programmatically too:

const widget = new VoteWidget('elem-id' /* or DOM node */);

Alternatively completely custom widget class may be created:

const inherits = require('inherits');
const Base = VoteWidget.Base;

function CustomWidget() {
  // Some configuration
  Base.call(this, /* optional */ 'vote-counter-id');
}
inherits(CustomWidget, Base);

CustomWidget.prototype.onStateChange = function onStateChange(state, payload) {
  // See states below
};

const instance = new CustomWidget();

// Cast vote:
instance.vote((err, res) => {
  // res = { votes: 1 }
});

Following states are available (they follow CSS classes above closely). Payload is missing unless stated explicitly:

NOTE: No DOM interactions are included in Base class. They have to be implemented in CustomWidget.

LICENSE

This software is licensed under the MIT License.

Copyright Fedor Indutny, 2017.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.