Compare commits
	
		
			16 Commits
		
	
	
		
			v9.0.2
			...
			4a81cbf321
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 4a81cbf321 | |||
| b1d846de32 | |||
| 748a8740eb | |||
| 248fbd5f0f | |||
| 20e011bb55 | |||
| bbb4a910a0 | |||
| 1cbde09ac6 | |||
| d107b1a49f | |||
| 505bab6d34 | |||
| e1459856c2 | |||
| 72e7a95904 | |||
| 69e5857963 | |||
| 9a0c476bc5 | |||
| e563279faf | |||
| 856181f530 | |||
| ae0c125a50 | 
							
								
								
									
										11148
									
								
								3CX_TAPI.user.js
									
									
									
									
									
								
							
							
						
						
									
										11148
									
								
								3CX_TAPI.user.js
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -9,8 +9,8 @@ module.exports = { | |||||||
|   source: pkg.repository.url, |   source: pkg.repository.url, | ||||||
|   downloadURL: 'https://source.cp-austria.at/git/CPATRD/3cx_tapi/raw/branch/master/3CX_TAPI.user.js', |   downloadURL: 'https://source.cp-austria.at/git/CPATRD/3cx_tapi/raw/branch/master/3CX_TAPI.user.js', | ||||||
|   match: [ |   match: [ | ||||||
|     'https://192.168.0.154:5001/webclient*', |     'https://192.168.0.154:5001/*', | ||||||
|     'https://cpsolution.my3cx.at:5001/webclient*' |     'https://cpsolution.my3cx.at:5001/*' | ||||||
|   ], |   ], | ||||||
|   require: [ |   require: [ | ||||||
|     'https://cdn.jsdelivr.net/gh/CoeJoder/waitForKeyElements.js@v1.2/waitForKeyElements.js', |     'https://cdn.jsdelivr.net/gh/CoeJoder/waitForKeyElements.js@v1.2/waitForKeyElements.js', | ||||||
|   | |||||||
| @@ -15,8 +15,6 @@ const webpackConfig = { | |||||||
|   }, |   }, | ||||||
|   externals: { |   externals: { | ||||||
|     jquery: '$', |     jquery: '$', | ||||||
|     axios: 'axios', |  | ||||||
|     'axios-userscript-adapter': 'axiosGmxhrAdapter' |  | ||||||
|   }, |   }, | ||||||
|   module: { |   module: { | ||||||
|     rules: [ |     rules: [ | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| const path = require('path') | const path = require('path') | ||||||
| const { merge } = require('webpack-merge') | const { merge } = require('webpack-merge') | ||||||
| const LiveReloadPlugin = require('webpack-livereload-plugin') | const LiveReloadPlugin = require('webpack-livereload-plugin') | ||||||
| const UserScriptMetaDataPlugin = require('userscript-metadata-webpack-plugin') | const { UserScriptMetaDataPlugin } = require('userscript-metadata-webpack-plugin') | ||||||
|  |  | ||||||
| const metadata = require('./metadata.cjs') | const metadata = require('./metadata.cjs') | ||||||
| const webpackConfig = require('./webpack.config.base.cjs') | const webpackConfig = require('./webpack.config.base.cjs') | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| const { merge } = require('webpack-merge') | const { merge } = require('webpack-merge') | ||||||
| const UserScriptMetaDataPlugin = require('userscript-metadata-webpack-plugin') | const { UserScriptMetaDataPlugin } = require('userscript-metadata-webpack-plugin') | ||||||
|  |  | ||||||
| const metadata = require('./metadata.cjs') | const metadata = require('./metadata.cjs') | ||||||
| const webpackConfig = require('./webpack.config.base.cjs') | const webpackConfig = require('./webpack.config.base.cjs') | ||||||
|   | |||||||
							
								
								
									
										12459
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										12459
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										52
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										52
									
								
								package.json
									
									
									
									
									
								
							| @@ -1,7 +1,7 @@ | |||||||
| { | { | ||||||
|   "name": "3cx-tapi", |   "name": "3cx-tapi", | ||||||
|   "description": "3CX CP Tapi and Projectmanager integration", |   "description": "3CX CP Tapi and Projectmanager integration", | ||||||
|   "version": "9.0.2", |   "version": "9.2.2", | ||||||
|   "author": { |   "author": { | ||||||
|     "name": "Daniel Triendl", |     "name": "Daniel Triendl", | ||||||
|     "email": "d.triendl@cp-solutions.at" |     "email": "d.triendl@cp-solutions.at" | ||||||
| @@ -24,34 +24,32 @@ | |||||||
|   }, |   }, | ||||||
|   "private": true, |   "private": true, | ||||||
|   "dependencies": { |   "dependencies": { | ||||||
|     "axios": "0.21.1", |     "chrono-node": "^2.7.7", | ||||||
|     "axios-userscript-adapter": "0.1.4", |     "@trim21/gm-fetch": "^0.1.16" | ||||||
|     "chrono-node": "^2.3.0" |  | ||||||
|   }, |   }, | ||||||
|   "devDependencies": { |   "devDependencies": { | ||||||
|     "@babel/core": "7.14.6", |     "@types/greasemonkey": "^4.0.7", | ||||||
|     "@babel/preset-env": "7.14.5", |     "@babel/core": "^7.25.8", | ||||||
|     "@typescript-eslint/eslint-plugin": "4.27.0", |     "@babel/preset-env": "^7.25.8", | ||||||
|     "@typescript-eslint/parser": "4.27.0", |     "@typescript-eslint/eslint-plugin": "^8.8.1", | ||||||
|     "babel-loader": "8.2.2", |     "@typescript-eslint/parser": "^8.8.1", | ||||||
|     "browserslist": "4.16.6", |     "babel-loader": "^9.2.1", | ||||||
|     "css-loader": "5.2.6", |     "browserslist": "^4.21.9", | ||||||
|     "eslint": "7.29.0", |     "css-loader": "^7.1.2", | ||||||
|     "eslint-config-standard": "16.0.3", |     "eslint": "^9.12.0", | ||||||
|     "eslint-plugin-import": "2.23.4", |     "eslint-plugin-import": "^2.31.0", | ||||||
|     "eslint-plugin-node": "11.1.0", |     "eslint-plugin-node": "11.1.0", | ||||||
|     "eslint-plugin-promise": "5.1.0", |     "eslint-plugin-promise": "^7.1.0S", | ||||||
|     "eslint-plugin-standard": "4.1.0", |     "less": "4.2.0", | ||||||
|     "less": "4.1.1", |     "less-loader": "^12.2.0", | ||||||
|     "less-loader": "10.0.0", |     "style-loader": "^4.0.0", | ||||||
|     "style-loader": "2.0.0", |     "ts-loader": "^9.5.1", | ||||||
|     "ts-loader": "9.2.3", |     "typescript": "^5.6.3", | ||||||
|     "typescript": "4.3.4", |     "userscript-metadata-webpack-plugin": "^0.4.0", | ||||||
|     "userscript-metadata-webpack-plugin": "0.1.0", |     "webpack": "^5.95.0", | ||||||
|     "webpack": "5.39.1", |     "webpack-bundle-analyzer": "^4.10.2", | ||||||
|     "webpack-bundle-analyzer": "4.4.2", |     "webpack-cli": "^5.1.4", | ||||||
|     "webpack-cli": "4.7.2", |     "webpack-livereload-plugin": "3.0.2", | ||||||
|     "webpack-livereload-plugin": "3.0.1", |     "webpack-merge": "^6.0.1" | ||||||
|     "webpack-merge": "5.8.0" |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| import * as chrono from 'chrono-node' | import * as chrono from 'chrono-node' | ||||||
| import { TapiContact } from './tapi-contact' | import { TapiContact } from './tapi-contact' | ||||||
| import { axios, extractNumber } from './utils' | import { extractNumber } from './utils' | ||||||
|  | import GM_fetch from '@trim21/gm-fetch' | ||||||
|  |  | ||||||
| export class CallHistory { | export class CallHistory { | ||||||
|   private callerIds: { [number: string]: TapiContact } = {} |   private callerIds: { [number: string]: TapiContact } = {} | ||||||
| @@ -22,9 +23,10 @@ export class CallHistory { | |||||||
|       date = dateParts.groups.date |       date = dateParts.groups.date | ||||||
|       duration = dateParts.groups.duration |       duration = dateParts.groups.duration | ||||||
|     } |     } | ||||||
|     var parsedDate = chrono.de.parseDate(date) |     var parsedDate = chrono.parseDate(date) | ||||||
|     if (!parsedDate) { |     var parsedDateDe = chrono.de.parseDate(date) | ||||||
|       parsedDate = chrono.parseDate(date) |     if (parsedDateDe) { | ||||||
|  |       parsedDate = parsedDateDe | ||||||
|     } |     } | ||||||
|     if (!parsedDate) { |     if (!parsedDate) { | ||||||
|       return |       return | ||||||
| @@ -84,10 +86,10 @@ export class CallHistory { | |||||||
|     if (this.callerIds[number] !== undefined) { |     if (this.callerIds[number] !== undefined) { | ||||||
|       this.updateCallHistoryEntry(element, this.callerIds[number]) |       this.updateCallHistoryEntry(element, this.callerIds[number]) | ||||||
|     } else { |     } else { | ||||||
|       var response = await axios.get<TapiContact>('http://cpatapi.cpsrvweb2016.cp-austria.at/callerid/' + encodeURIComponent(number)) |       var response = await GM_fetch('http://cpatapi.cpsrvweb2016.cp-austria.at/callerid/' + encodeURIComponent(number)) | ||||||
|       var callerId: TapiContact = { tD_NAME: '' } |       var callerId: TapiContact = { tD_NAME: '' } | ||||||
|       if (response.status === 200) { |       if (response.status === 200) { | ||||||
|         callerId = response.data |         callerId = await response.json() as TapiContact | ||||||
|       } |       } | ||||||
|       console.log('TAPI call histroy callerid response', number, response, callerId) |       console.log('TAPI call histroy callerid response', number, response, callerId) | ||||||
|       this.callerIds[number] = callerId |       this.callerIds[number] = callerId | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
|  | import GM_fetch from '@trim21/gm-fetch' | ||||||
| import { TapiContact } from './tapi-contact' | import { TapiContact } from './tapi-contact' | ||||||
| import { axios, extractNumber } from './utils' | import { extractNumber } from './utils' | ||||||
|  |  | ||||||
| export class CallNotification { | export class CallNotification { | ||||||
|   public async showCallNotification (element: HTMLElement) { |   public async showCallNotification (element: HTMLElement) { | ||||||
| @@ -13,19 +14,19 @@ export class CallNotification { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     console.log('TAPI searching callerid for', number) |     console.log('TAPI searching callerid for', number) | ||||||
|     var response = await axios.get<TapiContact>('http://cpatapi.cpsrvweb2016.cp-austria.at/callerid/' + encodeURIComponent(number)) |     var response = await GM_fetch('http://cpatapi.cpsrvweb2016.cp-austria.at/callerid/' + encodeURIComponent(number)) | ||||||
|     console.log('TAPI callerid response', response) |     console.log('TAPI callerid response', response) | ||||||
|     var notification = { |     var notification = { | ||||||
|       text: number |       text: number | ||||||
|     } |     } | ||||||
|     if (response.status === 200) { |     if (response.status === 200) { | ||||||
|       var callerId = response.data |       var callerId = await response.json() as TapiContact | ||||||
|       if (callerId) { |       if (callerId) { | ||||||
|         notification.text = callerId.tD_NAME + '\r\n' + number + ' (' + callerId.tD_MEDIUM + ')' |         notification.text = callerId.tD_NAME + '\r\n' + number + ' (' + callerId.tD_MEDIUM + ')' | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // eslint-disable-next-line no-undef |     // eslint-disable-next-line no-undef | ||||||
|     GM.notification(notification) |     GM.notification(notification.text, 'TAPI Anruf') | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										3
									
								
								src/decs.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								src/decs.d.ts
									
									
									
									
										vendored
									
									
								
							| @@ -1,3 +0,0 @@ | |||||||
| declare module 'axios-userscript-adapter' |  | ||||||
|  |  | ||||||
| declare const GM: any |  | ||||||
| @@ -9,7 +9,7 @@ console.log('script start') | |||||||
|  |  | ||||||
| const search = new Search() | const search = new Search() | ||||||
| // eslint-disable-next-line no-undef | // eslint-disable-next-line no-undef | ||||||
| waitForKeyElements('ongoing-call-button', (element) => { search.createSearchWindow(element) }, true) | waitForKeyElements('ongoing-call-button', (element) => { search.createSearchWindow(element) }, false) | ||||||
|  |  | ||||||
| const callNotification = new CallNotification() | const callNotification = new CallNotification() | ||||||
| // eslint-disable-next-line no-undef | // eslint-disable-next-line no-undef | ||||||
|   | |||||||
| @@ -1,9 +1,42 @@ | |||||||
| .tapi-search-result { | .tapi-search-autocomplete { | ||||||
|  |     /*the container must be positioned relative:*/ | ||||||
|  |     position: relative; | ||||||
|  |     display: inline-block; | ||||||
|  |     margin-right: 20px; | ||||||
|  |   } | ||||||
|  | .tapi-search-autocomplete input { | ||||||
|  |     border: 1px solid transparent; | ||||||
|  |     background-color: #f1f1f1; | ||||||
|  |     /*padding: 10px;*/ | ||||||
|  |     /*font-size: 16px;*/ | ||||||
|  | } | ||||||
|  | .tapi-search-autocomplete input[type=text] { | ||||||
|  |     background-color: #f1f1f1; | ||||||
|  |     width: 100%; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .tapi-search-autocomplete-items { | ||||||
|  |     position: absolute; | ||||||
|  |     border: 1px solid #d4d4d4; | ||||||
|  |     border-bottom: none; | ||||||
|  |     border-top: none; | ||||||
|  |     z-index: 99; | ||||||
|  |     /*position the autocomplete items to be the same width as the container:*/ | ||||||
|  |     top: 100%; | ||||||
|  |     left: 0; | ||||||
|  |     right: 0; | ||||||
|  | } | ||||||
|  | .tapi-search-autocomplete-items div { | ||||||
|  |     padding: 10px; | ||||||
|  |     cursor: pointer; | ||||||
|  |     background-color: #fff; | ||||||
|  |     border-bottom: 1px solid #d4d4d4; | ||||||
|     color: #000; |     color: #000; | ||||||
|     padding: 5px; |  | ||||||
| } | } | ||||||
|  | .tapi-search-autocomplete-items div p { | ||||||
| .tapi-search-result:hover, .tapi-search-result-selected { |     margin: 0; | ||||||
|     background-color: #E7E6E6; | } | ||||||
|  | .tapi-search-autocomplete-items div:hover, .tapi-search-autocomplete-active { | ||||||
|  |     /*when hovering an item:*/ | ||||||
|  |     background-color: #E7E6E6 !important; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,7 +1,8 @@ | |||||||
| import './search.css' | import './search.css' | ||||||
| import { TapiContact } from './tapi-contact' | import { TapiContact } from './tapi-contact' | ||||||
| import { debounce } from './debounce' | import { debounce } from './debounce' | ||||||
| import { axios, fireChangeEvents } from './utils' | import { fireChangeEvents } from './utils' | ||||||
|  | import GM_fetch from '@trim21/gm-fetch' | ||||||
|  |  | ||||||
| export class Search { | export class Search { | ||||||
|   private currentSearchText = '' |   private currentSearchText = '' | ||||||
| @@ -10,13 +11,10 @@ export class Search { | |||||||
|     console.log('Create TAPI Search') |     console.log('Create TAPI Search') | ||||||
|  |  | ||||||
|     var form = document.createElement('form') |     var form = document.createElement('form') | ||||||
|     form.style.width = '200px' |  | ||||||
|     form.style.float = 'right' |  | ||||||
|     form.style.marginRight = '20px' |  | ||||||
|     form.onsubmit = () => { |     form.onsubmit = () => { | ||||||
|       var items = document.getElementsByClassName('tapi-search-result-selected') |       var items = document.getElementsByClassName('tapi-search-autocomplete-active') | ||||||
|       if (items.length === 0) { |       if (items.length === 0) { | ||||||
|         items = document.getElementsByClassName('tapi-search-result') |         items = document.getElementsByClassName('tapi-search-autocomplete-item') | ||||||
|       } |       } | ||||||
|       if (items.length > 0) { |       if (items.length > 0) { | ||||||
|         this.dial((<HTMLElement>items[0]).dataset.tapiNumber) |         this.dial((<HTMLElement>items[0]).dataset.tapiNumber) | ||||||
| @@ -28,23 +26,14 @@ export class Search { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     var searchBox = document.createElement('div') |     var searchBox = document.createElement('div') | ||||||
|     searchBox.classList.add('contact-search-box') |     searchBox.classList.add('tapi-search-autocomplete') | ||||||
|  |     searchBox.style.width = '200px' | ||||||
|     searchBox.id = 'tapiSearchBox' |     searchBox.id = 'tapiSearchBox' | ||||||
|     form.appendChild(searchBox) |     form.appendChild(searchBox) | ||||||
|  |  | ||||||
|     var searchWrapper = document.createElement('div') |  | ||||||
|     searchWrapper.classList.add('search-input-wrapper') |  | ||||||
|     searchWrapper.style.position = 'relative' |  | ||||||
|     searchBox.appendChild(searchWrapper) |  | ||||||
|  |  | ||||||
|     var search = document.createElement('input') |     var search = document.createElement('input') | ||||||
|     search.id = 'tapiSearchInput' |     search.id = 'tapiSearchInput' | ||||||
|     search.autocomplete = 'off' |     search.autocomplete = 'off' | ||||||
|     search.classList.add('padder') |  | ||||||
|     search.classList.add('rounded') |  | ||||||
|     search.classList.add('bg-light') |  | ||||||
|     search.classList.add('no-border') |  | ||||||
|     search.classList.add('contact-search-box') |  | ||||||
|     search.placeholder = 'TAPI Suche' |     search.placeholder = 'TAPI Suche' | ||||||
|     search.onfocus = () => { this.doSearch() } |     search.onfocus = () => { this.doSearch() } | ||||||
|     search.onkeydown = (ev) => { this.doSearchKeyDown(ev) } |     search.onkeydown = (ev) => { this.doSearchKeyDown(ev) } | ||||||
| @@ -53,22 +42,15 @@ export class Search { | |||||||
|       setTimeout(() => { |       setTimeout(() => { | ||||||
|         console.log('TAPI clear search results') |         console.log('TAPI clear search results') | ||||||
|         this.removeSearchResults() |         this.removeSearchResults() | ||||||
|       }, 500) |       }, 250) | ||||||
|     } |     } | ||||||
|     searchWrapper.appendChild(search) |     searchBox.appendChild(search) | ||||||
|  |  | ||||||
|     var icon = document.createElement('span') |  | ||||||
|     icon.classList.add('fa') |  | ||||||
|     icon.classList.add('fa-search') |  | ||||||
|     icon.classList.add('form-control-feedback') |  | ||||||
|     icon.style.color = 'grey' |  | ||||||
|     searchWrapper.appendChild(icon) |  | ||||||
|  |  | ||||||
|     element.parentElement.insertBefore(form, element) |     element.parentElement.insertBefore(form, element) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   private removeSearchResults () { |   private removeSearchResults () { | ||||||
|     var resultList = document.getElementById('tapiResults') |     var resultList = document.getElementById('tapi-search-autocomplete-list') | ||||||
|     if (resultList) { |     if (resultList) { | ||||||
|       resultList.parentNode.removeChild(resultList) |       resultList.parentNode.removeChild(resultList) | ||||||
|     } |     } | ||||||
| @@ -77,12 +59,12 @@ export class Search { | |||||||
|  |  | ||||||
|   private doSearchKeyDown (ev: KeyboardEvent) { |   private doSearchKeyDown (ev: KeyboardEvent) { | ||||||
|     if (ev.key === 'ArrowUp') { |     if (ev.key === 'ArrowUp') { | ||||||
|       let items = document.getElementsByClassName('tapi-search-result-selected') |       let items = document.getElementsByClassName('tapi-search-autocomplete-active') | ||||||
|       if (items.length > 0) { |       if (items.length > 0) { | ||||||
|         var prev = <Element>items[0].previousSibling |         var prev = <Element>items[0].previousSibling | ||||||
|       } |       } | ||||||
|       if (!prev) { |       if (!prev) { | ||||||
|         items = document.getElementsByClassName('tapi-search-result') |         items = document.getElementsByClassName('tapi-search-autocomplete-item') | ||||||
|         if (items.length > 0) { |         if (items.length > 0) { | ||||||
|           prev = items[items.length - 1] |           prev = items[items.length - 1] | ||||||
|         } |         } | ||||||
| @@ -92,12 +74,12 @@ export class Search { | |||||||
|         prev.scrollIntoView(true) |         prev.scrollIntoView(true) | ||||||
|       } |       } | ||||||
|     } else if (ev.key === 'ArrowDown') { |     } else if (ev.key === 'ArrowDown') { | ||||||
|       let items = document.getElementsByClassName('tapi-search-result-selected') |       let items = document.getElementsByClassName('tapi-search-autocomplete-active') | ||||||
|       if (items.length > 0) { |       if (items.length > 0) { | ||||||
|         var next = <Element>items[0].nextSibling |         var next = <Element>items[0].nextSibling | ||||||
|       } |       } | ||||||
|       if (!next) { |       if (!next) { | ||||||
|         items = document.getElementsByClassName('tapi-search-result') |         items = document.getElementsByClassName('tapi-search-autocomplete-item') | ||||||
|         if (items.length > 0) { |         if (items.length > 0) { | ||||||
|           next = items[0] |           next = items[0] | ||||||
|         } |         } | ||||||
| @@ -121,52 +103,39 @@ export class Search { | |||||||
|       return |       return | ||||||
|     } |     } | ||||||
|     console.log('Searching TAPI') |     console.log('Searching TAPI') | ||||||
|     var response = await axios.get<TapiContact[]>('http://cpatapi.cpsrvweb2016.cp-austria.at/search?query=' + encodeURIComponent(searchText)) |     var response = await GM_fetch('http://cpatapi.cpsrvweb2016.cp-austria.at/search?query=' + encodeURIComponent(searchText)) | ||||||
|     console.log('TAPI Search response', response) |     console.log('TAPI Search response', response) | ||||||
|     var contacts = response.data |     var contacts = await response.json() as TapiContact[] | ||||||
|     console.log('TAPI Contacts', contacts) |     console.log('TAPI Contacts', contacts) | ||||||
|     this.removeSearchResults() |     this.removeSearchResults() | ||||||
|     this.currentSearchText = searchText |     this.currentSearchText = searchText | ||||||
|  |  | ||||||
|     var resultList = document.createElement('ul') |     var results = document.createElement('div'); | ||||||
|     resultList.id = 'tapiResults' |     results.setAttribute('id', 'tapi-search-autocomplete-list') | ||||||
|     resultList.classList.add('search-nav-absolute') |     results.setAttribute('class', 'tapi-search-autocomplete-items') | ||||||
|     resultList.classList.add('search-nav-ul') |     document.getElementById('tapiSearchBox').appendChild(results) | ||||||
|     document.getElementById('tapiSearchBox').appendChild(resultList) |  | ||||||
|  |  | ||||||
|     resultList.innerHTML = '' |  | ||||||
|     contacts.forEach(contact => { |     contacts.forEach(contact => { | ||||||
|       var li = document.createElement('li') |       var item = document.createElement('div'); | ||||||
|       li.classList.add('tapi-search-result') |       item.setAttribute('class', 'tapi-search-autocomplete-item') | ||||||
|       li.classList.add('pointer') |       var p = document.createElement('p') | ||||||
|       li.onmouseover = () => { this.selectResult(li) } |       p.innerHTML = contact.tD_NAME + '<br>' + contact.tD_MEDIUM + ': ' + contact.tD_NUMBER_TAPI | ||||||
|       li.dataset.tapiNumber = contact.tD_NUMBER_TAPI |       item.appendChild(p) | ||||||
|       li.onclick = () => { this.dial(contact.tD_NUMBER_TAPI) } |       item.onclick = () => { this.dial(contact.tD_NUMBER_TAPI) } | ||||||
|       li.style.listStyle = 'outside none none' // display: flex; align-items: center; |       item.onmouseover = () => { this.selectResult(item) } | ||||||
|  |       item.dataset.tapiNumber = contact.tD_NUMBER_TAPI | ||||||
|       var resultText = document.createElement('div') |       results.appendChild(item); | ||||||
|       resultText.classList.add('search-result-txt') |  | ||||||
|       li.appendChild(resultText) |  | ||||||
|  |  | ||||||
|       var line1 = document.createElement('div') |  | ||||||
|       line1.appendChild(document.createTextNode(contact.tD_NAME)) |  | ||||||
|       resultText.appendChild(line1) |  | ||||||
|  |  | ||||||
|       var line2 = document.createElement('div') |  | ||||||
|       line2.appendChild(document.createTextNode(contact.tD_MEDIUM + ': ' + contact.tD_NUMBER_TAPI)) |  | ||||||
|       resultText.appendChild(line2) |  | ||||||
|  |  | ||||||
|       resultList.appendChild(li) |  | ||||||
|     }) |     }) | ||||||
|   }, 200) |   }, 200) | ||||||
|  |  | ||||||
|   private selectResult (resultLi: Element) { |   private selectResult (item: Element) { | ||||||
|     var items = document.getElementsByClassName('tapi-search-result') |     console.log('Select item', item) | ||||||
|     for (var item of items) { |     var items = document.getElementsByClassName('tapi-search-autocomplete-active') | ||||||
|       item.classList.remove('tapi-search-result-selected') |     for (var i of items) { | ||||||
|  |       i.classList.remove('tapi-search-autocomplete-active') | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     resultLi.classList.add('tapi-search-result-selected') |     item.classList.add('tapi-search-autocomplete-active') | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   private dial (number: string) { |   private dial (number: string) { | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| import './status.css'; | import './status.css'; | ||||||
| import { axios } from './utils'; |  | ||||||
| import { ZcStatus } from './zc-status'; | import { ZcStatus } from './zc-status'; | ||||||
|  | import GM_fetch from "@trim21/gm-fetch"; | ||||||
|  |  | ||||||
| declare function waitForKeyElements(selectorOrFunction: any, callback: any, waitOnce: boolean): any; | declare function waitForKeyElements(selectorOrFunction: any, callback: any, waitOnce: boolean): any; | ||||||
|  |  | ||||||
| @@ -26,16 +26,18 @@ export class Status { | |||||||
|   private async checkStatus() { |   private async checkStatus() { | ||||||
|     if (this._enabled) { |     if (this._enabled) { | ||||||
|       try { |       try { | ||||||
|         var response = await axios.get<ZcStatus>('http://cpatapi.cpsrvweb2016.cp-austria.at/availability/' + encodeURIComponent(this._user)); |         var response = await GM_fetch('http://cpatapi.cpsrvweb2016.cp-austria.at/availability/' + encodeURIComponent(this._user)); | ||||||
|  |  | ||||||
|         if (response.status == 200) { |         if (response.status == 200) { | ||||||
|           var status = response.data; |           var status = await response.json() as ZcStatus; | ||||||
|           if (this._currentStatus !== status.loggedIn) { |           if (this._currentStatus !== status.loggedIn) { | ||||||
|             this._currentStatus = status.loggedIn; |             this._currentStatus = status.loggedIn; | ||||||
|             console.log('New status, loggedIn', this._currentStatus); |             console.log('New status, loggedIn', this._currentStatus); | ||||||
|             (document.getElementsByTagName("wcavatar")[0] as HTMLAnchorElement).click(); |             var accMenu = document.getElementsByTagName("wc-account-menu")[0]; | ||||||
|  |             var avatar = accMenu.getElementsByTagName("app-avatar")[0] as HTMLAnchorElement; | ||||||
|  |             avatar.click(); | ||||||
|             setTimeout(() => { |             setTimeout(() => { | ||||||
|               var statusId = this._currentStatus ? this._statusOn : this._statusOff; |               var statusId = this._currentStatus ? this._statusOn : this._statusOff; | ||||||
|  |               console.log('Clicking status', statusId); | ||||||
|               (document.getElementById(statusId) as HTMLSpanElement).click(); |               (document.getElementById(statusId) as HTMLSpanElement).click(); | ||||||
|             }, 1000); |             }, 1000); | ||||||
|           } |           } | ||||||
| @@ -70,7 +72,7 @@ export class Status { | |||||||
|     '<div role="document" class="modal-dialog">' + |     '<div role="document" class="modal-dialog">' + | ||||||
|     '  <div class="modal-content">' + |     '  <div class="modal-content">' + | ||||||
|     '    <div class="modal-header">' + |     '    <div class="modal-header">' + | ||||||
|     '      <h4 class="modal-title float-left">ZeitConsens Status</h4><button id="zc-btnClose" type="button" aria-label="Close" class="close float-right"><span aria-hidden="true">×</span></button>' + |     '      <h4 class="modal-title">ZeitConsens Status</h4><button id="zc-btnClose" type="button" aria-label="Close" class="btn-close"  data-qa="modal-cross"></button>' + | ||||||
|     '    </div>' + |     '    </div>' + | ||||||
|     '    <div class="modal-body">' + |     '    <div class="modal-body">' + | ||||||
|     '      <div class="form-group">' + |     '      <div class="form-group">' + | ||||||
| @@ -96,13 +98,13 @@ export class Status { | |||||||
|     '        <label class="i-checks" for="tapi-zc-enabled">' + |     '        <label class="i-checks" for="tapi-zc-enabled">' + | ||||||
|     '          <input type="checkbox" id="tapi-zc-enabled">' + |     '          <input type="checkbox" id="tapi-zc-enabled">' + | ||||||
|     '          <i></i><span>Enabled</span>' + |     '          <i></i><span>Enabled</span>' + | ||||||
|     '      </label>' |     '      </label>' + | ||||||
|     '      </div>'; |     '      </div>' + | ||||||
|     '    </div>' + |  | ||||||
|     '    <div class="modal-footer">' + |  | ||||||
|     '      <button id="zc-btnOk" type="button" class="btn btn-primary">OK </button>' + |  | ||||||
|     '      <button id="zc-btnCancel" type="button" class="btn btn-light">Cancel </button>' + |  | ||||||
|     '    </div>' + |     '    </div>' + | ||||||
|  |     //'    <div class="modal-footer">' + | ||||||
|  |     //'      <button id="zc-btnOk" type="button" class="btn btn-primary" data-qa="modal-ok">OK </button>' + | ||||||
|  |     //'      <button id="zc-btnCancel" type="button" class="btn btn-border" data-qa="modal-close">Cancel </button>' + | ||||||
|  |     //'    </div>' + | ||||||
|     '  </div>' + |     '  </div>' + | ||||||
|     '</div>'; |     '</div>'; | ||||||
|     var modal = document.createElement('modal-container'); |     var modal = document.createElement('modal-container'); | ||||||
| @@ -110,7 +112,7 @@ export class Status { | |||||||
|     modal.classList.add('modal'); |     modal.classList.add('modal'); | ||||||
|     modal.classList.add('fade'); |     modal.classList.add('fade'); | ||||||
|     modal.innerHTML = html; |     modal.innerHTML = html; | ||||||
|     var body = document.getElementsByTagName('body')[0].appendChild(modal); |     document.getElementsByTagName('body')[0].appendChild(modal); | ||||||
|  |  | ||||||
|     var btnClose = document.getElementById('zc-btnClose'); |     var btnClose = document.getElementById('zc-btnClose'); | ||||||
|     btnClose.onclick = () => { |     btnClose.onclick = () => { | ||||||
|   | |||||||
							
								
								
									
										20
									
								
								src/utils.ts
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								src/utils.ts
									
									
									
									
									
								
							| @@ -1,23 +1,3 @@ | |||||||
| /** |  | ||||||
|  * @typedef {Object} AxiosResponse |  | ||||||
|  * @property {Object} data |  | ||||||
|  * @property {Object} headers |  | ||||||
|  * @property {Object} config |  | ||||||
|  * @property {Object} request |  | ||||||
|  * @property {number} code |  | ||||||
|  * @property {string} statusText |  | ||||||
|  */ |  | ||||||
| /** |  | ||||||
|  * @typedef {Object} AxiosError |  | ||||||
|  * @property {AxiosResponse} response |  | ||||||
|  */ |  | ||||||
| import axios from 'axios' |  | ||||||
| import adapter from 'axios-userscript-adapter' |  | ||||||
|  |  | ||||||
| axios.defaults.adapter = adapter |  | ||||||
|  |  | ||||||
| export { axios } |  | ||||||
|  |  | ||||||
| export function extractNumber (s: string) { | export function extractNumber (s: string) { | ||||||
|   var match = /(\+?[0-9]{4,})/.exec(s) |   var match = /(\+?[0-9]{4,})/.exec(s) | ||||||
|   if (!match) { |   if (!match) { | ||||||
|   | |||||||
| @@ -2,8 +2,8 @@ | |||||||
|   "compilerOptions": { |   "compilerOptions": { | ||||||
|     "outDir": "./dist/", |     "outDir": "./dist/", | ||||||
|     "noImplicitAny": true, |     "noImplicitAny": true, | ||||||
|     "module": "es6", |     "module": "ESNext", | ||||||
|     "target": "es6", |     "target": "ES2022", | ||||||
|     "allowJs": true, |     "allowJs": true, | ||||||
|     "moduleResolution": "node" |     "moduleResolution": "node" | ||||||
|   } |   } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user