OpenVBXLibNamer

OpenVBX - Name Library Recordings

  1. // ==UserScript==
  2. // @name OpenVBXLibNamer
  3. // @namespace none.com
  4. // @description OpenVBX - Name Library Recordings
  5. // @include http://elitecallcenter.com/ivr/*
  6. // @version 1
  7. // @grant GM_xmlhttpRequest
  8. // ==/UserScript==
  9.  
  10. window.onload = function () {
  11.  
  12. (function(J,r,f){function s(a,b,d){a.addEventListener?a.addEventListener(b,d,!1):a.attachEvent("on"+b,d)}function A(a){if("keypress"==a.type){var b=String.fromCharCode(a.which);a.shiftKey||(b=b.toLowerCase());return b}return h[a.which]?h[a.which]:B[a.which]?B[a.which]:String.fromCharCode(a.which).toLowerCase()}function t(a){a=a||{};var b=!1,d;for(d in n)a[d]?b=!0:n[d]=0;b||(u=!1)}function C(a,b,d,c,e,v){var g,k,f=[],h=d.type;if(!l[a])return[];"keyup"==h&&w(a)&&(b=[a]);for(g=0;g<l[a].length;++g)if(k=
  13. l[a][g],!(!c&&k.seq&&n[k.seq]!=k.level||h!=k.action||("keypress"!=h||d.metaKey||d.ctrlKey)&&b.sort().join(",")!==k.modifiers.sort().join(","))){var m=c&&k.seq==c&&k.level==v;(!c&&k.combo==e||m)&&l[a].splice(g,1);f.push(k)}return f}function K(a){var b=[];a.shiftKey&&b.push("shift");a.altKey&&b.push("alt");a.ctrlKey&&b.push("ctrl");a.metaKey&&b.push("meta");return b}function x(a,b,d,c){m.stopCallback(b,b.target||b.srcElement,d,c)||!1!==a(b,d)||(b.preventDefault?b.preventDefault():b.returnValue=!1,b.stopPropagation?
  14. b.stopPropagation():b.cancelBubble=!0)}function y(a){"number"!==typeof a.which&&(a.which=a.keyCode);var b=A(a);b&&("keyup"==a.type&&z===b?z=!1:m.handleKey(b,K(a),a))}function w(a){return"shift"==a||"ctrl"==a||"alt"==a||"meta"==a}function L(a,b,d,c){function e(b){return function(){u=b;++n[a];clearTimeout(D);D=setTimeout(t,1E3)}}function v(b){x(d,b,a);"keyup"!==c&&(z=A(b));setTimeout(t,10)}for(var g=n[a]=0;g<b.length;++g){var f=g+1===b.length?v:e(c||E(b[g+1]).action);F(b[g],f,c,a,g)}}function E(a,b){var d,
  15. c,e,f=[];d="+"===a?["+"]:a.split("+");for(e=0;e<d.length;++e)c=d[e],G[c]&&(c=G[c]),b&&"keypress"!=b&&H[c]&&(c=H[c],f.push("shift")),w(c)&&f.push(c);d=c;e=b;if(!e){if(!p){p={};for(var g in h)95<g&&112>g||h.hasOwnProperty(g)&&(p[h[g]]=g)}e=p[d]?"keydown":"keypress"}"keypress"==e&&f.length&&(e="keydown");return{key:c,modifiers:f,action:e}}function F(a,b,d,c,e){q[a+":"+d]=b;a=a.replace(/\s+/g," ");var f=a.split(" ");1<f.length?L(a,f,b,d):(d=E(a,d),l[d.key]=l[d.key]||[],C(d.key,d.modifiers,{type:d.action},
  16. c,a,e),l[d.key][c?"unshift":"push"]({callback:b,modifiers:d.modifiers,action:d.action,seq:c,level:e,combo:a}))}var h={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",20:"capslock",27:"esc",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"ins",46:"del",91:"meta",93:"meta",224:"meta"},B={106:"*",107:"+",109:"-",110:".",111:"/",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},H={"~":"`","!":"1",
  17. "@":"2","#":"3",$:"4","%":"5","^":"6","&":"7","*":"8","(":"9",")":"0",_:"-","+":"=",":":";",'"':"'","<":",",">":".","?":"/","|":"\\"},G={option:"alt",command:"meta","return":"enter",escape:"esc",mod:/Mac|iPod|iPhone|iPad/.test(navigator.platform)?"meta":"ctrl"},p,l={},q={},n={},D,z=!1,I=!1,u=!1;for(f=1;20>f;++f)h[111+f]="f"+f;for(f=0;9>=f;++f)h[f+96]=f;s(r,"keypress",y);s(r,"keydown",y);s(r,"keyup",y);var m={bind:function(a,b,d){a=a instanceof Array?a:[a];for(var c=0;c<a.length;++c)F(a[c],b,d);return this},
  18. unbind:function(a,b){return m.bind(a,function(){},b)},trigger:function(a,b){if(q[a+":"+b])q[a+":"+b]({},a);return this},reset:function(){l={};q={};return this},stopCallback:function(a,b){return-1<(" "+b.className+" ").indexOf(" mousetrap ")?!1:"INPUT"==b.tagName||"SELECT"==b.tagName||"TEXTAREA"==b.tagName||b.isContentEditable},handleKey:function(a,b,d){var c=C(a,b,d),e;b={};var f=0,g=!1;for(e=0;e<c.length;++e)c[e].seq&&(f=Math.max(f,c[e].level));for(e=0;e<c.length;++e)c[e].seq?c[e].level==f&&(g=!0,
  19. b[c[e].seq]=1,x(c[e].callback,d,c[e].combo,c[e].seq)):g||x(c[e].callback,d,c[e].combo);c="keypress"==d.type&&I;d.type!=u||w(a)||c||t(b);I=g&&"keydown"==d.type}};J.Mousetrap=m;"function"===typeof define&&define.amd&&define(m)})(window,document);
  20.  
  21. var addEventHandler = function (elem, eventType, handler) {
  22. if (elem.addEventListener) {
  23. elem.addEventListener(eventType, handler, false);
  24. }
  25. else if (elem.attachEvent) {
  26. elem.attachEvent('on' + eventType, handler);
  27. }
  28. };
  29.  
  30. var removeOptions = function(selectbox){
  31. var i;
  32. for(i=selectbox.options.length-1;i>=0;i--)
  33. selectbox.remove(i);
  34. }
  35.  
  36. var InputValues = [];
  37. var optExists = function (val) {
  38. o = InputValues.length;
  39. while (o--) {
  40. if (InputValues[o].value === val)
  41. return true;
  42. }
  43. return false;
  44. };
  45.  
  46. var InputsLoaded = false;
  47. var checkInputs = function () {
  48. //window.alert("Checking Names");
  49. selects = document.getElementsByName('library');
  50. c = selects.length;
  51. while (c--) {
  52. options = selects[c].options;
  53. i = options.length;
  54. totalos = i;
  55. while (i--) {
  56. val = options[i].value;
  57. if(val === "") continue;
  58. text = options[i].text;
  59. if (false === optExists(val)) {
  60. (function(totalos){
  61. thisurl = "http://elitecallcenter.com/ivr/audio_names.php"+
  62. "?do=getName"+
  63. "&val=" + encodeURIComponent(val)+
  64. "&text=" + encodeURIComponent(text);
  65. //window.alert(thisurl);
  66. GM_xmlhttpRequest({
  67. method: "GET",
  68. url: thisurl,
  69. onload: function (response) {
  70. //alert(response.responseText);
  71. ix = InputValues.length;
  72. resp = JSON.parse(response.responseText);
  73. InputValues[ix] = resp;
  74. if(ix === totalos){
  75. document.getElementById('nloading').style.display= "none";
  76. selebox = document.getElementById('allRecsgm');
  77. removeOptions(selebox);
  78. opt = document.createElement("option");
  79. opt.setAttribute("value", "");
  80. opt.text = "Choose Recording";
  81. selebox.appendChild(opt);
  82. while(ix--){
  83. opt = document.createElement("option");
  84. opt.setAttribute("value", InputValues[ix].value);
  85. opt.text = InputValues[ix].name;
  86. selebox.appendChild(opt);
  87. }
  88. var InputsLoaded = true;
  89. }
  90. }
  91. });
  92. })(totalos);
  93. }
  94. }
  95. }
  96. };
  97.  
  98. var getTextByValue = function(val, text){
  99. o = InputValues.length;
  100. while (o--) {
  101. if (InputValues[o].value === val)
  102. return InputValues[o].name;
  103. }
  104. return text;
  105. };
  106. var setNames = function(){
  107. selects = document.getElementsByName('library');
  108. c = selects.length;
  109. while (c--) {
  110. options = selects[c].options;
  111. i = options.length;
  112. while (i--) {
  113. val = options[i].value;
  114. if(val === "") continue;
  115. z = options[i].text;
  116. options[i].text = getTextByValue(val, z);
  117. }
  118. }
  119. };
  120.  
  121. var Menu = false;
  122. var Open = false;
  123.  
  124. var createMenu = function () {
  125. Menu = document.createElement('div');
  126. Menu.setAttribute('style', 'position:fixed; z-index:99999; display:block; top:0; left:-250px; width:250px; height:100vh; margin:0; padding:0; background:#86C8E9;border-top-right-radius: 20px;border-bottom-right-radius: 20px;');
  127. bodies = document.getElementsByTagName('body');
  128. body = bodies[0];
  129. body.appendChild(Menu);
  130. mStr = '<div style="padding:1em;"><br><h2>OpenVBXLibNamer</h2><br><br>\
  131. <hr><b><big>SELECT RECORDING TO EDIT NAME</big><span id="nloading" style="color:red;"><br>(Loading, wait...)</span></b><br>\
  132. <select id="allRecsgm" name="library"></select>\
  133. <div id="apbox" style="display:none;"><b>Recording:</b><br><audio id="applayer" style="width:90%; display:block; margin:0 auto;" src="http://elitecallcenter.com/ivr/recs/REba7316c2f3ed6176ba636c1f1036737d.mp3" controls preload="auto" autobuffer></audio></div>\
  134. <div id="namebox" style="display:none"><b>Name:</b><br>\
  135. <input style="width:90%; display:block; margin:0 auto;" type="text" id="selectedname">\
  136. <button style="width:95%; display:block; margin:0 auto;" id="savename">Save Name</button></div>\
  137. <hr><br><b>or...<br><br><hr><br><big>CLICK TO SHOW NAMES</big></b><br><button style="width:95%; display:block; margin:0 auto;" id="setnames">Load Names</button><hr>\
  138. </div>';
  139. Menu.innerHTML = mStr;
  140. addEventHandler(document.getElementById('allRecsgm'), 'change', function(e){
  141. op = document.getElementById('allRecsgm');
  142. if(op.options[op.selectedIndex].value !== ""){
  143. document.getElementById('namebox').style.display="block";
  144. document.getElementById('selectedname').value = op.options[op.selectedIndex].text;
  145. document.getElementById('apbox').style.display="block";
  146. document.getElementById('applayer').setAttribute("src",op.options[op.selectedIndex].value);
  147. }else{
  148. document.getElementById('apbox').style.display="none";
  149. document.getElementById('namebox').style.display="none";
  150. }
  151. });
  152. addEventHandler(document.getElementById('setnames'), 'click', function(e){
  153. setNames();
  154. });
  155. addEventHandler(document.getElementById('savename'), 'click', function(e){
  156. op = document.getElementById('allRecsgm');
  157. SELINVAL = op.options[op.selectedIndex].value;
  158. SELIN = op.selectedIndex;
  159. NEWVAL = document.getElementById('selectedname').value;
  160. (function(SELIN, SELINVAL, NEWVAL){
  161. GM_xmlhttpRequest({
  162. method: "GET",
  163. url: "http://elitecallcenter.com/ivr/audio_names.php"+
  164. "?do=saveName"+
  165. "&val=" + encodeURIComponent(SELINVAL) +
  166. "&text=" + encodeURIComponent(NEWVAL),
  167. onload: function (response) {
  168. ix = InputValues.length;
  169. resp = JSON.parse(response.responseText);
  170. op = document.getElementById('allRecsgm');
  171. op.options[SELIN].text = NEWVAL;
  172. }
  173. });
  174. })(SELIN, SELINVAL, NEWVAL);
  175. });
  176. };
  177.  
  178. var openOpts = function () {
  179. if (Menu === false)
  180. createMenu();
  181. var left = 250;
  182. var openMenuInterval = setInterval(function () {
  183. left = left - 2;
  184. Menu.style.left = "-" + left + "px";
  185. if (left === 0) {
  186. clearInterval(openMenuInterval);
  187. Open = true;
  188. }
  189. }, 1);
  190. };
  191.  
  192. var closeOpts = function () {
  193. if (Menu === false)
  194. createMenu();
  195. var left = 0;
  196. var closeMenuInterval = setInterval(function () {
  197. left = left + 2;
  198. Menu.style.left = "-" + left + "px";
  199. if (left === 250) {
  200. clearInterval(closeMenuInterval);
  201. Open = false;
  202. }
  203. }, 1);
  204. };
  205.  
  206.  
  207.  
  208. Mousetrap.bind('shift+n', function (e) {
  209. if(InputsLoaded === false)
  210. checkInputs();
  211. else
  212. window.alert('loaded already');
  213. if (!Open)
  214. openOpts();
  215. else
  216. closeOpts();
  217. });
  218. };