Greasy Fork is available in English.

Twitter hide content warning crap

Makes it so nothing is marked as sensitive.

  1. // ==UserScript==
  2. // @name Twitter hide content warning crap
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.14
  5. // @description Makes it so nothing is marked as sensitive.
  6. // @author cromachina
  7. // @match https://*.twitter.com/*
  8. // @match https://*.x.com/*
  9. // @icon https://www.google.com/s2/favicons?domain=twitter.com
  10. // @license MIT
  11. // ==/UserScript==
  12. /* jshint esversion: 6 */
  13.  
  14. (function() {
  15. let find_objects_at_keys = function(obj, keys)
  16. {
  17. let found = [];
  18. let stack = Object.entries(obj);
  19. while (stack.length > 0)
  20. {
  21. let current = stack.pop();
  22. if (keys.includes(current[0]))
  23. {
  24. found.push(current[1]);
  25. }
  26. if (current[1] != null && typeof(current[1]) == 'object')
  27. {
  28. stack = stack.concat(Object.entries(current[1]));
  29. }
  30. }
  31. return found;
  32. };
  33.  
  34. let fix_media = function(data)
  35. {
  36. for (let obj of find_objects_at_keys(data, ['media']))
  37. {
  38. if (!Array.isArray(obj))
  39. {
  40. continue;
  41. }
  42. for (let media of obj)
  43. {
  44. if (typeof media != 'object')
  45. {
  46. continue;
  47. }
  48. delete media.sensitive_media_warning;
  49. media.ext_sensitive_media_warning = null;
  50. }
  51. };
  52. for (let obj of find_objects_at_keys(data, ['legacy']))
  53. {
  54. if (obj != null && obj.hasOwnProperty('possibly_sensitive') && typeof obj.possibly_sensitive == 'boolean')
  55. {
  56. obj.possibly_sensitive = false;
  57. }
  58. }
  59. };
  60.  
  61. // Intercept JSON parses to alter the sensitive media data.
  62. let old_parse = unsafeWindow.JSON.parse;
  63. let new_parse = function(string)
  64. {
  65. let data = old_parse(string);
  66. try
  67. {
  68. if (data != null)
  69. {
  70. fix_media(data);
  71. }
  72. }
  73. catch(error)
  74. {
  75. console.log(error);
  76. }
  77. return data;
  78. };
  79. exportFunction(new_parse, unsafeWindow.JSON, { defineAs: "parse" });
  80. })();