Daily Stormer Comments

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Daily Stormer Comments
// @namespace   Violentmonkey Scripts
// @match       https://dailystormer.su/*
// @grant       GM.xmlHttpRequest
// @grant       GM.notification
// @grant       unsafeWindow
// @version     1.1
// @author      perception
// @description 9/01/2021, 11:35:12 AM
// ==/UserScript==

function get(url, fn) {
  const method = 'GET'
  return GM.xmlHttpRequest({
    method,
    url,
    onload: fn
  })
}

function getArticlesForum(fn) {
  const url = 'https://gameruprising.to/index.php?forums/articles.5/'
  return get(url, fn)
}

function escape(s) {
  return s.replace(/\$/g, '\\$')
}

// Get Title of Article
const metaTitle = document.querySelector('head meta[property="og:title"]')
if (metaTitle) {
  const title = metaTitle.content.replace(/ - Daily Stormer/, '')
  const re    = new RegExp(escape(title), 'i')

  // Convert to XenForo Slug
  const xenforoTitle = encodeURIComponent(title.toLocaleLowerCase().replace(/\s+/g, '-'))
  console.log({title, xenforoTitle})
  //GM.notification(title, xenforoTitle)

  // Search for Forum Post for Article
  getArticlesForum(function(res) {
    unsafeWindow.res = res
    const $forum = jQuery(res.responseText)
    const $threads = $forum.find('div.structItem-title a').filter(function(i) {
      const content = jQuery(this).text().trim()
      console.log({title, content, equal: title === content })
      return !!content.match(re)
    })
    unsafeWindow.$forum = $forum
    unsafeWindow.$threads = $threads

    //   If found, scrape thread for comments
    if ($threads.length > 0) {
      const a = $threads[0]
      const threadUrl = `https://gameruprising.to${a.pathname}${a.search}`
      get(threadUrl, function(res) {
        const $thread = jQuery(res.responseText)
        unsafeWindow.$thread = $thread
        const $posts = $thread.find('article.message:not(:first)')
        $posts.each(function(i, p) {
          const $p = jQuery(p)
          const $a = $p.find('a.avatar')
          $a.attr('href', `https://gameruprising.to${$a.attr('href')}`)
          const $img = $a.find('img')
          $img.attr('src', `https://gameruprising.to${$img.attr('src')}`)
          if ($img.attr('srcset')) {
            // Some profiles don't have srcset for their avatar image.
            $img.attr('srcset', `https://gameruprising.to${$img.attr('srcset')}`)
          }
          const $name = $p.find('.message-name a.username')
          $name.attr('href', `https://gameruprising.to${$name.attr('href')}`)
          const $timestamp = $p.find('.message-attribution-main a')
          $timestamp.attr('href', `https://gameruprising.to${$timestamp.attr('href')}`)
          const $postNumber = $p.find('.message-attribution-opposite a:nth(1)')
          $postNumber.attr('href', `https://gameruprising.to${$postNumber.attr('href')}`)
          const $reactions = $p.find('a.reactionsBar-link')
          $reactions.attr('href', `https://gameruprising.to${$reactions.attr('href')}`)
        })
        unsafeWindow.$posts = $posts
        //   Insert comments onto current page
        jQuery('article.post-listing').append($posts)
      })
    }
  })
}

// Add CSS
var css = `
.reaction--small.reaction--1 .reaction-sprite {
  width: 16px;
  height: 16px;
  background: url(https://gameruprising.to/styles/default/xenforo/reactions/emojione/sprite_sheet_emojione.png) no-repeat 0px 0px;
  background-size: 100%;
}
.reaction--small.reaction--2 .reaction-sprite {
  width: 16px;
  height: 16px;
  background: url(https://gameruprising.to/styles/default/xenforo/reactions/emojione/sprite_sheet_emojione.png) no-repeat 0px -16px;
  background-size: 100%;
}
.reaction--small.reaction--3 .reaction-sprite {
  width: 16px;
  height: 16px;
  background: url(https://gameruprising.to/styles/default/xenforo/reactions/emojione/sprite_sheet_emojione.png) no-repeat 0px -32px;
  background-size: 100%;
}
.reaction--small.reaction--4 .reaction-sprite {
  width: 16px;
  height: 16px;
  background: url(https://gameruprising.to/styles/default/xenforo/reactions/emojione/sprite_sheet_emojione.png) no-repeat 0px -48px;
  background-size: 100%;
}
.reaction--small.reaction--5 .reaction-sprite {
  width: 16px;
  height: 16px;
  background: url(https://gameruprising.to/styles/default/xenforo/reactions/emojione/sprite_sheet_emojione.png) no-repeat 0px -64px;
  background-size: 100%;
}
.reaction--small.reaction--6 .reaction-sprite {
  width: 16px;
  height: 16px;
  background: url(https://gameruprising.to/styles/default/xenforo/reactions/emojione/sprite_sheet_emojione.png) no-repeat 0px -80px;
  background-size: 100%;
}
.reaction--small.reaction--7 .reaction-sprite {
  width: 16px;
  height: 16px;
  background: url(https://gameruprising.to/styles/default/xenforo/reactions/emojione/sprite_sheet_emojione.png) no-repeat 0px -96px;
  background-size: 100%;
}

article.message {
  margin: 0.5em;
  padding: 1em;
  border-top: 2px solid #000;
}
article.message .bbCodeBlock-expandLink {
  display: none;
}
`;
if (typeof GM_addStyle != "undefined") {
  GM_addStyle(css);
} else if (typeof PRO_addStyle != "undefined") {
  PRO_addStyle(css);
} else if (typeof addStyle != "undefined") {
  addStyle(css);
} else {
  var node = document.createElement("style");
  node.type = "text/css";
  node.appendChild(document.createTextNode(css));
  var heads = document.getElementsByTagName("head");
  if (heads.length > 0) {
    heads[0].appendChild(node);
  } else {
    // no head yet, stick it whereever
    document.documentElement.appendChild(node);
  }
}