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