// ==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.4
// @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 borderopacity = '0.8'; // 枠の透明度。0(不可視)~1(通常)
var likemax = 200; // Likeバーのカンスト上限
var ratiomax = 3.0; // Like率バーのカンスト上限。単位パーセント
var NGopacity = '0.3'; // NGしたやつの透明度。0(完全非表示)~1(実質NGオフ)
var NGdispstat = true; // NGのやつもバー表示する?
var showNGword = true; // ヒットしたNGワードを表示する?
var emRGB = 'ffff77'; // 強調したやつの背景色。rrggbb。'ffffff' (白背景)なら実質強調オフ
var showEMword = true; // ヒットした強調ワードを表示する?
var doforimage = true; // 静画もする?
var likemaxi = 50; // 静画ページでのLikeバーのカンスト上限
var ratiomaxi = 4.0; // 静画ページでのLike率バーのカンスト上限。単位パーセント
var NGWords = [ // NGワード。ほおりこめー
'わたしがNGワードだ',
'こんなふうにシングルクォートで囲って、最後にカンマを忘れずに',
'NG索敵範囲は該当箇所のHTMLソース全てです',
'タイトルも投稿者名も含みます',
'↓とりあえず作者をNGに入れてみるテスト↓',
'conn',
'↑できれば外してくれると嬉しいな…↑',
/こうやってシングルクォートの代わりにスラッシュを使うと、正規表現もできます/,
'このへんの説明、理解したら消しちゃってくださいね',
'この最後の行だけはカンマ無しで'
];
var EMWords = [ // 強調ワード。大好き
'わたしが強調ワードだ',
'NGワードと同様です',
'好きな投稿者やモデルを登録すると良いんじゃないかな',
'やっぱりこの最後の行もカンマ無しで'
];
//// ここから開発用 ////
// 初期化
var likes = null;
var disps = null;
var likebarstr = null;
var ratiobarstr = 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 ratioRGBA = null;
var dummy = null;
var bodyedit = null;
var nghit = false;
var divs = null;
// 動画エントリ用
divs = document.body.getElementsByClassName('node node-video node-teaser node-teaser clearfix');
for (i = 0; i < divs.length; i++) {
bodyedit = divs[i].innerHTML;
// NG機能
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>';
if (showNGword) {
bodyedit = bodyedit.replace(/(<\/div>\n)(\n\t+<\/div>)/,'$1<br><div class="left-icon likes-icon" style="color: red; background: rgba(255,255,255,0.5)"> NG:'+NGWords[j]+'<\/div>\n$2');
}
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>';
if (showEMword) {
bodyedit = bodyedit.replace(/(<\/div>\n)(\n\t+<\/div>)/,'$1<br><div class="left-icon likes-icon" style="color: green; background: rgba(255,255,255,0.5)"> EM:'+EMWords[j]+'<\/div>\n$2');
}
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);
likeRGB = '255,' + likenR.toString()+ ',' + likenR.toString();
likebarstr = 'right-icon likes-icon" align="right" style="width: ' + likewidth.toString() + 'px; background-color: rgba\(' + likeRGB + ',' + likebaropacity + '\)"';
bodyedit = bodyedit.replace(/right-icon likes-icon\"/, likebarstr);
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;
ratiobarstr = '$&<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>/, ratiobarstr);
bodyedit = bodyedit.replace(/height=\"150\"/, 'height="150" style="border:solid ' + borderthickness + 'px rgba\(' + likeRGB + ',' + borderopacity + '\)"');
}
}
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;
// NG機能
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>';
if (showNGword) {
bodyedit = bodyedit.replace(/(<\/div>\n)(\t+<\/div>)/,'$1<br><div class="left-icon likes-icon" style="color: red; background: rgba(255,255,255,0.5)"> NG:'+NGWords[j]+'<\/div>\n$2');
}
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>';
if (showEMword) {
bodyedit = bodyedit.replace(/(<\/div>\n)(\t+<\/div>)/,'$1<br><div class="left-icon likes-icon" style="color: green; background: rgba(255,255,255,0.5)"> EM:'+EMWords[j]+'<\/div>\n$2');
}
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);
likeRGB = '255,' + likenR.toString()+ ',' + likenR.toString();
likebarstr = 'right-icon likes-icon" align="right" style="width: ' + likewidth.toString() + 'px; background-color: rgba\(' + likeRGB + ',' + likebaropacity + '\)"';
bodyedit = bodyedit.replace(/right-icon likes-icon\"/, likebarstr);
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;
ratiobarstr = '$&<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>/, ratiobarstr);
bodyedit = bodyedit.replace(/height=\"150\"/, 'height="150" style="border:solid ' + borderthickness + 'px rgba\(' + likeRGB + ',' + borderopacity + '\)"');
}
}
divs[i].innerHTML = bodyedit;
}
}
};
main();