Show not checked content

Shows content hidden by Valve's automated content check system

当前为 2021-10-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Show not checked content
  3. // @namespace https://greasyfork.org/users/2205
  4. // @version 0.7
  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. // @run-at document-idle
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. /* global g_rgForumTopicCommentThreads */
  17. /* global g_rgForumTopics*/
  18. function GetText( gidTopic, gidComment )
  19. {
  20. var CommentThread = g_rgForumTopicCommentThreads[gidTopic];
  21. var rgRawComment;
  22. if ( gidComment && gidComment != -1 )
  23. {
  24. rgRawComment = CommentThread.GetRawComment( gidComment );
  25. }
  26. else
  27. {
  28. // topic quoting
  29. rgRawComment = g_rgForumTopics[gidTopic].m_rgRawData;
  30. }
  31. return rgRawComment.text;
  32. }
  33.  
  34. function FormatBBCode(text){
  35. let re = /\[noparse\]([\s\S]*?)\[\/noparse\]/g;
  36. let noparse = text.match(re);
  37. re = /([^\]])\n([^\[])/g;
  38. text = text.replace(re, '$1<br>$2');
  39. re = /\[h1\]([\s\S]*?)\[\/h1\]/g;
  40. text = text.replace(re, '<div class="bb_h1">$1</div>');
  41. re = /\[b\]([\s\S]*?)\[\/b\]/g;
  42. text = text.replace(re, '<b>$1</b>');
  43. re = /\[u\]([\s\S]*?)\[\/u\]/g;
  44. text = text.replace(re, '<u>$1</u>');
  45. re = /\[i\]([\s\S]*?)\[\/i\]/g;
  46. text = text.replace(re, '<i>$1</i>');
  47. re = /\[strike\]([\s\S]*?)\[\/strike\]/g;
  48. text = text.replace(re, '<span class="bb_strike">$1</span>');
  49. re = /\[spoiler\]([\s\S]*)\[\/spoiler\]/g;
  50. text = text.replace(re, '<span class="bb_spoiler"><span>$1</span></span>');
  51. re = /\[url=(.*?)\]([\s\S]*?)\[\/url\]/g;
  52. text = text.replace(re, '<a class="bb_link" href="$1" target="_blank" rel="noreferrer">$2</a>');
  53. re = /([^>"]|^)https?:\/\/store\.steampowered\.com\/app\/(\d*)[^\s]*/g;
  54. text = text.replace(re, '$1<br/><iframe src="https://store.steampowered.com/widget/$2/?dynamiclink=1" width="100%" height="190" frameborder="0"></iframe>');
  55. re = /([^>"]|^)(http|https|ftp)(:\/\/[^\s]*)/g;
  56. text = text.replace(re, '$1<a class="bb_link" href="$2$3" target="_blank" rel="noreferrer">$2$3</a>');
  57. re = /\[quote=([^;]*?)\]([\s\S]*?)\[\/quote\]/g;
  58. text = text.replace(re, '<blockquote class="bb_blockquote with_author"><div class="bb_quoteauthor">Originally posted by <b>$1</b>:</div>$2</blockquote>');
  59. re = /\[quote=([^;]*?);(\d*)\]([\s\S]*?)\[\/quote\]/g;
  60. text = text.replace(re, '<blockquote class="bb_blockquote with_author"><div class="bb_quoteauthor">Originally posted by <b><a href="#c$2">$1</a></b>:</div>$3</blockquote>');
  61. re = /\[quote\]([\s\S]*?)\[\/quote\]/g;
  62. text = text.replace(re, '<blockquote class="bb_blockquote">$1</blockquote>');
  63. re = /\[code\]([\s\S]*?)\[\/code\]/g;
  64. text = text.replace(re, '<div class="bb_code">$1</div>');
  65. re = /\[list\]([\s\S]*?)\[\/list\]/gm;
  66. text = text.replace(re, '<ul class="bb_ul">$1</ul>');
  67. re = /\[olist\]([\s\S]*?)\[\/olist\]/gm;
  68. text = text.replace(re, '<ol>$1</ol>');
  69. re = /\[\*\]([\s\S]*?)$/gm;
  70. text = text.replace(re, '<li>$1</li>');
  71. let index = 0;
  72. re = /\[noparse\]([\s\S]*?)\[\/noparse\]/g;
  73. text = text.replace(re,() => noparse[index++]);
  74. return text;
  75. }
  76.  
  77. function FixComments (comments){
  78. for (let i=comments.length-1; i>=0; i--) {
  79. let parent = comments[i].parentNode;
  80. let gidComment = parent.id.split('_')[2];
  81. parent.innerHTML = FormatBBCode(GetText( gidTopic, gidComment));
  82. //add a notice
  83. let noticeDiv = document.createElement("span");
  84. noticeDiv.className = "forum_comment_author_banned";
  85. noticeDiv.appendChild(document.createTextNode("(post awaiting analysis)"));
  86. parent.parentElement.querySelector("div.forum_author_menu").after(noticeDiv);
  87. }
  88. }
  89.  
  90. let re = /.*discussions\/\d+\/(\d+)/g;
  91. let res = re.exec(document.URL);
  92. if (res===null){
  93. re = /.*forum\/\d+\/(\d+)/g;
  94. res = re.exec(document.URL);
  95. }
  96. let gidTopic = res[1];
  97. let comments = document.getElementsByClassName('needs_content_check');
  98. FixComments(comments);
  99.  
  100. let mutationObserver = new MutationObserver(function(mutations) {
  101. mutations.forEach(function(mutation) {
  102. mutation.addedNodes.forEach( function(currentValue, currentIndex, listObj) {
  103. if (currentValue.nodeType == Node.ELEMENT_NODE) {
  104. let comments = currentValue.querySelectorAll("div[class^='needs_content_check']");
  105. FixComments(comments);
  106. }
  107. });
  108. });
  109. });
  110. mutationObserver.observe(document.documentElement, {
  111. childList: true,
  112. subtree: true
  113. });
  114.  
  115. })();