Twitter/X.com mark all media as sensitive

Marks all media as sensitive. This could be used to avoid seeing unwanted NSFW content.

目前為 2024-06-18 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Twitter/X.com mark all media as sensitive
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Marks all media as sensitive. This could be used to avoid seeing unwanted NSFW content.
  6. // @author Azeez
  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.  
  13. (function() {
  14. let findObjectsForKey = function(obj, keys) {
  15. return Object.entries(obj).reduce((found, [key, value]) => {
  16. if (keys.includes(key)) {
  17. found.push(value);
  18. }
  19. if (value != null && typeof(value) == 'object') {
  20. found = found.concat(findObjectsForKey(value, keys));
  21. }
  22. return found;
  23. }, []);
  24. };
  25.  
  26. let blurMedia = function(data) {
  27. findObjectsForKey(data, ['media']).forEach(obj => {
  28. if (Array.isArray(obj)) {
  29. obj.forEach(media => {
  30. if (typeof media == 'object') {
  31. media.sensitive_media_warning = {other: true};
  32. }
  33. });
  34. }
  35. });
  36. };
  37.  
  38. let old_parse = unsafeWindow.JSON.parse;
  39. let new_parse = function(string) {
  40. let data = old_parse(string);
  41. blurMedia(data);
  42. return data;
  43. };
  44. exportFunction(new_parse, unsafeWindow.JSON, { defineAs: "parse" });
  45. })();