Userscript template aktualisiert

This commit is contained in:
Daniel Triendl 2021-08-27 18:12:26 +02:00
parent fec9885a64
commit 4283ee6b5c
21 changed files with 9951 additions and 5850 deletions

9
.babelrc.js Normal file
View File

@ -0,0 +1,9 @@
module.exports = function (api) {
api.cache(true)
const presets = ['@babel/preset-env']
return {
presets,
}
}

3
.browserslistrc Normal file
View File

@ -0,0 +1,3 @@
> 1%
not IE 11
not dead

View File

@ -5,9 +5,9 @@ module.exports = {
namespace: 'http://cp-solutions.at',
version: pkg.version,
author: pkg.author,
copyright: 'Copyright 2020 CP Solutions GmbH',
copyright: 'Copyright 2021 CP Solutions GmbH',
source: pkg.repository.url,
downloadURL: 'http://scootaloo.cp-austria.at/gitlist/3cx_tapi.git/raw/master/3CX_TAPI.user.js',
downloadURL: 'https://source.cp-austria.at/git/CPATRD/3cx_tapi/raw/branch/master/3CX_TAPI.user.js',
match: [
'https://192.168.0.154:5001/webclient*',
'https://cpsolution.my3cx.at:5001/webclient*'
@ -18,8 +18,10 @@ module.exports = {
`https://cdn.jsdelivr.net/npm/axios-userscript-adapter@${pkg.dependencies['axios-userscript-adapter']}/dist/axiosGmxhrAdapter.min.js`
],
grant: [
'GM_xmlhttpRequest',
'GM.notification'
'GM.xmlHttpRequest',
'GM.notification',
'GM.getValue',
'GM.setValue'
],
connect: [
'cpatapi.cpsrvweb2016.cp-austria.at'

View File

@ -1,42 +1,38 @@
const path = require('path')
const webpack = require('webpack')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const webpackConfig = {
node: {
Buffer: false
},
resolve: {
extensions: ['.js', '.ts']
},
// performance: {
// hints: false
// },
optimization: {
minimize: false
minimize: false,
moduleIds: 'named',
},
entry: './src/js/index.js',
entry: './src/index.js',
output: {
path: path.resolve(__dirname, '../dist')
},
externals: {
jquery: '$',
axios: 'axios',
'axios-userscript-adapter': 'axiosGmxhrAdapter'
},
module: {
rules: [
{
use: {
loader: 'babel-loader',
},
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader'
},
{
test: /\.ts$/,
exclude: /node_modules/,
loader: 'ts-loader'
},
{
test: /\.less$/,
loader: [
use: [
'style-loader',
'css-loader',
'less-loader', // 将 Less 编译为 CSS
@ -44,16 +40,14 @@ const webpackConfig = {
},
{
test: /\.css$/,
loader: [
use: [
'style-loader',
'css-loader',
]
}
]
},
plugins: [
new webpack.HashedModuleIdsPlugin()
]
plugins: process.env.npm_config_report ? [new BundleAnalyzerPlugin()] : [],
}
module.exports = webpackConfig

View File

@ -0,0 +1,37 @@
const path = require('path')
const { merge } = require('webpack-merge')
const LiveReloadPlugin = require('webpack-livereload-plugin')
const UserScriptMetaDataPlugin = require('userscript-metadata-webpack-plugin')
const metadata = require('./metadata.cjs')
const webpackConfig = require('./webpack.config.base.cjs')
metadata.require.push(
'file://' + path.resolve(__dirname, '../dist/index.prod.user.js')
)
const cfg = merge(webpackConfig, {
entry: {
prod: webpackConfig.entry,
dev: path.resolve(__dirname, './empty.cjs'),
},
output: {
filename: 'index.[name].user.js',
path: path.resolve(__dirname, '../dist'),
},
devtool: 'inline-source-map',
watch: true,
watchOptions: {
ignored: /node_modules/,
},
plugins: [
new LiveReloadPlugin({
delay: 500,
}),
new UserScriptMetaDataPlugin({
metadata,
}),
],
})
module.exports = cfg

View File

@ -1,43 +0,0 @@
const path = require("path");
const { merge } = require("webpack-merge");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
const LiveReloadPlugin = require("webpack-livereload-plugin");
const UserScriptMetaDataPlugin = require("userscript-metadata-webpack-plugin");
const metadata = require("./metadata");
const webpackConfig = require("./webpack.config.base");
metadata.require.push(
"file://" + path.resolve(__dirname, "../dist/index.prod.user.js")
);
const cfg = merge(webpackConfig, {
entry: {
prod: webpackConfig.entry,
dev: path.resolve(__dirname, "./empty.js"),
},
output: {
filename: "index.[name].user.js",
path: path.resolve(__dirname, "../dist"),
},
devtool: "inline-source-map",
watch: true,
watchOptions: {
ignored: /node_modules/,
},
plugins: [
new LiveReloadPlugin({
delay: 500,
}),
new UserScriptMetaDataPlugin({
metadata,
}),
],
});
if (process.env.npm_config_report) {
cfg.plugins.push(new BundleAnalyzerPlugin());
}
module.exports = cfg;

View File

@ -0,0 +1,19 @@
const { merge } = require('webpack-merge')
const UserScriptMetaDataPlugin = require('userscript-metadata-webpack-plugin')
const metadata = require('./metadata.cjs')
const webpackConfig = require('./webpack.config.base.cjs')
const cfg = merge(webpackConfig, {
mode: 'production',
output: {
filename: metadata.name + '.prod.user.js',
},
plugins: [
new UserScriptMetaDataPlugin({
metadata,
}),
],
})
module.exports = cfg

View File

@ -1,23 +0,0 @@
const { merge } = require("webpack-merge");
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const UserScriptMetaDataPlugin = require('userscript-metadata-webpack-plugin')
const metadata = require('./metadata')
const webpackConfig = require('./webpack.config.base')
const cfg = merge({}, webpackConfig, {
output: {
filename: 'index.prod.user.js'
},
plugins: [
new UserScriptMetaDataPlugin({
metadata
})
]
})
if (process.env.npm_config_report) {
cfg.plugins.push(new BundleAnalyzerPlugin())
}
module.exports = cfg

15443
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,25 +1,22 @@
{
"name": "3cp-tapi",
"description": "Build your UserScript with webpack",
"version": "7.0.3",
"version": "8.0.0",
"author": {
"name": "Daniel Triendl",
"email": "d.triendl@cp-solutions.at"
},
"browserslist": [
"last 2 version",
"> 1%"
],
"eslintIgnore": [
"dist/*.js"
"dist/*.js",
"node_modules"
],
"scripts": {
"lint": "eslint src",
"lint": "eslint --ext .ts,.js src",
"preversion": "npm run lint",
"postversion": "git push --follow-tags",
"anylize": "npm_config_report=true npm run build",
"build": "webpack --mode production --config config/webpack.config.production.js",
"dev": "webpack --mode development --config config/webpack.config.dev.js"
"build": "webpack --mode production --config config/webpack.config.production.cjs",
"dev": "webpack --mode development --config config/webpack.config.dev.cjs"
},
"repository": {
"type": "git",
@ -27,32 +24,34 @@
},
"private": true,
"dependencies": {
"axios": "0.20.0",
"axios-userscript-adapter": "0.0.7",
"chrono-node": "2.1.9"
"axios": "0.21.1",
"axios-userscript-adapter": "0.1.4",
"chrono-node": "^2.3.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "4.3.0",
"@typescript-eslint/parser": "4.3.0",
"css-loader": "4.3.0",
"eslint": "7.10.0",
"eslint-config-standard": "14.1.1",
"eslint-loader": "4.0.2",
"eslint-plugin-import": "2.22.1",
"@babel/core": "7.14.6",
"@babel/preset-env": "7.14.5",
"@typescript-eslint/eslint-plugin": "4.27.0",
"@typescript-eslint/parser": "4.27.0",
"babel-loader": "8.2.2",
"browserslist": "4.16.6",
"css-loader": "5.2.6",
"eslint": "7.29.0",
"eslint-config-standard": "16.0.3",
"eslint-plugin-import": "2.23.4",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "4.2.1",
"eslint-plugin-standard": "4.0.1",
"less": "3.12.2",
"less-loader": "7.0.1",
"style-loader": "1.2.1",
"ts-loader": "8.0.4",
"typescript": "4.0.3",
"userscript-metadata-webpack-plugin": "0.0.6",
"webpack": "4.44.2",
"webpack-bundle-analyzer": "3.9.0",
"webpack-cli": "3.3.12",
"webpack-dev-server": "^3.11.0",
"webpack-livereload-plugin": "2.3.0",
"webpack-merge": "5.1.4"
"eslint-plugin-promise": "5.1.0",
"eslint-plugin-standard": "4.1.0",
"less": "4.1.1",
"less-loader": "10.0.0",
"style-loader": "2.0.0",
"ts-loader": "9.2.3",
"typescript": "4.3.4",
"userscript-metadata-webpack-plugin": "0.1.0",
"webpack": "5.39.1",
"webpack-bundle-analyzer": "4.4.2",
"webpack-cli": "4.7.2",
"webpack-livereload-plugin": "3.0.1",
"webpack-merge": "5.8.0"
}
}

View File

View File

@ -3,6 +3,7 @@ import * as chrono from 'chrono-node'
import { CallHistory } from './call-history'
import { CallNotification } from './call-notification'
import { Search } from './search'
import { Status } from './status'
console.log('script start')

View File

@ -1,33 +0,0 @@
/**
* @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) {
var match = /(\+?[0-9]{4,})/.exec(s)
if (!match) {
return undefined
}
var number = match[1]
if (number.startsWith('+')) {
number = number.replace('+', '00')
}
return number
}

View File

@ -1,6 +1,6 @@
import { TapiContact } from './tapi-contact'
import { debounce } from './debounce'
import { axios } from './utils'
import { axios, fireChangeEvents } from './utils'
export class Search {
private currentSearchText = ''
@ -175,23 +175,7 @@ export class Search {
(<HTMLInputElement>searchInput[0]).value = number
searchInput[0].focus()
this.fireChangeEvents(searchInput[0])
fireChangeEvents(searchInput[0])
}
}
private fireChangeEvents (element: Element) {
var changeEvent = null
changeEvent = document.createEvent('HTMLEvents')
changeEvent.initEvent('input', true, true)
element.dispatchEvent(changeEvent)
console.debug('input event dispatched for element: ' + element.id)
changeEvent = document.createEvent('HTMLEvents')
changeEvent.initEvent('keyup', true, true)
element.dispatchEvent(changeEvent)
console.debug('keyup event dispatched for element: ' + element.id)
changeEvent = document.createEvent('HTMLEvents')
changeEvent.initEvent('change', true, true)
element.dispatchEvent(changeEvent)
console.debug('change event dispatched for element: ' + element.id)
}
}

18
src/status.css Normal file
View File

@ -0,0 +1,18 @@
.tapi-dropdown {
position: relative;
display: inline-block;
}
.tapi-dropdown-content {
display: none;
position: absolute;
min-width: 200px;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
color: #000;
}
.show {
display: block;
}

49
src/utils.ts Normal file
View File

@ -0,0 +1,49 @@
/**
* @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) {
var match = /(\+?[0-9]{4,})/.exec(s)
if (!match) {
return undefined
}
var number = match[1]
if (number.startsWith('+')) {
number = number.replace('+', '00')
}
return number
}
export function fireChangeEvents (element: Element) {
var changeEvent = null
changeEvent = document.createEvent('HTMLEvents')
changeEvent.initEvent('input', true, true)
element.dispatchEvent(changeEvent)
console.debug('input event dispatched for element: ' + element.id)
changeEvent = document.createEvent('HTMLEvents')
changeEvent.initEvent('keyup', true, true)
element.dispatchEvent(changeEvent)
console.debug('keyup event dispatched for element: ' + element.id)
changeEvent = document.createEvent('HTMLEvents')
changeEvent.initEvent('change', true, true)
element.dispatchEvent(changeEvent)
console.debug('change event dispatched for element: ' + element.id)
}