Twitter hide content warning crap

Hide that annoying box. Also get rid of that blur filter.

当前为 2022-02-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Twitter hide content warning crap
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.6
  5. // @description Hide that annoying box. Also get rid of that blur filter.
  6. // @author You
  7. // @match https://*.twitter.com/*
  8. // @icon https://www.google.com/s2/favicons?domain=twitter.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12. /* jshint esversion: 6 */
  13.  
  14. (function() {
  15. 'use strict';
  16. setInterval(function ()
  17. {
  18. document.querySelectorAll('a[href*="appeal_tweet_warning"]').forEach(node => node.closest('div.r-14gqq1x').remove());
  19. document.querySelectorAll('div[role="button"].r-173mn98').forEach(node => node.click());
  20. }, 250);
  21.  
  22. // Wrap this entire call so that we do not disrupt the website with errors.
  23. let safe_call = function(fn, arg)
  24. {
  25. try
  26. {
  27. fn(arg);
  28. }
  29. catch
  30. {
  31. }
  32. };
  33.  
  34. let legacy_data_mod = function(legacy)
  35. {
  36. legacy.possibly_sensitive = false;
  37. let media_data = legacy.extended_entities.media;
  38. for (let media of media_data)
  39. {
  40. delete media.sensitive_media_warning;
  41. }
  42. };
  43.  
  44. let timeline_entries_mod = function(entries)
  45. {
  46. for (let entry of entries)
  47. {
  48. let legacy = entry?.content?.itemContent?.tweet_results?.result?.legacy;
  49. safe_call(legacy_data_mod, legacy);
  50. safe_call(legacy_data_mod, legacy?.retweeted_status_result?.result?.legacy);
  51. }
  52. }
  53.  
  54. let media_mod = function(tw_response)
  55. {
  56. let entries = tw_response.data.user.result.timeline_v2.timeline.instructions[0].entries;
  57. timeline_entries_mod(entries);
  58. };
  59.  
  60. let tweets_mod = function(tw_response)
  61. {
  62. let entries = tw_response.data.user.result.timeline.timeline.instructions[0].entries;
  63. timeline_entries_mod(entries);
  64. };
  65.  
  66. let tweet_detail_mod = function(tw_response)
  67. {
  68. let entries = tw_response.data.threaded_conversation_with_injections.instructions[0].entries;
  69. timeline_entries_mod(entries);
  70. };
  71.  
  72. // Modifying data on the home page is not working. I'm not sure what field twitter is looking at,
  73. // but these are the only reasonable ones that I could find. The above "click" will hand any leftovers.
  74. let tweet_data_mod = function(tweet)
  75. {
  76. tweet.possibly_sensitive = false;
  77. let media_data = tweet.extended_entities.media;
  78. for (let media of media_data)
  79. {
  80. media.ext_sensitive_media_warning = null;
  81. }
  82. };
  83.  
  84. let global_mod = function(tw_response)
  85. {
  86. for (let tweet in tw_response.globalObjects.tweets)
  87. {
  88. safe_call(tweet_data_mod, tweet);
  89. }
  90. };
  91.  
  92. // Intercept JSON parses to alter the sensitive media data.
  93. let old_parse = JSON.parse;
  94. JSON.parse = function(string)
  95. {
  96. let data = old_parse(string);
  97. safe_call(media_mod, data);
  98. safe_call(tweets_mod, data);
  99. safe_call(tweet_detail_mod, data);
  100. safe_call(global_mod, data);
  101. return data;
  102. };
  103. })();