Iwara Extension Script

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

目前為 2017-04-06 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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
// @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 doforimage = true; // 静画もする?
  var likemaxi = 50; // Likeバーのカンスト上限。静画ページ
  var ratiomaxi = 4; // Like率バーのカンスト上限。単位パーセント。静画ページ
  
  var NGWords = [ // NGワード。ほおりこめー
    'わたしがNGワードだ',
    'シングルクォートで囲って、最後にカンマを忘れずに',
    'NG索敵範囲は該当箇所のHTMLソース全てです',
    'タイトルも投稿者名も含みます',
    /こうやってシングルクォートの代わりにスラッシュを使うと、正規表現もできます/,
    '↓とりあえず作者をNGに入れてみるテスト↓',
    'conn',
    '↑できれば外してくれると嬉しいな…↑',
    'この最後の行だけはカンマ無しで'
  ];
  // ここから開発用
  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 (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 (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();