Iwara Extension Script

IwaraのLike数とLike率を可視化。あとNG機能

Fra og med 07.04.2017. Se den nyeste version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Iwara Extension Script
// @name:en        Iwara Extension Script
// @namespace   https://greasyfork.org/ja/users/115273-conn
// @description IwaraのLike数とLike率を可視化。あとNG機能
// @description:en Visualize Like and Like Ratio, and add NG function in iwara.tv
// @include     http://ecchi.iwara.tv/*
// @include     http://www.iwara.tv/*
// @version     1.1
// @grant       none
// ==/UserScript==

var main = function () {
  
  // パラメータ設定
  var likemax = 200; // Likeバーのカンスト上限
  var ratiomax = 3; // Like率バーのカンスト上限。単位パーセント
  var borderthickness = 5; // 枠の太さ。ピクセル単位
  
  var doNG = true; // NGする?
  var NGopacity = '0.2'; // NGしたのの透明度。0(不可視)~1(通常)
  var NGdispparam = false; // NGのやつもバー表示する?

  var doEM = true;  // 強調する?
  var emRGB = 'ffff77';  // 強調したのの背景色。rrggbb

  var doforimage = true; // 静画もする?
  var likemaxi = 50; // Likeバーのカンスト上限。静画ページ
  var ratiomaxi = 4; // Like率バーのカンスト上限。単位パーセント。静画ページ
  
  var NGWords = [ // NGワード。ほおりこめー
    'わたしがNGワードだ',
    'こんなふうにシングルクォートで囲って、最後にカンマを忘れずに',
    'NG索敵範囲は該当箇所のHTMLソース全てです',
    'タイトルも投稿者名も含みます',
    '↓とりあえず作者をNGに入れてみるテスト↓',
    'conn',
    '↑できれば外してくれると嬉しいな…↑',
    /こうやってシングルクォートの代わりにスラッシュを使うと、正規表現もできます/,
    'このへんの説明、理解したら消しちゃってくださいね',
    'この最後の行だけはカンマ無しで'
  ];
  
  var EMWords = [ // 強調ワード。大好き
    'わたしが強調ワードだ',
    'NGワードと同様です',
    '好きな投稿者やモデルを登録すると良いんじゃないかな',
    'やっぱりこの最後の行もカンマ無しで'
  ];
  
  // ここから開発用
  var likes = null;
  var disps = null;
  var likeadd = null;
  var ratioadd = null;
  var dispnum = 0;
  var likenum = 0;
  var ratio = 0;
  var likewidth = 0;
  var ratiowidth = 0;
  var likenR = 0;
  var rationB = 0;
  var likeRGB = null;
  var ratioRGB = null;
  var dummy = null;
  var bodyedit = null;
  var nghit = false;
  
  // 動画ページ
  var divs = document.body.getElementsByClassName('node node-video node-teaser node-teaser clearfix');
  for (i = 0; i < divs.length; i++) {
    bodyedit = divs[i].innerHTML;
    if (doNG) {
      nghit = false;
      for (j = 0; j < NGWords.length; j++) {
        dummy = null;
        dummy = bodyedit.match(NGWords[j]);
        if (dummy != null) {
          bodyedit = '<div style="opacity: ' + NGopacity + '">' + bodyedit + '</div>';
          nghit = true;
          j = NGWords.length;
        }
      }
    }
    
    if (doEM) {
      for (j = 0; j < EMWords.length; j++) {
        dummy = null;
        dummy = bodyedit.match(EMWords[j]);
        if (dummy != null) {
          bodyedit = '<div style="background-color: #' + emRGB + '">' + bodyedit + '</div>';
          j = EMWords.length;
        }
      }
    }
    
    if (NGdispparam || nghit == false) {
      likes = bodyedit.match(/heart\"><\/i> (\d+)/);
      disps = bodyedit.match(/open\"><\/i> ([0-9\.]+)k/);
      if (disps != null) {
        dispnum = parseFloat(disps[1]) * 1000;
      } else {
        disps = bodyedit.match(/open\"><\/i> ([0-9]+)/);
        dispnum = parseFloat(disps[1]);
      }
      if (likes != null) {
        likenum = parseInt(likes[1]);
        ratio = 100 * likenum / dispnum;
        likewidth = Math.min(Math.floor(likenum * 70 / likemax + 40), 110);
        ratiowidth = Math.min(Math.floor(ratio * 70 / ratiomax + 40), 110);
        likenR = 255 - Math.min(Math.floor(likenum * 245 / likemax + 10), 255);
        rationB = 255 - Math.min(Math.floor(ratio * 245 / ratiomax + 10), 255);
        likeRGB = 'ff' + ('0' + likenR.toString(16)).slice( - 2) + ('0' + likenR.toString(16)).slice( - 2);
        ratioRGB = ('0' + rationB.toString(16)).slice( - 2) + ('0' + rationB.toString(16)).slice( - 2) + 'ff';
        likeadd = 'right-icon likes-icon" align="right" style="width: ' + likewidth.toString() + 'px; background: #' + likeRGB + '"';
        ratioadd = '$&<br>\n\t\t\t<div class="right-icon likes-icon" align="right" style="width: ' + ratiowidth.toString() + 'px; background: #' + ratioRGB + '">' + (ratio.toFixed(1)).toString() + '%</div>';
        bodyedit = bodyedit.replace(/right-icon likes-icon\"/, likeadd);
        bodyedit = bodyedit.replace(/open.*div>/, ratioadd);
        bodyedit = bodyedit.replace(/height=\"150\"/, 'height="150" style="border:solid ' + borderthickness + 'px #' + likeRGB + '"');
      }
    }
    divs[i].innerHTML = bodyedit;
  }
  
  // 静画ページ
  if (doforimage) {
    divs = document.body.getElementsByClassName('node node-image node-teaser node-teaser clearfix');
    for (i = 0; i < divs.length; i++) {
      bodyedit = divs[i].innerHTML;
      if (doNG) {
        nghit = false;
        for (j = 0; j < NGWords.length; j++) {
          dummy = null;
          dummy = bodyedit.match(NGWords[j]);
          if (dummy != null) {
            bodyedit = '<div style="opacity: ' + NGopacity + '">' + bodyedit + '</div>';
            nghit = true;
            j = NGWords.length;
          }
        }
      }

      if (doEM) {
        for (j = 0; j < EMWords.length; j++) {
          dummy = null;
          dummy = bodyedit.match(EMWords[j]);
          if (dummy != null) {
            bodyedit = '<div style="background-color: #' + emRGB + '">' + bodyedit + '</div>';
            j = EMWords.length;
          }
        }
      }

      if (NGdispparam || nghit == false) {
        likes = bodyedit.match(/heart\"><\/i> (\d+)/);
        disps = bodyedit.match(/open\"><\/i> ([0-9\.]+)k/);
        if (disps != null) {
          dispnum = parseFloat(disps[1]) * 1000;
        } else {
          disps = bodyedit.match(/open\"><\/i> ([0-9]+)/);
          dispnum = parseFloat(disps[1]);
        }
        if (likes != null) {
          likenum = parseInt(likes[1]);
          ratio = 100 * likenum / dispnum;
          likewidth = Math.min(Math.floor(likenum * 70 / likemaxi + 40), 110);
          ratiowidth = Math.min(Math.floor(ratio * 70 / ratiomaxi + 40), 110);
          likenR = 255 - Math.min(Math.floor(likenum * 245 / likemaxi + 10), 255);
          rationB = 255 - Math.min(Math.floor(ratio * 245 / ratiomaxi + 10), 255);
          likeRGB = 'ff' + ('0' + likenR.toString(16)).slice( - 2) + ('0' + likenR.toString(16)).slice( - 2);
          ratioRGB = ('0' + rationB.toString(16)).slice( - 2) + ('0' + rationB.toString(16)).slice( - 2) + 'ff';
          likeadd = 'right-icon likes-icon" align="right" style="width: ' + likewidth.toString() + 'px; background: #' + likeRGB + '"';
          ratioadd = '$&<br>\n\t\t\t<div class="right-icon likes-icon" align="right" style="width: ' + ratiowidth.toString() + 'px; background: #' + ratioRGB + '">' + (ratio.toFixed(1)).toString() + '%</div>';
          bodyedit = bodyedit.replace(/right-icon likes-icon\"/, likeadd);
          bodyedit = bodyedit.replace(/open.*div>/, ratioadd);
          bodyedit = bodyedit.replace(/height=\"150\"/, 'height="150" style="border:solid ' + borderthickness + 'px #' + likeRGB + '"');
        }
      }
      divs[i].innerHTML = bodyedit;
    }
  }
};
main();