由于无限提示,我无法访问我的 javascript 代码

I can't access my javascript code because of infinite prompts

帮助,我一直在使用这个名为“codepen”的网站来进行一些 javascript 编码。但我不小心让它给我发送了无限提示,每次我打开项目。现在我无法访问代码。我搜索了一些时间来寻找答案,但我找到了 none。这是问题的 link:https://codepen.io/Aibel-Roy/pen/zYPBeEW

//I can't post the code because of the infinite prompts. Sorry.

在你的function draw()里面有一个提示:

function draw() {
  // Trimmed
  prompt(img.src);
  
  // Trimmed
}

您还以 tick 中定义的特定时间间隔调用 draw() 的 setInterval(您已指定 50 毫秒作为值):

setInterval(function main() {
  draw();
  Movement();
}, tick);

因此,draw() 每 50 毫秒被调用一次,其中 prompt(img.src) 被调用,导致无限提示。

您需要更改您在 setInterval() 中所做的任何事情。

这是您的代码:

//config
var tick = 50;
var fieldOfView = 25;
var Speed = 0.25;
var ZMulti = 4;
var ClearOnDraw = true;

// variables
var keymap = [];
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var meshA = [
  "0,0,0",
  "1,0,0",
  "1,1,0",
  "0,1,0",
  "0,0,1",
  "1,0,1",
  "0,1,1",
  "1,1,1"
];
var textures = [
  "http://www.textures4photoshop.com/tex/thumbs/red-sofa-leather-seamless-texture-53.jpg"
];
var cameraData = [0, 0, 0];

//keymap
window.addEventListener(
  "keydown",
  (event) => {
    var name = event.key;
    keymap.push(name);
  },
  false
);
window.addEventListener(
  "keyup",
  (event) => {
    var name = event.key;
    if (keymap.includes(name)) {
      keymap.splice(keymap.indexOf(name), 1);
    }
  },
  false
);

//render img
function draw() {
  if (ClearOnDraw) {
    ctx.clearRect(0, 0, 10000, 1000);
  }
  var img = new Image(); // texturing
  img.src = textures[0];
  prompt(img.src);
  img.onLoad = function () {
    var pattern = context.createPattern(imageObj, "repeat");
    ctx.fillStyle = pattern;
    var prevVert;
    for (let i = 0; i <= meshA.length; i++) {
      //convert 3D vector to 2D
      var vert = meshA[i];
      if (i >= meshA.length) {
        vert = meshA[0];
      }
      var vertPos = vert.split(",");
      var zMag = (vertPos[2] - cameraData[2]) * (fieldOfView / ZMulti);
      var vertPos2D = [
        (vertPos[0] - cameraData[0]) * fieldOfView + zMag,
        (vertPos[1] - cameraData[1]) * fieldOfView + zMag
      ];

      ctx.beginPath();
      ctx.moveTo(vertPos2D[0], vertPos2D[1]);
      for (let i1 = 0; i1 < meshA.length; i1++) {
        var prv = meshA[i1].split(",");
        var PrevzMag = (prv[2] - cameraData[2]) * (fieldOfView / ZMulti);
        var I1VertPos = [
          (prv[0] - cameraData[0]) * fieldOfView + PrevzMag,
          (prv[1] - cameraData[1]) * fieldOfView + PrevzMag
        ];
        ctx.lineTo(I1VertPos[0], I1VertPos[1]);
        ctx.stroke();
      }
      ctx.closePath();
      ctx.fill();
      prevVert = vertPos2D;
    }
  };
}
function Movement() {
  if (keymap.includes("w")) {
    cameraData[2] -= Speed * 2;
  }
  if (keymap.includes("s")) {
    cameraData[2] += Speed * 2;
  }
  if (keymap.includes("d")) {
    cameraData[0] -= Speed;
  }
  if (keymap.includes("a")) {
    cameraData[0] += Speed;
  }
}

draw();
setInterval(function main() {
  draw();
  Movement();
}, tick);

如何禁用 prompt(如果浏览器不建议您禁用它):

  1. 在该页面上,调出开发工具(Command + Option + I,或 F12 在 Windows)。

  2. 在开发工具上选择正确的页面,通常看起来像CodePen (Hash ID)

  3. 通过键入 window.prompt = () => {} 覆盖控制台中的 prompt 函数。

  4. 更改您的代码,保存并刷新页面。

There are probably better ways to do it but disabling JavaScript makes the code section unusable.