1(() => { 2 class OwO { 3 constructor(option) { 4 const defaultOption = { 5 container: document.getElementsByClassName('OwO')[0], 6 target: document.getElementsByTagName('textarea')[0], 7 position: 'down', 8 width: '100%', 9 maxHeight: '250px', 10 api: 'https://api.anotherhome.net/OwO/OwO.json' 11 }; 12 for (let defaultKey in defaultOption) { 13 if (defaultOption.hasOwnProperty(defaultKey) && !option.hasOwnProperty(defaultKey)) { 14 option[defaultKey] = defaultOption[defaultKey]; 15 } 16 } 17 this.container = option.container; 18 this.target = option.target; 19 if (option.position === 'up') { 20 this.container.classList.add('OwO-up'); 21 } 22 23 const xhr = new XMLHttpRequest(); 24 xhr.onreadystatechange = () => { 25 if (xhr.readyState === 4) { 26 if (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) { 27 this.odata = JSON.parse(xhr.responseText); 28 this.init(option); 29 } 30 else { 31 console.log('OwO data request was unsuccessful: ' + xhr.status); 32 } 33 } 34 }; 35 xhr.open('get', option.api, true); 36 xhr.send(null); 37 } 38 39 init(option) { 40 this.area = option.target; 41 this.packages = Object.keys(this.odata); 42 43 // fill in HTML 44 let html = ` 45 <div class="OwO-body" style="width: ${option.width}"><div class="OwO-jio"></div>`; 46 47 for (let i = 0; i < this.packages.length; i++) { 48 49 html += ` 50 <ul class="OwO-items OwO-items-${this.odata[this.packages[i]].type}" style="max-height: ${parseInt(option.maxHeight) - 53 + 'px'};">`; 51var type = this.odata[this.packages[i]].type; 52 let opackage = this.odata[this.packages[i]].container; 53 for (let i = 0; i < opackage.length; i++) { 54if (type == "image") { 55 html += ` 56 <li class="OwO-item" data-id="${opackage[i].data}" title="${opackage[i].text}">${opackage[i].icon}</li>`; 57}else{ 58 html += ` 59 <li class="OwO-item" data-id="not-given" title="${opackage[i].text}">${opackage[i].icon}</li>`; 60} 61 } 62 63 html += ` 64 </ul>`; 65 } 66 67 html += ` 68 <div class="OwO-bar"> 69 <ul class="OwO-packages">`; 70 71 for (let i = 0; i < this.packages.length; i++) { 72 73 html += ` 74 <li><span>${this.packages[i]}</span></li>` 75 76 } 77 78 html += ` 79 </ul> 80 </div> 81 </div> 82 `; 83 this.container.innerHTML = html; 84 85 // bind event 86 this.logo = document.getElementsByClassName('OwO-logo')[0]; 87 this.logo.addEventListener('click', () => { 88 this.toggle(); 89 }); 90 91 this.container.getElementsByClassName('OwO-body')[0].addEventListener('click', (e)=> { 92 let target = null; 93 if (e.target.classList.contains('OwO-item')) { 94 target = e.target; 95 } 96 else if (e.target.parentNode.classList.contains('OwO-item')) { 97 target = e.target.parentNode; 98 } 99 if (target) { 100 const cursorPos = this.area.selectionEnd; 101 let areaValue = this.area.value; 102 //this.area.value = areaValue.slice(0, cursorPos) + target.innerHTML + areaValue.slice(cursorPos); 103 if (target.dataset.id == "not-given") { 104 this.area.value = areaValue.slice(0, cursorPos) + target.innerHTML + areaValue.slice(cursorPos); 105 } else { 106 this.area.value = areaValue.slice(0, cursorPos) + target.dataset.id + areaValue.slice(cursorPos); 107 } 108 this.area.focus(); 109 this.toggle(); 110 } 111 }); 112 113 this.packagesEle = this.container.getElementsByClassName('OwO-packages')[0]; 114 for (let i = 0; i < this.packagesEle.children.length; i++) { 115 ((index) =>{ 116 this.packagesEle.children[i].addEventListener('click', () => { 117 this.tab(index); 118 }); 119 })(i); 120 } 121 122 this.tab(0); 123 } 124 125 toggle() { 126 if (this.container.classList.contains('OwO-open')) { 127 this.container.classList.remove('OwO-open'); 128 } 129 else { 130 this.container.classList.add('OwO-open'); 131 } 132 } 133 134 tab(index) { 135 const itemsShow = this.container.getElementsByClassName('OwO-items-show')[0]; 136 if (itemsShow) { 137 itemsShow.classList.remove('OwO-items-show'); 138 } 139 this.container.getElementsByClassName('OwO-items')[index].classList.add('OwO-items-show'); 140 141 const packageActive = this.container.getElementsByClassName('OwO-package-active')[0]; 142 if (packageActive) { 143 packageActive.classList.remove('OwO-package-active'); 144 } 145 this.packagesEle.getElementsByTagName('li')[index].classList.add('OwO-package-active'); 146 } 147 } 148 if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { 149 module.exports = OwO; 150 } 151 else { 152 window.OwO = OwO; 153 } 154})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.