Iwara Extension Script

Like数とLike率をバー表示。あとNG機能と強調機能

La data de 07-04-2017. Vezi ultima versiune.

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 Like数とLike率をバー表示。あとNG機能と強調機能
// @description:en Adding Like and Like Ratio bars, BlackList, and FavList.
// @include     http://ecchi.iwara.tv/*
// @include     http://www.iwara.tv/*
// @version     1.2
// @grant       none
// ==/UserScript==

var main = function () {
  
  // パラメータ設定
  var likebaropacity = '0.8'; // Likeバーと枠の透明度。0(実質バー表示オフ)~1(通常)
  var ratiotextopacity = '1.0'; // Like率テキストの透明度。0(実質バー表示オフ)~1(通常)
  var ratiobaropacity = '0.5'; // Like率バーの透明度。0(実質バー表示オフ)~1(通常)
  var borderthickness = '5'; // 枠の太さ。単位ピクセル。0なら枠なし
  var likemax = 200; // Likeバーのカンスト上限
  var ratiomax = 3; // Like率バーのカンスト上限。単位パーセント
  
  var NGopacity = '0.3'; // NGしたやつの透明度。0(完全非表示)~1(実質NGオフ)
  var NGdispstat = true; // NGのやつもバー表示する?

  var emRGB = 'ffff77';  // 強調したやつの背景色。rrggbb。'ffffff' (白背景)なら実質強調オフ

  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 likeRGBA = null;
  var ratioRGBA = 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;
    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;
      }
    }
    
    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 (NGdispstat || 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]);
        likewidth = Math.min(Math.floor(likenum * 70 / likemax + 40), 110);
        likenR = 255 - Math.min(Math.floor(likenum * 205 / likemax + 50), 255);
        likeRGBA = '255,' + likenR.toString()+ ',' + likenR.toString() + ',' + likebaropacity;
        likeadd = 'right-icon likes-icon" align="right" style="width: ' + likewidth.toString() + 'px; background-color: rgba\(' + likeRGBA + '\)"';
        bodyedit = bodyedit.replace(/right-icon likes-icon\"/, likeadd);
        ratio = 100 * likenum / dispnum;
        ratiowidth = Math.min(Math.floor(ratio * 70 / ratiomax + 40), 110);
        rationB = 255 - Math.min(Math.floor(ratio * 205 / ratiomax + 50), 255);
        ratioRGBA = rationB.toString()+ ',' + rationB.toString() + ',255,' + ratiobaropacity;
        ratioadd = '$&<br>\n\t\t\t<div class="right-icon likes-icon" align="right" style="width: ' + ratiowidth.toString() + 'px; background: rgba\(' + ratioRGBA + '\)"><span style="opacity: ' + ratiotextopacity + '">' + (ratio.toFixed(1)).toString() + '%</span></div>';
        bodyedit = bodyedit.replace(/open.*div>/, ratioadd);
        bodyedit = bodyedit.replace(/height=\"150\"/, 'height="150" style="border:solid ' + borderthickness + 'px rgba\(' + likeRGBA + '\)"');
      }
    }
    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;
      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;
        }
      }

      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 (NGdispstat || 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]);
          likewidth = Math.min(Math.floor(likenum * 70 / likemaxi + 40), 110);
          likenR = 255 - Math.min(Math.floor(likenum * 205 / likemaxi + 50), 255);
          likeRGBA = '255,' + likenR.toString()+ ',' + likenR.toString() + ',' + likebaropacity;
          likeadd = 'right-icon likes-icon" align="right" style="width: ' + likewidth.toString() + 'px; background-color: rgba\(' + likeRGBA + '\)"';
          bodyedit = bodyedit.replace(/right-icon likes-icon\"/, likeadd);
          ratio = 100 * likenum / dispnum;
          ratiowidth = Math.min(Math.floor(ratio * 70 / ratiomax + 40), 110);
          rationB = 255 - Math.min(Math.floor(ratio * 205 / ratiomax + 50), 255);
          ratioRGBA = rationB.toString()+ ',' + rationB.toString() + ',255,' + ratiobaropacity;
          ratioadd = '$&<br>\n\t\t\t<div class="right-icon likes-icon" align="right" style="width: ' + ratiowidth.toString() + 'px; background: rgba\(' + ratioRGBA + '\)"><span style="opacity: ' + ratiotextopacity + '">' + (ratio.toFixed(1)).toString() + '%</span></div>';
          bodyedit = bodyedit.replace(/open.*div>/, ratioadd);
          bodyedit = bodyedit.replace(/height=\"150\"/, 'height="150" style="border:solid ' + borderthickness + 'px rgba\(' + likeRGBA + '\)"');
        }
      }
      divs[i].innerHTML = bodyedit;
    }
  }
};
main();