Last active
March 8, 2025 02:21
-
-
Save user202729/92671afe95905a4017ed0e261b100c57 to your computer and use it in GitHub Desktop.
Remove comment popup on StackExchange sites ( see https://meta.stackoverflow.com/q/433155/5267751 )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Auto-Click Popover Comment Button (Suppress Original Click) | |
// @namespace http://tampermonkey.net/ | |
// @version 1.1 | |
// @description When a comment-add button is clicked, prevent its default behavior and instead click the corresponding popover comment button. | |
// @author user202729 | |
// @match https://*.stackoverflow.com/* | |
// @match https://*.stackexchange.com/* | |
// @match https://*.superuser.com/* | |
// @match https://stackapps.com/* | |
// @match https://*.serverfault.com/* | |
// @match https://*.askubuntu.com/* | |
// @match https://*.mathoverflow.net/* | |
// @grant none | |
// ==/UserScript== | |
/* created by o3-mini, with some modifications */ | |
/* tested by me and it work on qutebrowser and Firefox tampermonkey */ | |
/* with match list copied from https://stackapps.com/questions/9443/revert-stack-exchanges-new-up-down-vote-buttons */ | |
(function() { | |
'use strict'; | |
// Helper function to check if an element's id starts with a specific prefix. | |
function startsWith(element, prefix) { | |
return element.id && element.id.indexOf(prefix) === 0; | |
} | |
document.addEventListener('click', function(e) { | |
let target = e.target; | |
// Check if the clicked element is a button | |
if (target.tagName !== 'BUTTON') { | |
return; | |
} | |
// Look for a comment-add button | |
if (startsWith(target, "comment-add-button-")) { | |
// Extract the random part of the id. | |
const idParts = target.id.split("comment-add-button-"); | |
if (idParts.length < 2) return; | |
const randomPart = idParts[1]; | |
// Find the corresponding popover comment button. | |
const popoverButtonId = "popover-comment-button-" + randomPart; | |
const popoverButton = document.getElementById(popoverButtonId); | |
// If found, trigger the click on the popover comment button. | |
if (popoverButton) { | |
// Suppress the original event and its default actions. | |
e.preventDefault(); | |
e.stopPropagation(); | |
popoverButton.click(); | |
} | |
} | |
}, true); // useCapture set to true to intercept the event early. | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
apparently JavaScript already have https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith and o3 doesn't know. Well it works anyway