Delete Thread

Delete thread on Perplexity by pressing the Delete key and confirming with Enter

目前为 2024-05-15 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Delete Thread
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Delete thread on Perplexity by pressing the Delete key and confirming with Enter
  6. // @author JJJ
  7. // @match https://www.perplexity.ai/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=perplexity.ai
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. // Listen for keydown events
  17. document.addEventListener('keydown', function (event) {
  18. // If the Delete key is pressed, open the menu and trigger the delete thread action
  19. if (event.key === 'Delete') {
  20. openMenuAndDeleteThread();
  21. }
  22. // If the Enter key is pressed, confirm the deletion
  23. else if (event.key === 'Enter') {
  24. confirmDeletion();
  25. }
  26. // If the Backspace key is pressed, cancel the deletion
  27. else if (event.key === 'Backspace') {
  28. cancelDeletion();
  29. }
  30. });
  31.  
  32. // Function to open the menu and trigger the delete thread action
  33. function openMenuAndDeleteThread() {
  34. var ellipsisButton = document.querySelector('svg[data-icon="ellipsis"]').parentNode;
  35. if (ellipsisButton) {
  36. ellipsisButton.click();
  37. setTimeout(deleteThread, 10); // Wait for a short time before triggering the delete thread action
  38. } else {
  39. console.log('Ellipsis button not found');
  40. }
  41. }
  42.  
  43. // Function to trigger the delete thread action
  44. function deleteThread() {
  45. var deleteButton = Array.from(document.querySelectorAll('span')).find(button => button.textContent === 'Delete Thread');
  46. if (deleteButton) {
  47. deleteButton.click();
  48. console.log('Thread deletion triggered');
  49. } else {
  50. console.log('Delete button not found');
  51. }
  52. }
  53.  
  54. // Function to confirm the deletion
  55. function confirmDeletion() {
  56. var confirmButton = document.querySelector('.bg-superAlt.text-white');
  57. if (confirmButton) {
  58. confirmButton.click();
  59. console.log('Confirm triggered');
  60. } else {
  61. console.log('Confirm button not found');
  62. }
  63. }
  64.  
  65. // Function to cancel the deletion
  66. function cancelDeletion() {
  67. var nevermindButton = document.querySelector('');
  68. if (nevermindButton) {
  69. nevermindButton.click();
  70. console.log('Nevermind triggered');
  71. } else {
  72. console.log('Nevermind button not found');
  73. }
  74. }
  75. })();