From 5ef75829b79b4e1a034324c4b72d21cad0f01cbc Mon Sep 17 00:00:00 2001 From: Saif Sultan Date: Wed, 29 Jan 2025 12:00:29 +0530 Subject: [PATCH] `gpqr-play-beep-on-scan.js`: Added snippet to play beep sound on successful QR Code scan. --- gp-qr-code/gpqr-play-beep-on-scan.js | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 gp-qr-code/gpqr-play-beep-on-scan.js diff --git a/gp-qr-code/gpqr-play-beep-on-scan.js b/gp-qr-code/gpqr-play-beep-on-scan.js new file mode 100644 index 000000000..88322e446 --- /dev/null +++ b/gp-qr-code/gpqr-play-beep-on-scan.js @@ -0,0 +1,34 @@ +/** + * Gravity Perks // GP QR Code // Automatically Play Beep Sound on Successful Scan + * https://gravitywiz.com/documentation/gravity-forms-qr-code/ + * + * When using the QR scanner, automatically play beep after a successful scan. + * + * Instruction Video: https://www.loom.com/share/7f413231517b423eba3ccc1bf3055b40 + * + * We recommend installing this snippet with our free Custom Javascript plugin: + * https://gravitywiz.com/gravity-forms-code-chest/ + */ +function playBeep() { + var context = new( window.AudioContext || window.webkitAudioContext )(); + var oscillator = context.createOscillator(); + var gainNode = context.createGain(); + + oscillator.type = "square"; // Square wave for a more scanner-like sound. + oscillator.frequency.setValueAtTime( 800, context.currentTime ); // Frequency in Hz. + gainNode.gain.setValueAtTime( 0.5, context.currentTime ); // Adjust volume. + + oscillator.connect( gainNode ); + gainNode.connect( context.destination ); + + oscillator.start(); + + // Beep duration in milliseconds. + setTimeout( () => { + oscillator.stop(); + }, 100 ); +} + +gform.addAction( 'gpqr_on_scan_success', function( decodedText, decodedResult, gpqr ) { + playBeep(); +} );