One Form (Phones) - Improvements Project

Going Above and Beyond!

// ==UserScript==
// @name         One Form (Phones) - Improvements Project
// @namespace    I_will_be_hired
// @version      0.1
// @description  Going Above and Beyond!
// @author       MySelf
// @include      https://td.*.*/TDNext/Apps/48/Tickets/New?formId=3244
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAAXNSR0IArs4c6QAADXhJREFUeF7tW0lvHMcVfr3OvnInLVk05TiRE0QGjORHxNlhIAiQ/JQsSBAgQA455JBDkP8jn+yjD5ZtObZkiSLFbfYl+N5SXT2kZ0hldGCkBgpvNBx19/vqe0u9ehWs/PbfU8IVhERhREEQs+TPkEHIMghDCsOAwkBkFIWURAElKmP+WzaCgO+6tAu3wz3xDMgI7xAGFEcq9d/2fRTqbwL5u7w7RnYPVvsVAL/5V44BFMQy8yFkSBTI7OM7oChMCCkOlQGxSEbeMQCztVwK4HY5BgQzsx/hnTJm4F0yNmQzD5WYRcrNoP3rfzoAgtDobyCYGZgJmAzVBEJK4oDSKHQPM4rhIcu8fADwDKY/myJkyKbA/7bvmfIZIEx/VR7fGwRB+1f/8BgAxWOi6AJfwAwQQMCCKIoohQ9gBgB9PJzEP6idLhcAbxYNADzflPd8gQHBtu98gMw8K+8zoPX+3zMGRGBATAFLHwRhBI9IzCNm5wcGhAyE/1A8eMkEcPQ3MwPY8g5iCsIAmYgcADwhMjGmfI4BrV/+LWNAZAxQqSYhpqEgKDjCAANAKOh74GX7gJBMCWEYqC9RyFNeJ8JAYDaa9/fp7zOg+fO/CgDs6HwG+CAIK9g5KkgAwOjPJuCZgTBguT7AfIs5Wx8Aeb7MPA/zSTrzBoI40RkTaP7sLxf4gPNMELMw84jZByRxpHlAdC4eL1l/Z8vm3aGwy0NiU1zMwByhMIAkOmFSNJfI+YDGT/6UjwJmBqZslKhjNFDk3wAgVgAgzf7s4S8MAKW10d/5IPUBfnJkYLnQp96fI4qFwcaP/3guDEokgMKJyEglfy8AhADAgYDPGfJ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Mx1t7P6bq8Q84ncDe7OFphQd4krC9xgQ/wUZmlYP6YHR+w8nqKln5kxHPGuLf5Izvmh8bNi3wCN2IqCH6D9XMCkOUF1jrDdq/nC62hKtdet4hZl/07d3edfz6fb3IN3gYCTCLzCXLGMTvdAp/w/ADkwmJ2sDKv/AuIAvpc7vQzc9QDXnl/JGedpJVXfQKHSXGKFiafA4CZvABLi1z7rL6Yn0BddnYv8zt2WvIMxwQ9wJWZg513zMIj+wUAYAxQc7DE6wo+QMOiraQsLmsCxKYwkz1eRq8r/YafrSCY6dkxX9fXnPU3s0/gZEnYYMtx+ITnY4CfFzgGeN7/Rc0+Y28zrym6ZoNyzjlr55Pjfpapqk9QECRPEDCwKLtEIjRnflxYnAHAzx6vNL2LfiyKy2k0dYameC4sewe/1UHaeUfLESI9/Pm/AaAvwS9kGeCLZICxwLV867lmfrawwM2+f/pdj/vZOSeAAJMQk53XKLloQv5PAPgvi2YHVPfqWRYAAAAASUVORK5CYII=
// @run-at       document-end
// @grant        none
// ==/UserScript==

