Web monetization plugin for Gridsome.
- Add
gridsome-plugin-monetization
dependency to your project
yarn add gridsome-plugin-monetization # or npm install gridsome-plugin-monetization
- Add
gridsome-plugin-monetization
to theplugins
section ofgridsome.config.js
{
plugins: [
{
use: "gridsome-plugin-monetization",
options: {
paymentPointer: "$wallet.example.com/alice", // your payment pointer
global: true, // add monetization to every page; default: true
},
},
],
}
For gridsome-plugin-monetization
to work properly, you must specify your payment pointer (paymentPointer
) in the gridsome plugin options as shown above.
NOTE: As of now, any of the following methods are unable to be accessed at build time through component
data
ortemplate
s due to SSR constraints.
Enables web monetization for the current page if not already enabled.
Returns: HTMLElement | false
Disables web monetization for the current page if not already disabled.
Returns: undefined | false
Gets the document's monetization DOM object if monetization is enabled.
Returns: HTMLElement | false
Checks if the browser has monetization capability within the document.
Returns: true | false
Checks if the monetization is currently enabled within the document.
Returns: true | false
Checks if the monetization is currently disabled within the document.
Returns: true | false
Checks if the browser is currently sending payments.
Returns: true | false
Checks if the browser is currently preparing to send payments.
Returns: true | false
Checks if the browser is currently not sending payments.
Returns: true | false
Gets the current state of the browser's monetization event if monetization is enabled.
Returns: ("started" || "stopped" || "pending") | false
Converts a monetization event to its corresponding state string.
Returns: ("started" || "stopped" || "pending") | false
The specification for the
event
objects returned for each handler are specified on the Web Monetization JavaScript API page.
Attaches a listener for the started
state on the monetization object using the specified handler.
Returns: undefined | false
Attaches a listener for the pending
state on the monetization object using the specified handler.
Returns: undefined | false
Attaches a listener for the stopped
state on the monetization object using the specified handler.
Returns: undefined | false
Attaches a listener for when the current amount of progress in sending funds changes on the monetization object using the specified handler.
Returns: undefined | false
Attaches the onStart
, onPending
, and onStop
listeners to the handler.
Returns: undefined | false
This example can also be found by launching the demo project in the demo/
folder (see the Development section below).
<template>
<Layout>
<button @click="toggle">Toggle Monetization</button>
<h2>Current state: {{ state }}</h2>
</Layout>
</template>
<script>
export default {
metaInfo: {
title: "Web Monetization",
},
data() {
return {
state: "Waiting for monetization to load...",
}
},
methods: {
toggle() {
this.$monetization.isEnabled()
? this.$monetization.disable()
: this.$monetization.enable()
},
},
mounted() {
this.state = this.$monetization.getState()
this.$monetization.onStateChange(
(event) => (this.state = this.$monetization.getEventStateString(event))
)
},
}
</script>
- Clone this repository
- Install dependencies using
yarn install
ornpm install
yarn link
ornpm link
in the projects directorycd demo/
yarn link gridsome-plugin-monetization
ornpm link gridsome-plugin-monetization
in thedemo/
directory- Start the development server with
yarn dev
ornpm run dev
A basic demo is hosted on 💻 CodeSandbox.
NOTE: By default,
<iframe>
components do not have monetization enabled, so the inline project browser in CodeSandbox will not work with monetization. However, you can open the browser in another tab or access the project here to see it in action.
Copyright (c) sergix [email protected]