EZ-Blurb

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

目前为 2024-12-26 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name EZ-Blurb
  3. // @namespace http://tampermonkey.net/
  4. // @version V0.2
  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. this.card = card
  22. this.customerName = card.children[0].innerText.split(' ')[0]
  23. this.card.loaded = true
  24. this.blurbDiv = document.createElement("div")
  25. this.blurbDiv.style.marginTop = '-10px'
  26. this.card.appendChild(this.blurbDiv)
  27. this.addButtons()
  28. }
  29.  
  30. addButtons(){
  31. if (blurbs.length > 0)
  32. blurbs.forEach((blurb)=>{
  33. this.addButton(blurb.symb, blurb.tooltip, blurb.text, blurb.backColor, blurb.textColor)
  34. })
  35. }
  36. sendMessage(text){
  37. let chatText = document.querySelector("textarea[data-node-id='ccp-chat-composer-editor']")
  38. if (chatText)
  39. chatText.value = text
  40. alert("No chat text found:\n" + text)
  41. }
  42. addButton(symb,tooltip,text,backColor,textColor){
  43. var div = document.createElement("SPAN")
  44. div.innerText = symb
  45. div.style.display = 'inline-block'
  46. div.style.padding = '0px 5px'
  47. div.style.borderRadius = "10px"
  48. div.style.margin = "1px"
  49. div.style.backgroundColor = backColor
  50. div.style.color = textColor
  51. div.title = tooltip
  52. this.blurbDiv.appendChild(div)
  53. div.addEventListener('click',()=>{this.sendMessage(this.compileText(text))})
  54. div.addEventListener('mouseover',()=>{
  55. div.style.backgroundColor = 'red'
  56. })
  57. div.addEventListener('mouseout',()=>{
  58. div.style.backgroundColor = backColor
  59. div.style.color = textColor
  60. div.style.padding = '0px 5px'
  61. div.innerHTML = symb
  62. })
  63. }
  64. compileText(text){
  65. return text.replace("$customer$", this.customerName)
  66. }
  67. }
  68.  
  69. class Blurb{
  70. constructor(symb, tooltip, text, backColor, textColor){
  71. this.symb = symb
  72. this.tooltip = tooltip
  73. this.text = text
  74. this.backColor = backColor
  75. this.textColor = textColor
  76. }
  77. }
  78.  
  79. function readBlurbs(){
  80. console.log("Reading blurbs...")
  81. savedBlurbs = localStorage.getItem('EZBlurbs')
  82. const inputBtn = document.createElement("input")
  83. inputBtn.type= "file"
  84. inputBtn.multiple = false
  85. inputBtn.style.display = 'None'
  86. inputBtn.addEventListener('change',(event)=>{
  87. const file = event.target.files[0]
  88. if (file) {
  89. const reader = new FileReader();
  90. reader.onload = function(e) {
  91. blurbsJSON = JSON.parse(e.target.result)
  92. makeBlurbs(blurbsJSON.Blurbs, true)
  93. };
  94. reader.readAsText(file);
  95. }
  96. })
  97. const btn = document.createElement("input")
  98. btn.type = 'button'
  99. btn.className = 'awsui-button awsui-button-variant-normal awsui-hover-child-icons'
  100. btn.value= "Load EZ-Blurbs"
  101. btn.addEventListener('click',()=>{
  102. inputBtn.click()
  103. })
  104. document.getElementsByClassName("omnia-ui-tabtools")[0].appendChild(btn)
  105. if ( savedBlurbs ) {
  106. console.log ('Blurbs found:', localStorage.getItem("EZBlurbs"))
  107. makeBlurbs(JSON.parse(localStorage.getItem("EZBlurbs")), false)
  108. }
  109. }
  110.  
  111. function makeBlurbs(blurbsJSON, save) {
  112. for (i=0; i< blurbsJSON.length; i++){
  113. let blurbJSON = blurbsJSON[i]
  114. symb = blurbJSON.symbol
  115. tooltip = blurbJSON.tooltip
  116. text = blurbJSON.text
  117. backColor = blurbJSON.backColor
  118. textColor = blurbJSON.textColor
  119. blurbs.push(new Blurb(symb,tooltip,text,backColor, textColor))
  120. if (save)
  121. localStorage.setItem("EZBlurbs", JSON.stringify(blurbsJSON))
  122. }
  123. }
  124.  
  125. function extractCards (mainContainer){
  126. cardsDivs = mainContainer.children[1].firstChild.firstChild.children
  127. cardsDivs = [...cardsDivs]
  128. return cardsDivs
  129. }
  130.  
  131. function start(){
  132. console.log("EZBlurbs V0.1 started.")
  133. readBlurbs()
  134. var observer = new MutationObserver(function (mutations){
  135. const mainContainer = document.querySelector('.contact-queue-card-list-all-contacts')
  136. if (mainContainer) {
  137. console.log("Observig Contacts...")
  138. observer.observe(mainContainer,{
  139. childList: true,
  140. subtree: true,
  141. })
  142. let cards = extractCards(mainContainer)
  143. cards.forEach(card => {
  144. if (!card.loaded){
  145. if (card.children.length != 0)
  146. cardsObjects.push(new Card(card))
  147. }
  148. })
  149. }
  150. })
  151. const cqcl=document.querySelector('#contact-queue-card-list')
  152. observer.observe(cqcl,{
  153. childList: true,
  154. subtree: true,
  155. })
  156. }
  157. })();