Greasy Fork

MAM Ratio Protect

Prevents downloading based on resulting Ratio Loss due to forgetting to buy w/FL

目前为 2020-11-18 提交的版本。查看 最新版本

// ==UserScript==
// @name MAM Ratio Protect
// @namespace yyyzzz999
// @author yyyzzz999
// @description Prevents downloading based on resulting Ratio Loss due to forgetting to buy w/FL
// @include https://www.myanonamouse.net/t/*
// @version 1.52 (11/17/20)
// @grant none
// @run-at document-end
// ==/UserScript==
// Many Thanks to GardenShade for major code contributions!
/*jshint esversion: 6 */

// The download text area
let dlBtn = document.getElementById("tddl");
// The unused label area above the download text
let dlLabel = document.querySelector("#download .torDetInnerTop");
// Would become ratio
let rnew = document.getElementById("ratio").textContent.match(/\d+\.\d+/)[0];
// Current ratio
let rcur = document.getElementById("tmR").textContent.match(/\d+\.\d+/)[0];
// Seeding or downloading
let seeding = document.getElementById('DLhistory');
// console.log(seeding);

//Hide banner on book pages if not using MAM+
//document.getElementById("msb").style.display = "none";

// Only run the code if the ratio exists
if(rnew && rcur){
    let rdiff = rcur-rnew; // Loss in ratio after download (if error in old browser use var instead of let)
//console.log("rdiff= " + rdiff); // For debugging
  
  if (seeding == null) { // if NOT already seeding or downloading
         dlLabel.innerHTML = `Ratio loss ${rdiff.toPrecision(5)}`;
         dlLabel.style.fontWeight = "normal"; //To distinguish from BOLD Titles
  }

    // Change this number to your "trivial ratio loss" amount
    // These changes will always happen if the ratio conditions are met
    if(rdiff > 0.3){
        dlBtn.style.backgroundColor="SpringGreen";
        dlBtn.style.color="black";
    }

    // Change this number to your I never want to dl w/o FL ratio loss amount
    if(rdiff > 1){
        dlBtn.style.backgroundColor="Red";
        // Disable link to prevent download
        dlBtn.style.pointerEvents="none";
        // maybe hide the button, and add the Ratio Loss warning in its place?
        dlBtn.innerHTML = "FL Recommended";
        dlLabel.style.fontWeight = "bold";
    // Change this number to your "I need to think about using a FL ratio loss" amount
    }else if(rdiff > 0.5){
        dlBtn.style.backgroundColor="Orange";
    }
}