0

pls help me with adding sound notification to my TamperMonkey script, i trying many ways, but can't understand how to make it work. Site where i'm test it: https://p2p.binance.com/ru/trade/all-payments/RUB?fiat=RUB

// ==UserScript==
// @name         Binance Helper
// @namespace    https://p2p.binance.com/ru/trade/*
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://p2p.binance.com/ru/trade/all-payments/RUB?fiat=RUB
// @require      http://code.jquery.com/jquery-3.4.1.min.js
// @icon         https://www.google.com/s2/favicons?sz=64&domain=pogrommist.ru
// @grant        none
// ==/UserScript==
const mySound = new Audio("https://audio.code.org/win3.mp3");
const myinterval = window.setInterval(function() {
  $(".css-1m1f8hn").each((i, value) => {
    if (parseFloat($(value).html()) < 1.06) {
      $(value).css("border", "3px solid red")
      mySound.play()
      return false;
    }
  });
}, 3000); // 1

1 Answers1

0

Your code seams to work fine, can you give more details or a https://stackoverflow.com/help/minimal-reproducible-example

const mySound = new Audio("https://audio.code.org/win3.mp3");
const myinterval = window.setInterval(function() {
  $(".css-1m1f8hn").each((i, value) => {
    if (parseFloat($(value).html()) < 1.06) {
      $(value).css("border", "3px solid red")
      mySound.play()
      return false;
    }
  });
}, 3000); // 1
$("#stop").on("click", function() {
  clearInterval(myinterval)
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> 3 Second delay
<div class="css-1m1f8hn">1</div>
<button id="stop">stop</button>

thanks

Patrick Hume
  • 2,064
  • 1
  • 3
  • 11
  • That's strange, but in Chrome i don't hear sound, if i open this page in Edge and press run Snippet i hear it. What can be wrong with my Chrome? Looks like for chrome i need to use something like this https://stackoverflow.com/questions/60394997/html5-audio-autoplay-not-working-in-chrome But i don't understand how to implement it in js – Сергей Родин Aug 11 '22 at 18:39
  • thats stange as I'm running chrome and I can hear the code snippet example, do you have some plug-in /extension in chrome or have you changed a chrome setting that might account for it, check what version you are running too, I'm running Version 104.0.5112.81 (Official Build) (64-bit) – Patrick Hume Aug 11 '22 at 19:04
  • I checked in firefox and edge both work ok, try this fiddle see if that's any better: https://jsfiddle.net/PatrickHume/qx40octg/1/ – Patrick Hume Aug 11 '22 at 19:06
  • same 104.0.5112.81. I already disable all adblockers, but still can't hear voice in chrome(((( i can't open fiddle in my country((( – Сергей Родин Aug 11 '22 at 19:19
  • Here is error description, when i'm trying to use it as chrome extension, https://www.dropbox.com/s/vzdunldeogubjmf/%D0%A1%D0%BA%D1%80%D0%B8%D0%BD%D1%88%D0%BE%D1%82%202022-08-11%2023.10.13.png i don't understand how i can start interact with it, if i don't have any buttons or somesting like this – Сергей Родин Aug 11 '22 at 20:11
  • Ok, i run chrome with --autoplay-policy=no-user-gesture-required and it's help me to her sound in you'r "Run code snippet", but on real site with tampermonkey, i still not hear sound(((((( I change top question code to real code and link site where im try to do that, can you test? – Сергей Родин Aug 11 '22 at 20:51
  • is the sound meant to play when the site loads or do I need to click something first? – Patrick Hume Aug 11 '22 at 21:12
  • same as red boarder if->true-> red boarder and play sound, no interact needed, on site in right side you may see refresh button, wich refresh bottom frame each 5 second, script runs every 3 second, if he found value - boarder and sound. You may see in first post, page and full script, what i need to start work – Сергей Родин Aug 11 '22 at 21:19
  • no dosnt appear to work in any of the browsers looking at the page source code I could not see where the audio script even was ? – Patrick Hume Aug 11 '22 at 21:37