// ==UserScript== // @name 1fichier tools // @namespace surrealmoviez.info // @description Tools to manage 1fichier links easily // @require http://code.jquery.com/jquery-1.11.1.min.js // @include http://www.1fichier.com/console/* // @include http://www.1fichier.com/*/console/* // @include http://1fichier.com/console/* // @include http://1fichier.com/*/console/* // @include https://www.1fichier.com/console/* // @include https://www.1fichier.com/*/console/* // @include https://1fichier.com/console/* // @include https://1fichier.com/*/console/* // @grant none // @version 1.2.3 // @downloadURL https://update.greasyfork.cloud/scripts/6728/1fichier%20tools.user.js // @updateURL https://update.greasyfork.cloud/scripts/6728/1fichier%20tools.meta.js // ==/UserScript== this.$ = this.jQuery = jQuery.noConflict(true); // Creates an array of direct links function createArrayLinks() { var links = []; $("li.file.ext_gif.ui-selectee.ui-selected").each(function () { var temp_id = $(this).attr("rel"); var id_start = temp_id.lastIndexOf("_") + 1; var id = "https://1fichier.com/?" + temp_id.substring(id_start); links.push(id); }); return (links); } // Retrieves all IDs of the folders in the current account as an array function getFoldersIds() { var folders_droppable = ["0"]; var folders_ids = ["0"]; var temp_html = ""; while (folders_droppable.length !== 0) { $.ajax({ type: "GET", url: "/console/dirs.pl?dir_id=" + folders_droppable[0] + "&map=0&start=0&fk=false", async: false, success: function (text) { temp_html = text; } }); $(temp_html).find('li').each(function () { if (!$(this).hasClass('root') && $("div > a", $(this)).text() !== "Ignore") { folders_ids.push($(this).attr('rel')); } if ($(this).hasClass('fcp')) { folders_droppable.push($(this).attr('rel')); } }); folders_droppable.shift(); } return folders_ids; } // Extracts the ID, query ID, name and upload date of all files in the current folder // Returns an array of [id, id_ref, date, name]. Date as yyyy-mm-dd function extractFoldersData(folder_ids) { var collection = []; for (var i = 0; i < folder_ids.length; i++) { $.ajax({ type: "GET", url: "/console/files.pl?dir_id=" + folder_ids[i] + "&oby=", async: false, success: function (data) { $("li.file", $(data)).each(function () { var current = []; var temp_id = $(this).attr("rel"); current[0] = temp_id.substring(temp_id.lastIndexOf("_") + 1); current[1] = "selected%5B%5D=" + temp_id; current[2] = formatDate($(this).find("div.dD").text()); current[3] = $(this).find("div.dF").text(); collection.push(current); }); }, error: function (request, status, error) { console.log("Error in extractFoldersData()\nStatus: " + status + ", error: " + error + "\n" + request.responseText); } }); } return (collection); } // Groups the ref_ids to make the info requests // Returns an array of querries function createQueries(folders_data) { var array_id_ref = []; for (var i = 0; i < folders_data.length; i++) { array_id_ref.push(folders_data[i][1]); } var array_queries = []; // Array containing all IDs in the current folder var size_split = 150; // Number of files to send in each info request while (array_id_ref.length !== 0) { var current = array_id_ref.splice(0, size_split); array_queries.push(current.join("&")); } return (array_queries); } // Returns the id, total downloads and last download date of all files in the account // Returns an array with [id, total_downloads, date_last_download]. Date as yyyy-mm-dd function retrieveInfo(array_queries) { var files_info = []; for (var i = 0; i < array_queries.length; i++) { $.ajax({ method: "POST", async: false, url: "/console/info.pl", data: array_queries[i], success: function (data) { files_info = files_info.concat(extractStats(data)); } }); } return files_info; } // Extracts the info of the curent query // Returns an array of [id, total_downloads, date_last_download]. Date as yyyy-mm-dd function extractStats(data) { var info = []; $("tr td:has(a):first-child", $(data)).each(function () { var id = $("a", $(this)).attr("href"); id = id.substring(id.lastIndexOf('?') + 1); var total_downloads, date_last_download; var $nextTr = $(this).parent().next("tr"); // Check if a "not downloaded yet" message is present if ($("td", $nextTr).length === 1) { total_downloads = 0; date_last_download = "NO_DOWNLOADS"; } else { var $lastDownloadTr = $(this).parent().nextUntil('tr:not(.t,.t1)').last(); var $totalTr = $lastDownloadTr.next(); total_downloads = $('td:eq(2)', $totalTr).text(); date_last_download = $('td:eq(1) > a', $lastDownloadTr).text(); } info.push([id, total_downloads, date_last_download]); }); return info; } // Returns a date in the format yyyy-mm-dd function formatDate(uglyDate) { var arr_date = uglyDate.split("/"); if (arr_date.length === 3) { arr_date[2] = arr_date[2].substring(0, arr_date[2].indexOf(" ")); var niceDate = arr_date[2] + "-" + arr_date[1] + "-" + arr_date[0]; } else { console.log("Error parsing date: " + uglyDate); niceDate = uglyDate; } return (niceDate); } // Checks if the link weren't downloaded since a given ammount of days // Returns an array with the file name and the download link as a string, containing only the endangered ones function checkEndangered(date_last_download, milliseconds_now) { var danger_time = 45; // days since the last download. Files are stored for 90 days danger_time = danger_time * 86400000; // days to milliseconds var milliseconds_last_download = Date.parse(date_last_download); if (milliseconds_now - milliseconds_last_download > danger_time) { return true; } return false; } // Creates a table containing all file names and time since the last download // Displayed in a new window function createExtensiveTable(complete_info) { //[id, total_downloads, date_last_download, name] complete_info = sortArrayOfArrays(complete_info, 3); var page_beginning = "
File name | Link | Total downloads | Time since last download | "; var page_end = "
---|