// ==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.54 (11/28/20) // @grant none // @run-at document-end // @downloadURL none // ==/UserScript== // Many Thanks to GardenShade for advice and major code contributions! /*jshint esversion: 6 */ // downloadURL: https://greasyfork.org/en/scripts/416189-mam-ratio-protect let DEBUG =0; // Debugging mode on (1) or off (0) added in (v1.54) // 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 = 0; // FALSE if (document.getElementById("ratio").textContent.split(" ")[1].match(/become/) ) { rnew = document.getElementById("ratio").textContent.split(" ")[2].replace(/,/g,""); // (v1.54) // VIP expires date caused rdiff to be NaN in v1.53 bcause text crept in in v1.52 } if (DEBUG) console.log("rnew= " + rnew); //let rnew = document.getElementById("ratio").textContent.split("become ")[1].replace(/,/g,""); // broke w/On list for next FL pick //let rnew = document.getElementById("ratio").textContent.match(/\d*\,?\d+\.\d+/)[0].replace(/,/g,"''); //breaks at 1,000,000bp if (DEBUG) console.log("rnew= " + rnew); // For debugging // Current ratio - Version 1.52 and earlier broke when a ratio has a comma let rcur = document.getElementById("tmR").textContent.replace(/,/g,""); if (DEBUG) console.log("rcur= " + rcur); // For debugging // Seeding or downloading TRUE if "Actively Seeding" etc. let seeding = document.getElementById('DLhistory'); if (DEBUG) console.log("seeding= " + seeding); // Available FL wedges - for future use... (>v1.54) // Only visible if set on MAM in Preferences, Style, Main Menu, Top Menu //let wedgeAvail = document.getElementById('tmFW').textContent.split(":")[1].trim(); //only works if added to top menu //if(wedgeAvail) console.log("wedgeAvail= " + wedgeAvail); // ELSE try finding in drop downs with Rel XPath //a[contains(text(),'FL Wedges: ')] or // CSS ul:nth-child(1) li.mmUserStats ul.hidden:nth-child(2) li:nth-child(7) > a:nth-child(1) // let wedgeAvail = document.querySelector('[aria-labelledby="userMenu"] li:nth-of-type(7)').textContent.split(':')[1].trim(); //Hide banner on book pages if not using MAM+ //document.getElementById("msb").style.display = "none"; // Only run the code if the new ratio exists and we found the current one if(rnew && rcur){ let rdiff = rcur-rnew; // Loss in ratio after download (if error in old browser use var instead of let) if (DEBUG) console.log("rdiff= " + rdiff); // For debugging if (seeding == null ) { // if NOT already seeding, downloading or VIP expires (v1.54) dlLabel.innerHTML = `Ratio loss ${rdiff.toFixed(4)}`; //changed from toPrecision(5) (v1.54) 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"; // Uncomment (remove //) above line to disable the download button // 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"; } }