Don't tweet without alt text

Adds a conformation box before tweeting with media lacking alt text

  1. // ==UserScript==
  2. // @name Don't tweet without alt text
  3. // @description Adds a conformation box before tweeting with media lacking alt text
  4. // @author stick
  5. // @version 1
  6. // @homepageURL https://github.com/sticks-stuff/Dont-tweet-without-alt-text
  7. // @include https://twitter.*/*
  8. // @grant none
  9. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js
  10. // @require https://gf.qytechs.cn/scripts/31940-waitforkeyelements/code/waitForKeyElements.js
  11. // @namespace https://gf.qytechs.cn/users/710818
  12. // ==/UserScript==
  13.  
  14. console.log("Don't tweet without alt text loaded!");
  15.  
  16. waitForKeyElements ('[data-testid="tweetButton"][data-focusable="true"]', tweetButtonLoaded);
  17. waitForKeyElements ('[aria-label="Media"][role="group"]', imagesAdded);
  18.  
  19. function tweetButtonLoaded (tweetButton)
  20. {
  21. console.log("hijacked tweet button");
  22. var tweetButtonReal = tweetButton[0];
  23. tweetButtonReal.dataset.testid = "hijacked";
  24. var clonedButton = $(tweetButtonReal).clone(true);
  25. var parentOfButton = $(tweetButtonReal).parent();
  26. console.log($(tweetButtonReal).data('events'));
  27. $(tweetButtonReal).hide();
  28. $(clonedButton).appendTo($(parentOfButton));
  29. $(clonedButton).click(function () {
  30. var attachmentsWithoutAlt = document.querySelectorAll('[aria-label="Media"][role="group"]').length;
  31. if(attachmentsWithoutAlt > 0) {
  32. var answer = window.confirm("You have " + attachmentsWithoutAlt + " attachments without alt text in this tweet. Are you sure you want to send?");
  33. if (answer) {
  34. $(clonedButton).remove();
  35. $(tweetButtonReal).click();
  36. $(tweetButtonReal).show();
  37. }
  38. else {
  39. console.log("cancelled");
  40. }
  41. } else {
  42. $(clonedButton).remove();
  43. $(tweetButtonReal).click();
  44. $(tweetButtonReal).show();
  45. }
  46. });
  47. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址