HSPTV! Forum Script

HSPTV!掲示板用のUserScriptです。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         HSPTV! Forum Script
// @version      1.1.2
// @description  HSPTV!掲示板用のUserScriptです。
// @author       prince
// @homepage     http://prince0203.github.io/
// @copyright    (c)prince 2016
// @namespace    io.github.prince0203
// @icon         http://hsp.tv/favicon.ico
// @match        http://hsp.tv/play/pforum.php?mode=*
// @run-at       document-end
// @grant        none
// @require      https://code.jquery.com/jquery-3.1.1.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.10.0/highlight.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.10.0/languages/hsp.min.js
// ==/UserScript==

// 設定
var option = {
  // 長いソースがあるときでも表示が崩れないようにする(デフォルト: true)
  "fixDisplay": true,

  // 投稿にHPがない場合「HP」画像を削除する(デフォルト: true)
  "noHpImage": true,

  // 投稿者のIPアドレスを表示する(デフォルト: true)
  "ip": true,

  // ソースコードをhighlight.jsを使用して色分けする(デフォルト: true)
  "highlight": true,

  // highlight.jsのテーマ https://highlightjs.org/static/demo/ を参照(デフォルト: Dark)
  "highlightTheme": "Dark"
};

// 長いソースがあるときでも表示が崩れないようにする
if (option.fixDisplay) {
  $('table[background^="../images/bbs/back"]').css('table-layout', 'fixed');
  $('pre > br').remove();
  if(!option.highlight) {
    $('pre').css({
      'border-radius': '5px',
      'box-shadow': '0px 0px 3px 2px rgba(0, 0, 0, 0.15)',
      'margin': '10px',
      'padding': '10px',
      'color': '#5A5A5A',
      'background-color': '#F8F8F8',
      'overflow': 'auto'
    });
  }
}

// HPがない場合画像を削除
if (option.noHpImage) {
  $('div#info')
    .append('<br>')
    .children('img[src="../images/bbs/icon_hp_g_no.gif"], img[src="../images/bbs/icon_hp_no.gif"]')
    .remove();
}

// IPアドレスを表示
if (option.ip) {
  var comments = document.body.innerHTML.match(/<!--.*-->/g);
  $(comments).each(function(index) {
    comments[index] = this.substr(4);
    comments[index] = comments[index].substr(0, (comments[index].length - 3));
  });

  $('div#info').each(function(index) {
    $(this).append(comments[index]);
  });
}

// highlight.js
if (option.highlight) {
  $('pre')
    .css('margin', '0px')
    .wrapInner('<code/>')
    .children('code')
    .css({
    'margin': '10px',
    'padding': '10px',
    'border-radius': '8px',
    'box-shadow': '0px 0px 3px 2px rgba(0, 0, 0, 0.15)',
    'font-size': '1.2em'
  })
    .each(function() {
      $(this).text($(this).text().substr(1));
    });
  $('head').append('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.10.0/styles/' + option.highlightTheme.toLowerCase().replace(/ /g, '-') + '.min.css">');

  hljs.initHighlightingOnLoad();
}