testingscript14temp

Moves Unconfirmed Releases to their own Edition

目前為 2018-12-16 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         testingscript14temp
// @namespace    testingtesting123_233000
// @author       temptesting13
// @version      1.0
// @description  Moves Unconfirmed Releases to their own Edition
// @run-at       document-end
// @include      *redacted.ch/torrents.php?id=*
// @include      *https://redacted.ch/torrents.php?action=edit&id=*
// ==/UserScript==

// maybe add a second button Confirm year+cat only, etc.
// make a diff one to catch all the daytrotter ones
// catch all IDs from collage, edit torrent page has year at the bottom

var year;
var link = [];
var label = [];
var cat = [];

(function() {
    // Make the button
    var r = $('<input type="button" value="Confirm" id="confButton">');
    $(".header .linkbox").before(r);

    // Find year (currently looks for h2 and strips non-digits and takes last 4)
    year = $("h2:first").text().replace(/[^0-9]/g, '').slice(-4);

    // Find ED URLs, record label and catalogue number
    $('a[href*="action=edit&id"]').each(function(i){
        var edition_info = $(this).parent().parent().parent().prevAll('.edition.group_torrent').first().text();
        if (edition_info.includes("Unconfirmed Release")){
            link[i] = $(this).attr('href');
            edition_info = edition_info.trim().replace("− Unconfirmed Release / ", '');
            var split = edition_info.split(" / ");

            switch (split.length){
                case 3:
                    label[i] = split[0];
                    cat[i] = split[1];
                    break;
                case 2:
                    label[i] = split[0];
                    cat[i] = "";
                    break;
                case 1:
                    label[i] = "";
                    cat[i] = "";
                    break;
                default:
                    alert("This probably has two editions!");
            }
        }
    });

})();

// Do things on click
// consider a middle ground where this is done with .post() to avoid the timing issue.
$('#confButton').click(function(){
    var n;
    var w = [];
    var closed = 0;

    for (let n = 0; n < link.length; n++){
        w[n] = window.open("https://redacted.ch/"+link[n]);
        w[n].onload = (function(){
            //w[n].onbeforeunload = function(){w[n].close();}
            $(w[n]).unload(function(){
                setTimeout(function(){
                    w[n].close();
                    closed++;
                }, 250);
            });

            w[n].document.getElementById("remaster_year").value = year;
            w[n].document.getElementById("remaster_record_label").value = label[n];
            w[n].document.getElementById("remaster_catalogue_number").value = cat[n];

            w[n].document.getElementById("post").click();
        });
    }

    var id = setInterval(function(){
        if (closed == link.length){
            setTimeout(function(){
                location.reload();
                clearInterval(id);
            }, 500);
        }
    }, 250);
})

// browser.tabs.loadDivertedInBackground=true
// consider :contains('Unconfirmed Release') then travese down

// other old code
        //         w[n] = window.open("https://redacted.ch/"+link[n]);
        //         w[n].onload = (function(){
        //             w[n].document.getElementById("remaster_year").value = year;
        //             w[n].document.getElementById("remaster_record_label").value = label;
        //             w[n].document.getElementById("remaster_catalogue_number").value = cat;

        //             var form_data = $(w[n].document).find("#upload_table").serialize();

        //             $.post(link[n], form_data).done(function(){
        //                 w[n].close();
        //                 closed++;
        //                 checkComplete(closed);
        //             });
        //         });