Twitter 移除内容警告

移除 twitter 的敏感内容警告

目前为 2024-04-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Twitter remove content warning
  3. // @name:zh-CN Twitter 移除内容警告
  4. // @icon https://twitter.com/favicon.ico
  5. // @namespace https://github.com/Tsuk1ko
  6. // @version 1.0.0
  7. // @description Remove twitter content warning
  8. // @description:zh-CN 移除 twitter 的敏感内容警告
  9. // @author 神代綺凛
  10. // @include https://twitter.com/*
  11. // @include https://mobile.twitter.com/*
  12. // @license MIT
  13. // @grant GM_addStyle
  14. // @run-at document-end
  15. // ==/UserScript==
  16.  
  17. (async () => {
  18. 'use strict';
  19.  
  20. const css = (strings, ...values) => GM_addStyle(String.raw({ raw: strings }, ...values));
  21.  
  22. /**
  23. * @template {Function} T
  24. * @param {T} func
  25. * @param {number} timeout
  26. * @returns {ReturnType<T>}
  27. */
  28. const waitValue = (func, timeout = 10000) =>
  29. new Promise((resolve, reject) => {
  30. const val = func();
  31. if (val) {
  32. resolve(val);
  33. return;
  34. }
  35. const timeoutTimer = setTimeout(() => {
  36. clearInterval(timer);
  37. reject();
  38. }, timeout);
  39. const timer = setInterval(() => {
  40. const val = func();
  41. if (val) {
  42. clearTimeout(timeoutTimer);
  43. clearInterval(timer);
  44. resolve(val);
  45. }
  46. }, 500);
  47. });
  48.  
  49. const findBlurCssRule = () => {
  50. for (const ss of document.styleSheets) {
  51. for (const rule of ss.cssRules) {
  52. if (!(rule instanceof CSSStyleRule)) continue;
  53. if (rule.style.filter === 'blur(30px)') {
  54. return rule;
  55. }
  56. }
  57. }
  58. };
  59.  
  60. const rule = await waitValue(findBlurCssRule);
  61. if (!rule) return;
  62.  
  63. rule.style.filter = '';
  64.  
  65. css`
  66. ${rule.selectorText} + div {
  67. display: none;
  68. }
  69. `;
  70. })();