// ==UserScript==
// @name Fanfiction.net ratio
// @namespace https://greasyfork.org/users/728828
// @version 1.1
// @description Adds score ratio to fanfics
// @author 1233Echo
// @match https://www.fanfiction.net/*
// @grant none
// @downloadURL none
// ==/UserScript==
// My first and probably last script
// Shout out to Min "AO3: Kudos/hits ratio" for inspiring this script
// Colors of the Ratio div
var border_color = "#cdcdcd";
var green_color = "#b7e1cd";
var yellow_color = "#fce8b2";
var orange_color = "#f8d8ba";
var red_color = "#f4c7c3";
// Calculate score based on genre popularity
var genre_popularity = true;
// Calculate score based on rating popularity
var rating_popularity = true;
(function($) {
var i;
var ratio_equa;
var genre_list;
var genre_popu;
var ratin_popu;
var ratin_list;
if (localStorage.getItem("ratio_settings") === null) {
ratio_equa = "(10*reviews/Math.log(words))/5";
genre_popu = genre_popularity;
genre_list = [
{name : "Adventure", value : 0.87},
{name : "Angst", value : 0.91},
{name : "Crime", value : 0.99},
{name : "Drama", value : 0.84},
{name : "Family", value : 0.95},
{name : "Fantasy", value : 0.98},
{name : "Friendship", value : 0.92},
{name : "Horror", value : 0.99},
{name : "Humor", value : 0.78},
{name : "Hurt", value : 0.91},
{name : "Mystery", value : 0.98},
{name : "Parody", value : 0.98},
{name : "Poetry", value : 0.99},
{name : "Romance", value : 0.40},
{name : "Sci-Fi", value : 1.00},
{name : "Spiritual", value : 1.00},
{name : "Supernatual", value : 0.98},
{name : "Suspense", value : 0.99},
{name : "Tragedy", value : 0.96},
{name : "Western", value : 1.00}
];
ratin_popu = rating_popularity;
ratin_list = [
{name : "K", value : 1.00, id : "K"},
{name : "K+", value : 1.00, id : "Kp"},
{name : "T", value : 1.00, id : "T"},
{name : "M", value : 3.00, id : "M"},
];
}
else{
var ratio_settings = localStorage.getItem('ratio_settings');
var obj = JSON.parse(ratio_settings);
ratio_equa = obj[0];
genre_popu = obj[1];
genre_list = obj[2];
ratin_popu = obj[3];
ratin_list = obj[4];
}
var button = $('').text("Ratio");
var btn = $('span[class="btn"]');
btn.after(button ,'\n');
$("#ratio-settings").css("margin-left","10px");
$("#ratio-settings").css("width","39.8px");
$("#ratio-settings").click(function(){
Settings();
});
Ratio();
function Settings(){
function Check_color(a, b, c){
if($(a).is(":checked")){
$(b).css('color','#04761c');
$(c).show();
}else{
$(b).css('color','#c00000');
$(c).hide();
}
}
function Genre_input(){
$('.span_a').after("
")
for(i=0; i"+genre_list[i].name+"
\
");
}
}
function Rating_input(){
$('.span_b').after("")
for(i=0; i"+ratin_list[i].name+"
\
");
}
}
var modal = ("\
\
\
\
Ratio\
Formula\
\
\
?
\
\
Score\
with genre popularity\
Genre \
\
Score\
with rating popularity\
Rating \
\
\
\
\
");
$('.lc-wrapper').after(modal);
Genre_input();
Rating_input();
$(".btn_default").hover(function(){
$(this).css('background-image', 'none');
}, function(){
$(this).css('background-image', 'linear-gradient(to bottom,#cc8800,#cc4400)');
});
$(".g_box_a").prop('checked', genre_popu);
$(".g_box_b").prop('checked', ratin_popu);
Check_color($('.g_box_a'), $('.color_style_a'), $('#ara'));
Check_color($('.g_box_b'), $('.color_style_b'), $('#arb'));
$('input').change(function(){
Check_color($('.g_box_a'), $('.color_style_a'), $('#ara'));
Check_color($('.g_box_b'), $('.color_style_b'), $('#arb'));
});
$('.ar div:nth-child(odd)').css({
'margin-right':'5px'
});
$('.ar div:nth-child(even)').css({
'margin-left':'5px'
});
$('#ara').css({
'width':'auto',
'height':'400px',
'margin-top':'10px',
});
$('#arb').css({
'width':'auto',
'height':'80px',
'margin-top':'10px',
});
$('.single').css({
'height': '30px',
'height': '30px',
'width':'49%',
'display': 'flex',
'align-items': 'center',
'float':'left',
'margin-bottom':'10px',
'display': 'table-cell',
'vertical-align': 'middle',
});
$('.genre_input').css({
'width':'55%',
'height':'26px',
'margin-top':'4px',
'border-radius':'4px',
'color':'#555',
'border':'1px solid #ccc',
'outline':'none',
'text-align':'left',
'float':'left',
'padding-left':'10px'
});
$('.btn_default').css({
'text-shadow': '0 -1px 0 rgb(0 0 0 /25%)',
'line-height': '20px',
'background-color': '#cc4400',
'display': 'inline-block',
'padding': '4px 12px',
'cursor': 'pointer',
'border': '1px solid #ccc',
'border-radius': '4px',
'background-image': 'linear-gradient(to bottom,#cc8800,#cc4400)',
'border-color':'rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25)',
'color':'white'
});
$('.color_style').css({
'width':'auto',
'height':'auto',
'max-height':'100%'
});
$('.text_box').css({
'width':'calc(100% - 40px)',
'height':'26px',
'margin-top':'4px',
'border-radius':'4px',
'color':'#555',
'border':'1px solid #ccc',
'outline':'none',
'text-align':'center'
});
$('.info_box').css({
'width':'28px',
'height':'23px',
'margin-top':'4px',
'border-radius':'4px',
'color':'#555',
'border':'1px solid #ccc',
'outline':'none',
'text-align':'center',
'padding-top':'5px',
'user-select':'none',
'float':'right'
});
$('.modal-body').css({
'width':'auto',
'height':'auto',
'max-height':'100%'
});
var remove_modal = $('.modal-backdrop');
$(".modal-backdrop").click(function(e){
var container = $("#settings");
if (!container.is(e.target) && container.has(e.target).length === 0){
remove_modal.remove();
return false;
}
});
$("#cancel-settings").click(function(){
remove_modal.remove();
return false;
});
$("#default-settings").click(function(){
localStorage.removeItem('ratio_settings');
location.reload();
});
console.log( $("#K+").val());
$("#apply-settings").click(function(){
var genre_popu = false;
var ratin_popu = false;
if($('.g_box_a').is(":checked")) {
genre_popu = true;
}
if($('.g_box_b').is(":checked")) {
ratin_popu = true;
}
var cal_string = $("#calc_ratio").val();
for(i=0; i 0){
score = score_muliplayer/counter;
}
}
// This is also optional I adjusted this based on popularity of mature fics
if(ratin_popu){
for(i = 0; i < ratin_list.length; i++){
if(rated_string == ratin_list[i].name){
score *= ratin_list[i].value;
}
}
}
score = Number(score).toFixed(2);
if (score < 0.1) {
score = 0;
}
if (score > 100) {
score = 100;
}
var hits_count = parseInt(hits_value.text());
var ratio_label = $('').text("Ratio: "+score+"%");
wrevi.after(ratio_label ,'\n');
// Ratio div background color
// Green
if(score>75){
ratio_label.css("background-color", green_color);
}
// Yellow
else if(score>50){
ratio_label.css("background-color", yellow_color);
}
// Orange
else if(score>25){
ratio_label.css("background-color", orange_color);
}
// Red
else if(score>=0){
ratio_label.css("background-color", red_color);
}
});
$('.ratio').css({
'width':'110px',
'text-align':'center',
'float':'right',
'border-radius':'3px',
'border-style':'solid',
'border-width':'thin',
'border-color':border_color
});
}
})(jQuery);