MCPcopy
hub / github.com/ocsjs/ocsjs / methods

Function methods

packages/scripts/src/projects/common.ts:645–713  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

643 }
644 },
645 methods() {
646 return {
647 /**
648 * 获取自动答题配置,包括题库配置
649 */
650 getWorkOptions: () => {
651 // 使用 json 深拷贝,防止修改原始配置
652 const workOptions: typeof this.cfg = JSON.parse(JSON.stringify(this.cfg));
653
654 /**
655 * 过滤掉被禁用的题库
656 */
657 workOptions.answererWrappers = workOptions.answererWrappers.filter(
658 (aw) => this.cfg.disabledAnswererWrapperNames.find((daw) => daw === aw.name) === undefined
659 );
660
661 return workOptions;
662 },
663 /**
664 * 根据全局设置的配置,发起通知
665 * @param content
666 * @param opts
667 */
668 notificationBySetting: (
669 content: string,
670 opts?: {
671 extraTitle?: string;
672 /** 显示时间,单位为秒,默认为 30 秒, 0 则表示一直存在 */
673 duration?: number;
674 /** 通知点击时 */
675 onclick?: () => void;
676 /** 通知关闭时 */
677 ondone?: () => void;
678 }
679 ) => {
680 if (this.cfg.notification !== 'no-notify') {
681 $gm.notification(content, {
682 extraTitle: opts?.extraTitle,
683 duration: opts?.duration ?? 30,
684 important: this.cfg.notification === 'all',
685 silent: this.cfg.notification === 'only-notify'
686 });
687
688 const message = (opts?.extraTitle ? opts?.extraTitle + ':' : '') + content;
689
690 const webhooks = this.cfg.notificationWebhooks
691 .split('\n')
692 .map((i) => i.trim())
693 .filter(Boolean);
694
695 for (const webhook of webhooks) {
696 let resolved_webhook = webhook;
697 // eslint-disable-next-line no-template-curly-in-string
698 resolved_webhook = webhook.replace('${message}', encodeURIComponent(message));
699 request(resolved_webhook, {
700 method: 'get',
701 type: 'GM_xmlhttpRequest'
702 })

Callers

nothing calls this directly

Calls 5

requestFunction · 0.90
setNumStyleFunction · 0.85
createResultFunction · 0.85
renderFunction · 0.85
toStringMethod · 0.80

Tested by

no test coverage detected