View Single Post
  #2532  
Old 23.12.2022, 13:46
marko117 marko117 is offline
Junior Loader
 
Join Date: Jul 2017
Posts: 10
Default Function to count package

Hi everyone.
Is there a function that allows me to save the number of packages in my Download list in a variable?
Basically I'm using this script to merge packages with the same name:
Code:
if (name == "Merge Packages") {
    alert("Merging...");
    var count=0;   //used to count merged packages
    getAllFilePackages().forEach(function(package) {

        if (package) {
            var packages = [];

            getAllFilePackages().forEach(function(package2) {
                if (package2.name + package2.downloadFolder == package.name + package.downloadFolder) {
                    packages.push(package2);
                }
            })

            if (packages.length > 1) {
                var linkIds = [];

                packages.forEach(function(package3) {
                    package3.downloadLinks.forEach(function(link) {
                        linkIds.push(link.UUID);
                    })
                })

                linkIds.sort().forEach(function(linkId) {
                    callAPI("downloadsV2", "moveLinks", [linkId], -1, package.UUID);
                })
                count++;
            }
        }
    })
    alert("Merged: "+count);
}
but I have a lot of packages and I wanted to print a progress percentage on a popup using alert()
25%, 50%, 75 and 90%
using the percentage formula:
tot*0.25, tot*0.50....
in pseudo code
Code:
tot=countFunction() //or similar
....
....
if(actualPackage==tot*0.25)
       alert("progress 25%")
......
.......
do you have any idea how to count all the packages?
Reply With Quote