Skip to content

Commit

Permalink
fix(puppeteer): rawtext support for selector
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jun 4, 2021
1 parent 11e9fe3 commit 03507fa
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/plugin-eval/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function apply(ctx: Context, config: Config = {}) {
// worker should be running for all the features
ctx = ctx.intersect(() => ctx.worker?.state === EvalWorker.State.open)

const command = ctx.command('evaluate [expr:text]', '执行 JavaScript 脚本', { noEval: true })
const command = ctx.command('evaluate [expr:rawtext]', '执行 JavaScript 脚本', { noEval: true })
.alias('eval')
.userFields(['authority'])
.option('slient', '-s 不输出最后的结果')
Expand All @@ -113,7 +113,7 @@ export function apply(ctx: Context, config: Config = {}) {
if (!expr) return '请输入要执行的脚本。'

try {
expr = await ctx.worker.loader.transformScript(segment.unescape(expr))
expr = await ctx.worker.loader.transformScript(expr)
} catch (err) {
return err.message
}
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-puppeteer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export function apply(ctx: Context, config: Config = {}) {
})

const ctx1 = ctx.intersect(sess => !!sess.app.puppeteer)
ctx1.command('shot <url> [selector:text]', '网页截图', { authority: 2 })
ctx1.command('shot <url> [selector:rawtext]', '网页截图', { authority: 2 })
.alias('screenshot')
.option('full', '-f 对整个可滚动区域截图')
.option('viewport', '-v <viewport> 指定视口', { type: 'string' })
Expand Down Expand Up @@ -244,12 +244,12 @@ export function apply(ctx: Context, config: Config = {}) {
}).finally(() => page.close())
})

ctx1.command('tex <code:text>', 'TeX 渲染', { authority: 2 })
ctx1.command('tex <code:rawtext>', 'TeX 渲染', { authority: 2 })
.usage('渲染器由 https://www.zhihu.com/equation 提供。')
.action(async (_, tex) => {
if (!tex) return '请输入要渲染的 LaTeX 代码。'
return ctx.puppeteer.render(null, async (page, next) => {
await page.goto('https://www.zhihu.com/equation?tex=' + escape(segment.unescape(tex)))
await page.goto('https://www.zhihu.com/equation?tex=' + escape(tex))
const svg = await page.$('svg')
const inner: string = await svg.evaluate((node: SVGElement) => {
node.style.padding = '0.25rem 0.375rem'
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-tools/src/brainfuck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ export const name = 'brainfuck'
export function apply(ctx: Context, config: BrainfuckOptions = {}) {
ctx.command('tools/brainfuck <code>', '运行 brainfuck 代码')
.alias('bf')
.option('input', '-- <input:text> 设置输入', { fallback: '' })
.option('input', '-- <input:rawtext> 设置输入', { fallback: '' })
.usage('语言介绍:http://www.muppetlabs.com/~breadbox/bf')
.action(async ({ options }, source) => {
if (!source) return '请输入源代码。'
source = segment.unescape(source)
const input = segment.unescape(options.input)
const input = options.input
try {
return segment.escape(new BrainFuck(source, config).exec(input))
} catch (error) {
Expand Down
5 changes: 1 addition & 4 deletions packages/plugin-tools/src/crypto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import Vigenere from './algorithms/vigenere'
import TwoSquare from './algorithms/two-square'
import FourSquare from './algorithms/four-square'
import { Context } from 'koishi-core'
import { segment } from 'koishi-utils'

export const name = 'crypto'

export function apply(ctx: Context) {
ctx.command('tools/crypto <algorithm> <text>', '加密解密工具')
ctx.command('tools/crypto <algorithm> <text:rawtext>', '加密解密工具')
.option('encrypt', '-e 加密模式(默认)')
.option('decrypt', '-d 解密模式')
.option('case', '-c <maintain|upper|lower> 控制输出字母的大小写,默认为 maintain')
Expand All @@ -30,8 +29,6 @@ export function apply(ctx: Context) {
.action(({ options }, algorithms, text) => {
if (!text) return '请输入文本。'
if (!algorithms) return '请指定算法。'
text = segment.unescape(text)
algorithms = segment.unescape(algorithms)

let cap: RegExpMatchArray
const cryptos = []
Expand Down

0 comments on commit 03507fa

Please sign in to comment.