0

I don't understand why it doesn't work,on js it usually work.

I mean what's wrong in it ?? when a box open it should return true directly

// ==UserScript==
// @name         Moderate Faster
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  A tool to moderate faster for moderators, it bypass alert box
// @author       Kai Smith
// @match      *://*stackoverflow.com/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

window.confirm = function myConfirm() {
  return true;
}

const a = confirm("Are you sure")
console.log(a)
mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • Seem to work in the snippet I made – mplungjan Apr 30 '21 at 20:28
  • it doesn't with tampermonkey – Black SouleZOD Apr 30 '21 at 20:30
  • It also works in Tampermonkey. As long as you use the correct `@match` (Stack Overflow snippets run on `https://stacksnippets.net/`) and you make sure that the confirm runs _after_ your user script runs (using `@run-at document-start`). – Ivar Apr 30 '21 at 20:35
  • I will check using run at document start :) – Black SouleZOD Apr 30 '21 at 20:40
  • well it still doesn't work – Black SouleZOD Apr 30 '21 at 20:41
  • When I click on a button in another script connected to a function with a confirm, it still shows the confirm box – Black SouleZOD Apr 30 '21 at 20:43
  • @BlackSouleZOD We can't really help you if we can't reproduce the problem. If I use [this user script](https://jsfiddle.net/ya7x2vem/) and run `console.log(confirm('test'));` [it logs "true"](https://i.stack.imgur.com/YobE7.png) without showing the confirm box. – Ivar Apr 30 '21 at 20:50
  • on the console log of the specified web they say "[Violation] 'click' handler took 2255ms" is there any relation ? – Black SouleZOD Apr 30 '21 at 21:14
  • I don't think so. That message is just a warning that the click function took over 2 seconds. `confirm()` is a blocking function which means that as long as the box is open, no other JavaScript can be executed. For `confirm()` that is not much of a nightmare because they need to click one of the buttons anyway and don't need to do anything else, but other functions that take that long generally completely freeze the page which is not something users like. – Ivar Apr 30 '21 at 21:25

0 Answers0