(function() {
  'use strict';
  //MY TO DO LIST!!!

  //Make noname1/2/3 show all under noname, or when noname1/2/3 is clicked auto open the drop down menu and show the options.
  //Hide person type, until the person name or I-Number is found, since this input box is never used until the person name or I-Number is found. And sometimes Phone Agents try to write names/I-Numbers on this box.
  //The next improvement steps for this script will be to add stock texts that can be single clicked and auto pasted on the input notes box, to improve the ticketing speed.
  //Fetch the caller profile page and append more data like credits, assigned track and holds on the One Form Phone website on the right side of the screen for convenience of the Phone Agent!
  //When Sechedule adivising appointment is selected, auto open the I-Planner schedule for others link for convenience.
  //Auto search for keywords (key terms) when they are written in the notes and auto select the right tag for it, example: If Phone Agent wrote "want's to defer", the deferments questions tag would be selected.

  //var array = [];
  //document.querySelectorAll("#select2-results-3 >li > div > span").forEach(a => array.push(a.nextSibling.nodeValue));
  //https://pastebin.com/8Aes5dRa
  //List of all available tags


  document.querySelectorAll("fieldset")[1].insertAdjacentHTML('beforeend', '<label style="cursor:pointer; margin-left: 10px;" id="ALL"><input data-val="true" type="radio">ALL Tags</label>'); //Add a tag called "ALL Tags" for the convenience mentioned in the previous comment
  document.querySelectorAll("fieldset")[1].insertAdjacentHTML('beforeend', '<label style="cursor:pointer; margin-left: 10px;" id="Dropped"><input data-val="true" type="radio">Dropped Call</label>'); //Add a tag called "Dropped Call" for convenience (This really should have been built in in the One Form itself...)

  document.querySelector("#Dropped").onclick = function() {
    window.open("https://td.xxxx.xxx/TDNext/Apps/40/Tickets/New?formId=2582", "_blank"); //REPLACE xx with the proper url!!!!!!!!!!!!!!!!!!!!!
    this.querySelector("input").checked = false;
  }

  document.querySelector("#ALL").onclick = function() {
    document.querySelectorAll("#attribute10329-grp > div.js-ca > fieldset > label.radio-inline > input").forEach(el => el.checked = false); //Uncheck any checked tags

    setTimeout(function() {

      document.querySelectorAll("#attribute10333 > option").forEach(function(el) { //Reveal again all hidden tags
        el.className = '';
        el.hidden = false;
        el.disabled = false;
      })
      document.querySelector("#attribute10333-grp").style.display = 'block'; //Reveal the drop down menu with all tags
      document.querySelector("#attribute10333 > option:nth-child(2)").remove(); //Hide the needless Abandoned chat tag on the phone tags... Why is it on the one form phone html?
    }, 100);
  }

  document.querySelectorAll("#attribute10329-grp > div.js-ca > fieldset > label.radio-inline").forEach(function(el) {
    el.onclick = function() {
      if (document.querySelector("#ALL > input").checked === true) {
        document.querySelector("#ALL > input").checked = false; //Uncheck the ALL Tags btn
      }
    }
  })

  //Remove needless html on the page
  document.querySelector("div.gutter-left-sm.gutter-bottom-sm.gray").remove();
  document.querySelector("div.form-group.gutter-top.required").remove(); //Workers do not have the need to change between forms
  document.querySelector("h2").remove();
  document.querySelector("#static-1461581-grp > div > span").remove();

  //Better page formatting
  document.querySelector("#attribute528-grp > div.input-group").setAttribute('style', 'width: 730px; top: -30px; left: 140px;');
  document.querySelector("#attribute50-grp > div.input-group").setAttribute('style', 'width: 750px; top: -30px; left: 120px;');
  document.querySelector("#attribute50-help").style.position = 'absolute';
  document.querySelector("#attribute528-help").style.position = 'absolute';
  document.querySelector("#select2-chosen-2").innerText = 'Person Type...';
  document.querySelector("#select2-chosen-1").innerText = 'Caller I-Number or Name...';
  document.querySelector("#attribute12375-grp > div.js-ca").setAttribute('style', 'display: inline-block; position: relative; top: 15px;');
  document.querySelector("#attribute10376-grp > div.js-ca").setAttribute('style', 'display: inline-block; position: relative; top: 15px;');
  document.querySelector("#attribute11847-grp > div.js-ca").setAttribute('style', 'display: inline-block; position: relative; top: 15px;');
  document.querySelector("#attribute10500-grp > div.js-ca").setAttribute('style', 'display: inline-block; position: relative; top: 5px;');
  document.querySelector("#attribute10500-grp > div.js-ca").setAttribute('style', 'display: inline-block; position: relative; top: 5px;');
  setTimeout(function() {
    document.querySelector("#attribute146").placeholder = "In this section, record your notes and tag the ticket with the most accurate tag that fits the situation you are helping the contact with.";
  }, 0);
})();