Created
September 21, 2024 15:30
-
-
Save mark05e/73681518fed51fb91573431b83205ba2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://ringcentral.github.io/ringcentral-embeddable/ | |
function dialNumber(number) { | |
const buttonSelector = "#viewport > div > div > div.sc-eIcdZJ.czoGgN > div.sc-BQMaI.bHaYic > div.sc-epqpcT.cBEqvY > div > div.sc-gvPdwL.lcuqyY > div.sc-ggqIjW.gfQTjQ > div > button:nth-child({index})"; | |
const digits = number.toString().split(''); | |
const delay = 500; // 50ms delay between each press | |
digits.forEach((digit, index) => { | |
setTimeout(() => { | |
const button = document.querySelector(buttonSelector.replace('{index}', digit)); | |
if (button) { | |
const rect = button.getBoundingClientRect(); | |
const x = rect.left + (rect.width / 2); | |
const y = rect.top + (rect.height / 2); | |
const mouseDownEvent = new MouseEvent('mousedown', { | |
bubbles: true, | |
cancelable: true, | |
view: window, | |
buttons: 1, // left mouse button | |
clientX: x, | |
clientY: y | |
}); | |
const mouseUpEvent = new MouseEvent('mouseup', { | |
bubbles: true, | |
cancelable: true, | |
view: window, | |
buttons: 0, // no buttons | |
clientX: x, | |
clientY: y | |
}); | |
button.dispatchEvent(mouseDownEvent); | |
button.dispatchEvent(mouseUpEvent); | |
} else { | |
console.error(`Button ${digit} not found`); | |
} | |
}, index * delay); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment