Daily Stormer Comments

9/01/2021, 11:35:12 AM

  1. // ==UserScript==
  2. // @name Daily Stormer Comments
  3. // @namespace Violentmonkey Scripts
  4. // @match https://dailystormer.su/*
  5. // @grant GM.xmlHttpRequest
  6. // @grant GM.notification
  7. // @grant unsafeWindow
  8. // @version 1.1
  9. // @author perception
  10. // @description 9/01/2021, 11:35:12 AM
  11. // ==/UserScript==
  12.  
  13. function get(url, fn) {
  14. const method = 'GET'
  15. return GM.xmlHttpRequest({
  16. method,
  17. url,
  18. onload: fn
  19. })
  20. }
  21.  
  22. function getArticlesForum(fn) {
  23. const url = 'https://gameruprising.to/index.php?forums/articles.5/'
  24. return get(url, fn)
  25. }
  26.  
  27. function escape(s) {
  28. return s.replace(/\$/g, '\\$')
  29. }
  30.  
  31. // Get Title of Article
  32. const metaTitle = document.querySelector('head meta[property="og:title"]')
  33. if (metaTitle) {
  34. const title = metaTitle.content.replace(/ - Daily Stormer/, '')
  35. const re = new RegExp(escape(title), 'i')
  36.  
  37. // Convert to XenForo Slug
  38. const xenforoTitle = encodeURIComponent(title.toLocaleLowerCase().replace(/\s+/g, '-'))
  39. console.log({title, xenforoTitle})
  40. //GM.notification(title, xenforoTitle)
  41.  
  42. // Search for Forum Post for Article
  43. getArticlesForum(function(res) {
  44. unsafeWindow.res = res
  45. const $forum = jQuery(res.responseText)
  46. const $threads = $forum.find('div.structItem-title a').filter(function(i) {
  47. const content = jQuery(this).text().trim()
  48. console.log({title, content, equal: title === content })
  49. return !!content.match(re)
  50. })
  51. unsafeWindow.$forum = $forum
  52. unsafeWindow.$threads = $threads
  53.  
  54. // If found, scrape thread for comments
  55. if ($threads.length > 0) {
  56. const a = $threads[0]
  57. const threadUrl = `https://gameruprising.to${a.pathname}${a.search}`
  58. get(threadUrl, function(res) {
  59. const $thread = jQuery(res.responseText)
  60. unsafeWindow.$thread = $thread
  61. const $posts = $thread.find('article.message:not(:first)')
  62. $posts.each(function(i, p) {
  63. const $p = jQuery(p)
  64. const $a = $p.find('a.avatar')
  65. $a.attr('href', `https://gameruprising.to${$a.attr('href')}`)
  66. const $img = $a.find('img')
  67. $img.attr('src', `https://gameruprising.to${$img.attr('src')}`)
  68. if ($img.attr('srcset')) {
  69. // Some profiles don't have srcset for their avatar image.
  70. $img.attr('srcset', `https://gameruprising.to${$img.attr('srcset')}`)
  71. }
  72. const $name = $p.find('.message-name a.username')
  73. $name.attr('href', `https://gameruprising.to${$name.attr('href')}`)
  74. const $timestamp = $p.find('.message-attribution-main a')
  75. $timestamp.attr('href', `https://gameruprising.to${$timestamp.attr('href')}`)
  76. const $postNumber = $p.find('.message-attribution-opposite a:nth(1)')
  77. $postNumber.attr('href', `https://gameruprising.to${$postNumber.attr('href')}`)
  78. const $reactions = $p.find('a.reactionsBar-link')
  79. $reactions.attr('href', `https://gameruprising.to${$reactions.attr('href')}`)
  80. })
  81. unsafeWindow.$posts = $posts
  82. // Insert comments onto current page
  83. jQuery('article.post-listing').append($posts)
  84. })
  85. }
  86. })
  87. }
  88.  
  89. // Add CSS
  90. var css = `
  91. .reaction--small.reaction--1 .reaction-sprite {
  92. width: 16px;
  93. height: 16px;
  94. background: url(https://gameruprising.to/styles/default/xenforo/reactions/emojione/sprite_sheet_emojione.png) no-repeat 0px 0px;
  95. background-size: 100%;
  96. }
  97. .reaction--small.reaction--2 .reaction-sprite {
  98. width: 16px;
  99. height: 16px;
  100. background: url(https://gameruprising.to/styles/default/xenforo/reactions/emojione/sprite_sheet_emojione.png) no-repeat 0px -16px;
  101. background-size: 100%;
  102. }
  103. .reaction--small.reaction--3 .reaction-sprite {
  104. width: 16px;
  105. height: 16px;
  106. background: url(https://gameruprising.to/styles/default/xenforo/reactions/emojione/sprite_sheet_emojione.png) no-repeat 0px -32px;
  107. background-size: 100%;
  108. }
  109. .reaction--small.reaction--4 .reaction-sprite {
  110. width: 16px;
  111. height: 16px;
  112. background: url(https://gameruprising.to/styles/default/xenforo/reactions/emojione/sprite_sheet_emojione.png) no-repeat 0px -48px;
  113. background-size: 100%;
  114. }
  115. .reaction--small.reaction--5 .reaction-sprite {
  116. width: 16px;
  117. height: 16px;
  118. background: url(https://gameruprising.to/styles/default/xenforo/reactions/emojione/sprite_sheet_emojione.png) no-repeat 0px -64px;
  119. background-size: 100%;
  120. }
  121. .reaction--small.reaction--6 .reaction-sprite {
  122. width: 16px;
  123. height: 16px;
  124. background: url(https://gameruprising.to/styles/default/xenforo/reactions/emojione/sprite_sheet_emojione.png) no-repeat 0px -80px;
  125. background-size: 100%;
  126. }
  127. .reaction--small.reaction--7 .reaction-sprite {
  128. width: 16px;
  129. height: 16px;
  130. background: url(https://gameruprising.to/styles/default/xenforo/reactions/emojione/sprite_sheet_emojione.png) no-repeat 0px -96px;
  131. background-size: 100%;
  132. }
  133.  
  134. article.message {
  135. margin: 0.5em;
  136. padding: 1em;
  137. border-top: 2px solid #000;
  138. }
  139. article.message .bbCodeBlock-expandLink {
  140. display: none;
  141. }
  142. `;
  143. if (typeof GM_addStyle != "undefined") {
  144. GM_addStyle(css);
  145. } else if (typeof PRO_addStyle != "undefined") {
  146. PRO_addStyle(css);
  147. } else if (typeof addStyle != "undefined") {
  148. addStyle(css);
  149. } else {
  150. var node = document.createElement("style");
  151. node.type = "text/css";
  152. node.appendChild(document.createTextNode(css));
  153. var heads = document.getElementsByTagName("head");
  154. if (heads.length > 0) {
  155. heads[0].appendChild(node);
  156. } else {
  157. // no head yet, stick it whereever
  158. document.documentElement.appendChild(node);
  159. }
  160. }