Search code examples
javascripttampermonkey

How to fix issue on tampermonkey script


I am using a tampermonkey script but I have this error. I don't know how to fix this issue.

the error displayed the source

document.onkeypress = async function(e) {
    e = e || window.event;
    var charCode = (typeof e.which == "number") ? e.which : e.keyCode;
    if (String.fromCharCode(charCode) === '=') {
        const {
            value: formValues
        } = await Swal.fire({
            title: 'Enter your credentials ',
            html: '<input id="swal-input1" class="swal2-input" placeholder="email"
            type = "text"
            value = "kor@gmail.com" > ' +
            '<input id="swal-input2" class="swal2-input" placeholder="password"
            type = "password"
            value = "A23@" > ',
            focusConfirm: false,
            preConfirm: () => {
                return [
                    document.getElementById('swal-input1').value,
                    document.getElementById('swal-input2').value
                ][![enter image description here][1]][1]
            }
        })

Solution

  • Try to use ` ... ` ;
    You can search about template string in javascript.
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

    document.onkeypress = async function(e) {
            e = e || window.event;
            var charCode = (typeof e.which == "number") ? e.which : e.keyCode;
            if (String.fromCharCode(charCode) === '=') {
                const {
                    value: formValues
                } = await Swal.fire({
                    title: 'Enter your credentials ',
                    html: `<input id="swal-input1" class="swal2-input" placeholder="email" type = "text" value = "kor@gmail.com" >
                           <input id="swal-input2" class="swal2-input" placeholder="password" type = "password" value = "A23@" > `,
                    focusConfirm: false,
                    preConfirm: () => {
                        return [
                            document.getElementById('swal-input1').value,
                            document.getElementById('swal-input2').value
                        ]
                    }
                })
    

    Also, you can try like below;

    html: '<input id="swal-input1" class="swal2-input" placeholder="email" type="text" value="kor@gmail.com"> <input id="swal-input2" class="swal2-input" placeholder="password" type="password" value="A23@" > ',