// ==UserScript== // @name 网页Cmd模拟 // @namespace unrival // @version 0.0.1 // @description 通过引用网页Cmd模拟模块,实现在任意页面上模拟出cmd命令行效果 // @author unrival // @match *://cmd.xn--6cs.top/* // @grant unsafeWindow // @run-at document-end // @require https://scriptcat.org/lib/751/0.1.2/%E7%BD%91%E9%A1%B5Cmd%E6%A8%A1%E6%8B%9F%E6%A8%A1%E5%9D%97.js // ==/UserScript== (function() { 'use strict'; var useEval = false, cmd = new UselessCmd(); //创建cmd cmd.initialize(unsafeWindow,'UselessCmd命令行','https://scriptcat.org/favicon.ico'); //初始化模块,向cmd传入窗口对象、窗口标题和ico,将页面重写为仿cmd窗口 function callback(command){ //定义一个回调函数,又来接收用户输入的命令 if(!useEval){ if(command=='eval'){ useEval = true; this.update('已切换至eval模式'); return } this.update('您输入了:'+command); this.update('输入“eval”切换至eval模式'); }else{ //this.update用来向屏幕输出信息 try{ let result = eval(command); this.update(result); }catch(e){ this.update(e); } } } cmd.bind(callback); //为UselessCmd绑定一个回调函数,在用户输入指令后,该指令会作为字符串参数传递至回调函数,回调函数的this即为UselessCmd的this //cmd.unBind(); //解绑回调函数 //cmd.getCommand(); //获取用户输入的最新一条命令 })();