EZ-Blurb

EZ-Blurb will save your time with frequently used blurbs.

目前为 2025-02-15 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name EZ-Blurb
  3. // @namespace http://tampermonkey.net/
  4. // @version V0.3
  5. // @description EZ-Blurb will save your time with frequently used blurbs.
  6. // @author Amin Ahmadizadeh
  7. // @match https://omnia.it.a2z.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=a2z.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. cardNumbers = 0
  15. let cardsObjects = []
  16. let blurbs = []
  17. 'use strict';
  18. setTimeout(start,10000)
  19. class Card{
  20. constructor(card){
  21. console.log("EZB->Creating Card Object", card)
  22. this.card = card
  23. this.customerName = document.querySelectorAll(".editable-contact-alias")[0].innerText.split(" ")[0]
  24. this.card.loaded = true
  25. this.blurbDiv = document.createElement("div")
  26. this.blurbDiv.style.marginTop = '-10px'
  27. this.card.appendChild(this.blurbDiv)
  28. this.addButtons()
  29. }
  30.  
  31. addButtons(){
  32. if (blurbs.length > 0)
  33. blurbs.forEach((blurb)=>{
  34. this.addButton(blurb.symb, blurb.tooltip, blurb.text, blurb.backColor, blurb.textColor)
  35. })
  36. }
  37.  
  38. sendMessage(text){
  39. localStorage.setItem("EZBMessage",text);
  40. console.log("Sending messgage...")
  41. const iframe = document.querySelector("iframe")
  42. iframe.contentWindow.postMessage("EZB" + text, 'https://itservices-connect.my.connect.aws/ccp-v2');
  43. }
  44.  
  45. addButton(symb,tooltip,text,backColor,textColor){
  46. var div = document.createElement("SPAN")
  47. div.innerText = symb
  48. div.style.display = 'inline-block'
  49. div.style.padding = '0px 5px'
  50. div.style.borderRadius = "10px"
  51. div.style.margin = "1px"
  52. div.style.backgroundColor = backColor
  53. div.style.color = textColor
  54. div.title = tooltip
  55. this.blurbDiv.appendChild(div)
  56. div.addEventListener('click',()=>{this.sendMessage(this.compileText(text))})
  57. div.addEventListener('mouseover',()=>{
  58. div.style.backgroundColor = 'red'
  59. })
  60. div.addEventListener('mouseout',()=>{
  61. div.style.backgroundColor = backColor
  62. div.style.color = textColor
  63. div.style.padding = '0px 5px'
  64. div.innerHTML = symb
  65. })
  66. }
  67. compileText(text){
  68. var customerName = document.querySelectorAll(".editable-contact-alias")[0].innerText.split(" ")[0]
  69. return text.replace("$customer$", customerName)
  70. }
  71. }
  72.  
  73. class Blurb{
  74. constructor(symb, tooltip, text, backColor, textColor){
  75. this.symb = symb
  76. this.tooltip = tooltip
  77. this.text = text
  78. this.backColor = backColor
  79. this.textColor = textColor
  80. }
  81. }
  82.  
  83. function readBlurbs(){
  84. console.log("Reading blurbs...")
  85. savedBlurbs = localStorage.getItem('EZBlurbs')
  86. const inputBtn = document.createElement("input")
  87. inputBtn.type= "file"
  88. inputBtn.multiple = false
  89. inputBtn.style.display = 'None'
  90. inputBtn.addEventListener('change',(event)=>{
  91. const file = event.target.files[0]
  92. if (file) {
  93. const reader = new FileReader();
  94. reader.onload = function(e) {
  95. blurbsJSON = JSON.parse(e.target.result)
  96. makeBlurbs(blurbsJSON.Blurbs, true)
  97. };
  98. reader.readAsText(file);
  99. }
  100. })
  101. const btn = document.createElement("input")
  102. btn.type = 'button'
  103. btn.className = 'awsui-button awsui-button-variant-normal awsui-hover-child-icons'
  104. btn.value= "Load EZ-Blurbs"
  105. btn.addEventListener('click',()=>{
  106. inputBtn.click()
  107. })
  108. document.getElementsByClassName("omnia-ui-tabtools")[0].appendChild(btn)
  109. if ( savedBlurbs ) {
  110. console.log ('Blurbs found:', localStorage.getItem("EZBlurbs"))
  111. makeBlurbs(JSON.parse(localStorage.getItem("EZBlurbs")), false)
  112. }
  113. }
  114.  
  115. function makeBlurbs(blurbsJSON, save) {
  116. for (i=0; i< blurbsJSON.length; i++){
  117. let blurbJSON = blurbsJSON[i]
  118. symb = blurbJSON.symbol
  119. tooltip = blurbJSON.tooltip
  120. text = blurbJSON.text
  121. backColor = blurbJSON.backColor
  122. textColor = blurbJSON.textColor
  123. blurbs.push(new Blurb(symb,tooltip,text,backColor, textColor))
  124. if (save)
  125. localStorage.setItem("EZBlurbs", JSON.stringify(blurbsJSON))
  126. }
  127. }
  128.  
  129. function extractCards (mainContainer){
  130. cardsDivs = mainContainer.children[1].firstChild.firstChild.children
  131. cardsDivs = [...cardsDivs]
  132. return cardsDivs
  133. }
  134.  
  135. function start(){
  136. console.log("EZBlurbs V0.1 started.")
  137. readBlurbs()
  138. var observer = new MutationObserver(function (mutations){
  139. const mainContainer = document.querySelector('.contact-queue-card-list-all-contacts')
  140. if (mainContainer) {
  141. console.log("Observig Contacts...")
  142. observer.observe(mainContainer,{
  143. childList: true,
  144. subtree: true,
  145. })
  146. let cards = extractCards(mainContainer)
  147. cards.forEach(card => {
  148. if (!card.loaded){
  149. if (card.children.length != 0)
  150. cardsObjects.push(new Card(card))
  151. }
  152. })
  153. }
  154. })
  155. const cqcl=document.querySelector('#contact-queue-card-list')
  156. observer.observe(cqcl,{
  157. childList: true,
  158. subtree: true,
  159. })
  160. }
  161. })();