// ==UserScript== // @name U2 FL Helper // @namespace http://tampermonkey.net/ // @version 0.2 // @description Just a quick magic set // @author solomax // @contributor Stardream // @match https://u2.dmhy.org/* // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== // @grant GM.xmlHttpRequest // ==/UserScript== (function() { 'use strict'; function getCurrentUCoins() { return parseFloat($("#info_block span.ucoin-notation").attr("title").replace(",", "")); } function addQuickMagicButtons(baseform, typeid, hrs, buttonid, name, ord) { let form = $(baseform).clone(); $(form).find(typeid).prop("checked", true).trigger("click"); $(form).find("input[name='hours']").val(hrs); let serialized = $(form).serialize(); console.log(serialized); let ready = false; $.post("promotion.php?test=1", serialized, function (data, status, xhr) { let forbidden = true, button = "", message = "", price = 0.0, disabled = false; if (data.status == "operational" || data.status == "insufficient") { forbidden = false; button = "Magic it"; message = data.price; price = parseFloat($(data.price).attr("title").replace(",", "")); disabled = (data.status == "insufficient"); } else { forbidden = true; } if (!forbidden) { $("a[href*='promotion.php?action=magic&torrent=']").parent().append($(``).append("  ") .append( ``).append(``).append(`${message}`)); if (disabled) { $(`#${buttonid}`).prop("disabled", true) } } $(".quickMagic").sort(function(a, b){ return +$(a).attr('order') - +$(b).attr('order'); }).appendTo($("a[href*='promotion.php?action=magic&torrent=']").parent()); }, "json"); } if (window.location.href.includes("details.php")) { console.log("We're on details page!"); let id = (new URLSearchParams(window.location.search)).get('id'); console.log("ID: " + id); GM.xmlHttpRequest({ method: "GET", url: "https://u2.dmhy.org/promotion.php?action=magic&torrent=" + id, onload(response) { if (response.status === 200) { console.log("Got magic page!"); var parser = new DOMParser(); var ajaxDoc = parser.parseFromString(response.responseText, "text/html"); var form = ajaxDoc.querySelectorAll("form:not([style])"); $(form).attr("action", "promotion.php"); console.log("Test - button name: " + $(form).find("#btn_query").val()); let ord = 0; addQuickMagicButtons(form, "#s_user_self", "24", "selfFl1d", "FL 24h", ord++); addQuickMagicButtons(form, "#s_user_self", "72", "selfFl3d", "FL 3d", ord++); addQuickMagicButtons(form, "#s_user_everyone", "24", "globalFl1d", "GFL 24h", ord++); addQuickMagicButtons(form, "#s_user_everyone", "72", "globalFl3d", "GFL 3d", ord++); addQuickMagicButtons(form, "#s_user_everyone", "168", "globalFl7d", "GFL 1w", ord++); } } }); GM.xmlHttpRequest({ method: "GET", url: "https://u2.dmhy.org/promotion.php?action=torrent&id=" + id, onload(response) { if (response.status === 200) { console.log("Got promotions page!"); var parser = new DOMParser(); var ajaxDoc = parser.parseFromString(response.responseText, "text/html"); var table = ajaxDoc.querySelectorAll("#outer .embedded table[width='99%']"); let good = 0; $(table).find("tr").each(function (i) { if (i !== 0 && !["Effective", "有效"].includes($(this).find("td:nth-child(9)").text())) { $(this).remove(); } else if (i !== 0) { good++; } }); console.log(`found ${good} good promotions`); if (good > 0) { const isChinese = document.documentElement.lang.startsWith("zh"); let row = $(` ${isChinese ? "进行中的优惠" : "Ongoing promotions"} `); $(row).find("td:nth-child(2)").append($(table)); $("a[href*='promotion.php?action=magic&torrent=']").parent().parent().after(row); } } } }); } })();