Rename to hkt.sh

This commit is contained in:
mango
2026-03-21 01:10:53 +08:00
parent 76a263d0f9
commit 8f1171fe99
6676 changed files with 1724268 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2019 berstend <github@berstend.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,130 @@
'use strict'
const util = require('util')
const fs = require('fs')
const fse = require('fs-extra')
const os = require('os')
const path = require('path')
const rimraf = require('rimraf')
const debug = require('debug')('puppeteer-extra-plugin:user-data-dir')
const mkdtempAsync = util.promisify(fs.mkdtemp)
const { PuppeteerExtraPlugin } = require('puppeteer-extra-plugin')
/**
*
* Further reading:
* https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md
*/
class Plugin extends PuppeteerExtraPlugin {
constructor(opts = {}) {
super(opts)
this._userDataDir = null
this._isTemporary = false
const defaults = {
deleteTemporary: true,
deleteExisting: false,
files: []
}
// Follow Puppeteers temporary user data dir naming convention by default
defaults.folderPath = os.tmpdir()
defaults.folderPrefix = 'puppeteer_dev_profile-'
this._opts = Object.assign(defaults, opts)
debug('initialized', this._opts)
}
get name() {
return 'user-data-dir'
}
get requirements() {
return new Set(['runLast', 'dataFromPlugins'])
}
get shouldDeleteDirectory() {
if (this._isTemporary && this._opts.deleteTemporary) {
return true
}
return this._opts.deleteExisting
}
get temporaryDirectoryPath() {
return path.join(this._opts.folderPath, this._opts.folderPrefix)
}
get defaultProfilePath() {
return path.join(this._userDataDir, 'Default')
}
async makeTemporaryDirectory() {
this._userDataDir = await mkdtempAsync(this.temporaryDirectoryPath)
this._isTemporary = true
}
deleteUserDataDir() {
debug('removeUserDataDir', this._userDataDir)
if (!this._userDataDir) {
debug('No userDataDir, not running rimraf')
return
}
// We're using rimraf here because it throw errors and don't seem to freeze the process
// If ressources busy or locked by chrome try again 4 times, then give up. overall a timout of 400ms
rimraf(
this._userDataDir,
{
maxBusyTries: 4
},
err => {
debug(err)
}
)
}
async writeFilesToProfile() {
const filesFromPlugins = this.getDataFromPlugins('userDataDirFile').map(
d => d.value
)
const files = [].concat(filesFromPlugins, this._opts.files)
if (!files.length) {
return
}
for (const file of files) {
if (file.target !== 'Profile') {
console.warn(`Warning: Ignoring file with invalid target`, file)
continue
}
const filePath = path.join(this.defaultProfilePath, file.file)
try {
await fse.outputFile(filePath, file.contents)
debug(`Wrote file`, filePath)
} catch (err) {
console.warn('Warning: Failure writing file', filePath, file, err)
}
}
}
async beforeLaunch(options) {
this._userDataDir = options.userDataDir
if (!this._userDataDir) {
await this.makeTemporaryDirectory()
options.userDataDir = this._userDataDir
debug('created custom dir', options.userDataDir)
}
await this.writeFilesToProfile()
}
async onDisconnected() {
debug('onDisconnected')
if (this.shouldDeleteDirectory) {
this.deleteUserDataDir()
}
}
}
module.exports = function(pluginConfig) {
return new Plugin(pluginConfig)
}

View File

@@ -0,0 +1,53 @@
{
"name": "puppeteer-extra-plugin-user-data-dir",
"version": "2.4.1",
"description": "Custom user data directory for puppeteer.",
"main": "index.js",
"repository": "berstend/puppeteer-extra",
"author": "berstend",
"license": "MIT",
"scripts": {
"docs": "node -e 0",
"lint": "eslint --ext .js .",
"test": "run-p lint",
"test-ci": "run-s test"
},
"engines": {
"node": ">=8"
},
"keywords": [
"puppeteer",
"puppeteer-extra",
"puppeteer-extra-plugin",
"user-data",
"userDataDir",
"profile",
"chrome",
"headless",
"pupeteer"
],
"devDependencies": {
"ava": "2.4.0",
"npm-run-all": "^4.1.5",
"puppeteer": "^2.0.0"
},
"dependencies": {
"debug": "^4.1.1",
"fs-extra": "^10.0.0",
"puppeteer-extra-plugin": "^3.2.3",
"rimraf": "^3.0.2"
},
"peerDependencies": {
"playwright-extra": "*",
"puppeteer-extra": "*"
},
"peerDependenciesMeta": {
"puppeteer-extra": {
"optional": true
},
"playwright-extra": {
"optional": true
}
},
"gitHead": "2f4a357f233b35a7a20f16ce007f5ef3f62765b9"
}

View File

@@ -0,0 +1,30 @@
# puppeteer-extra-plugin-user-data-dir
> A plugin for [puppeteer-extra](https://github.com/berstend/puppeteer-extra).
### Install
```bash
yarn add puppeteer-extra-plugin-user-data-dir
```
## API
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
#### Table of Contents
- [Plugin](#plugin)
### [Plugin](https://github.com/berstend/puppeteer-extra/blob/db57ea66cf10d407cf63af387892492e495a84f2/packages/puppeteer-extra-plugin-user-data-dir/index.js#L19-L113)
**Extends: PuppeteerExtraPlugin**
Further reading:
<https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md>
Type: `function (opts)`
- `opts` (optional, default `{}`)
* * *