Show not checked content

Shows content hidden by Valve's automated content check system

当前为 2020-08-25 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Show not checked content
  3. // @namespace https://greasyfork.org/users/2205
  4. // @version 0.2
  5. // @description Shows content hidden by Valve's automated content check system
  6. // @author Ryzhehvost
  7. // @license Apache-2.0
  8. // @match https://steamcommunity.com/groups/*/discussions/*
  9. // @match https://steamcommunity.com/discussions/forum/*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. /* global g_rgForumTopicCommentThreads */
  16. /* global g_rgForumTopics*/
  17. function GetText( gidTopic, gidComment )
  18. {
  19. var CommentThread = g_rgForumTopicCommentThreads[gidTopic];
  20. var rgRawComment;
  21. if ( gidComment && gidComment != -1 )
  22. {
  23. rgRawComment = CommentThread.GetRawComment( gidComment );
  24. }
  25. else
  26. {
  27. // topic quoting
  28. rgRawComment = g_rgForumTopics[gidTopic].m_rgRawData;
  29. }
  30. return rgRawComment.text;
  31. }
  32.  
  33. function FormatBBCode(text){
  34. console.log(text);
  35. let re = /[noparse](.*)[/noparse]/g;
  36. let noparse = text.match(re);
  37. re = /\[h1\](.*?)\[\/h1\]/g;
  38. text = text.replace(re, '<div class="bb_h1">$1</div>');
  39. console.log(text);
  40. re = /\[b\](.*?)\[\/b\]/g;
  41. text = text.replace(re, '<b>$1</b>');
  42. console.log(text);
  43. re = /\[u\](.*?)\[\/u\]/g;
  44. text = text.replace(re, '<u>$1</u>');
  45. console.log(text);
  46. re = /\[i\](.*?)\[\/i\]/g;
  47. text = text.replace(re, '<i>$1</i>');
  48. console.log(text);
  49. re = /\[strike\](.*?)\[\/strike\]/g;
  50. text = text.replace(re, '<span class="bb_strike">$1</span>');
  51. console.log(text);
  52. re = /\[spoiler\](.*)\[\/spoiler\]/g;
  53. text = text.replace(re, '<span class="bb_spoiler"><span>$1</span></span>');
  54. console.log(text);
  55. re = /\[url=(.*?)\](.*?)\[\/url\]/g;
  56. text = text.replace(re, '<a class="bb_link" href="$1" target="_blank" rel="noreferrer">$2</a>');
  57. console.log(text);
  58. re = /([^>"]|^)(http|https|ftp)(:\/\/[^\s]*)/g;
  59. text = text.replace(re, '$1<a class="bb_link" href="$1" target="_blank" rel="noreferrer">$2$3</a>');
  60. console.log(text);
  61. re = /\[quote=([^;]*?)\](.*?)\[\/quote\]/g;;
  62. text = text.replace(re, '<blockquote class="bb_blockquote with_author"><div class="bb_quoteauthor"><b>$1</b>:</div>$2</blockquote>');
  63. console.log(text);
  64. re = /\[quote=([^;]*?);(\d*)\](.*?)\[\/quote\]/g;;
  65. text = text.replace(re, '<blockquote class="bb_blockquote with_author"><div class="bb_quoteauthor"><b><a href="#c$2">$1</a></b>:</div>$3</blockquote>');
  66. console.log(text);
  67. re = /\[quote\](.*?)\[\/quote\]/g;;
  68. text = text.replace(re, '<blockquote class="bb_blockquote"><div class="bb_quoteauthor"><b>$1</b>:</div>$2</blockquote>');
  69. console.log(text);
  70. re = /\[code\](.*?)\[\/code\]/g;
  71. text = text.replace(re, '<div class="bb_code">$1</div>');
  72. /*
  73. we still miss:
  74. - steam store widgets;
  75. - user content widgets;
  76. - youtube widgets;
  77. - numbered lists;
  78. - not numbered lists;
  79. */
  80. let index = 0;
  81. re = /\[noparse\](.*?)\[\/noparse\]/g;
  82. text = text.replace(re,() => noparse[index++]);
  83. console.log(text);
  84. return text;
  85. }
  86.  
  87. function FixComments (comments){
  88. for (let i=comments.length-1; i>=0; i--) {
  89. let parent = comments[i].parentNode;
  90. let gidComment = parent.id.split('_')[2];
  91. parent.innerHTML = FormatBBCode(GetText( gidTopic, gidComment));
  92. }
  93. }
  94.  
  95. let re = /.*discussions\/\d+\/(\d+)/g;
  96. let res = re.exec(document.URL);
  97. if (res===null){
  98. re = /.*forum\/\d+\/(\d+)/g;
  99. res = re.exec(document.URL);
  100. }
  101. let gidTopic = res[1];
  102. let comments = document.getElementsByClassName('needs_content_check');
  103. FixComments(comments);
  104.  
  105. let mutationObserver = new MutationObserver(function(mutations) {
  106. mutations.forEach(function(mutation) {
  107. mutation.addedNodes.forEach( function(currentValue, currentIndex, listObj) {
  108. if (currentValue.nodeType == Node.ELEMENT_NODE) {
  109. let comments = currentValue.querySelectorAll("div[class^='needs_content_check']");
  110. FixComments(comments);
  111. }
  112. });
  113. });
  114. });
  115. mutationObserver.observe(document.documentElement, {
  116. childList: true,
  117. subtree: true
  118. });
  119.  
  120. })();