Filling fields with JS(Violent Monkey)

31 views Asked by At

I'm trying to fill a page automatically with a button added with Violent Monkey, I Already made some arrangements but the page uses javascript as it is a "dynamic" table where you can add rows, This part works fine. and was able to change one of the fields, but some of them are "different" and not sure how to approach them as they change the code after clicking on them

<tr class="data" lang="0" name="dataRow0">
    <td class="modCol c">
        <div class="insert " title="Add Row Below">
            <i class="fa fa-plus-circle fa-lg" aria-hidden="true"></i>
        </div>
        <div class="delete " title="Delete Row">
            <i class="fa fa-times fa-lg" aria-hidden="true"></i>
        </div></td>
            <td colspan="1" class="c  formatTooltip  unlocked  orig_unlocked lookup alt  hasCodeDates" title="Worked" lang="code">(W)</td>
            <td colspan="1" class="c  formatTooltip  unlocked  orig_unlocked lookup" title="Auto" lang="center">AUTO</td>
            <td colspan="1" class="c  formatTooltip  unlocked  orig_unlocked lookup alt" title="" lang="position" name="center">AUTO</td>
            <td colspan="1" title="" class="c  unlocked  orig_unlocked editable" lang="startTime" name="militaryTime">00:00</td>
            <td colspan="1" title="" class="c  unlocked  orig_unlocked editable alt" lang="endTime" name="militaryTime">00:00</td>
            <td colspan="1" title="" class="c  unlocked  orig_unlocked editable" lang="duration" name="duration546">00:00</td>
            <td colspan="1" class="c  formatTooltip  locked  orig_locked  alt" title="Regular Time Hours" lang="hourType">REG</td>
            <td colspan="1" title="" class="c  unlocked  orig_unlocked editable" lang="udf2"></td>
</tr>

Then after clicking/selecting the field it changes to

<tr class="data" lang="0" name="dataRow0">
    <td class="modCol c">
    <div class="insert " title="Add Row Below">
        <i class="fa fa-plus-circle fa-lg" aria-hidden="true"></i>
    </div>
        <div class="delete " title="Delete Row"><i class="fa fa-times fa-lg" aria-hidden="true"></i>
    </div></td>
<td colspan="1" class="c  formatTooltip  unlocked  orig_unlocked lookup alt  hasCodeDates" title="Worked" lang="code">(W)</td>
<td colspan="1" class="c  formatTooltip  unlocked  orig_unlocked lookup currentFocus" title="Auto" lang="center">
    <input id="dValue" class="lookupInputBox" lang="center" name="undefined" value="AUTO" type="text">
    <div class="lookupIndicator search2" lang="center">
        <i class="fa fa-search lookupButton" aria-hidden="true"></i>
    </div>
        </td><td colspan="1" class="c  formatTooltip  unlocked  orig_unlocked lookup alt" title="" lang="position" name="center">AUTO</td>
        <td colspan="1" title="" class="c  unlocked  orig_unlocked editable" lang="startTime" name="militaryTime">00:00</td>
        <td colspan="1" title="" class="c  unlocked  orig_unlocked editable alt" lang="endTime" name="militaryTime">00:00</td>
        <td colspan="1" title="" class="c  unlocked  orig_unlocked editable" lang="duration" name="duration546">00:00</td>
        <td colspan="1" class="c  formatTooltip  locked  orig_locked  alt" title="Regular Time Hours" lang="hourType">REG</td>
        <td colspan="1" title="" class="c  unlocked  orig_unlocked editable" lang="udf2"></td>
</tr>

And this is the code I wrote till now: I'm aware that copying is not possible due to security reasons, So tried to store those values in variables an tried just paste them on click like with a normal field but that does not work in that case

var zNode       = document.createElement ('div');
zNode.innerHTML = '<button id="fill" type="button">'
                + 'Autofill'
                ;
zNode.setAttribute ('id', 'myContainer');
document.body.appendChild (zNode);

//--- Activate the newly added button.
document.getElementById ("fill").addEventListener (
    "click", ButtonClickAction, false
);
  // Update/addrows to table simulating user
function ButtonClickAction (zEvent) {
  document.getElementsByClassName("fa fa-plus-circle fa-lg")[0].click();
  document.getElementsByClassName("fa fa-plus-circle fa-lg")[0].click();
  document.getElementsByClassName("fa fa-plus-circle fa-lg")[0].click();
  document.getElementsByClassName("fa fa-times fa-lg")[0].click();

  // 80 (hours)
  document.getElementById("actualShift").addEventListener('click', function () {
    var text = document.getElementById('actualShift');
    text.value = '80';
});
  document.getElementsByClassName("actualShift preference_showActualShift search lookupInputBox")[0].click();

  //paste/input value of workcode
    document.getElementsByClassName("c  formatTooltip  unlocked  orig_unlocked lookup")[1].click();
    document.getElementByClassName("c  formatTooltip  unlocked  orig_unlocked lookup currentFocus").addEventListener('click', function () {
    var text = document.getElementById('dValue');
    text.value = workcode;
});
0

There are 0 answers