Volafile Upload-Helper

Helps Volafile users avoid certain problematic servers when uploading files, and allows raising the parallel-upload limit, up to 10.

当前为 2021-05-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Volafile Upload-Helper
  3. // @author Arnold François Lecherche and a Vola anon named Adonis
  4. // @namespace greasyfork.org
  5. // @icon https://volafile.org/favicon.ico
  6. // @version 1.00
  7. // @description Helps Volafile users avoid certain problematic servers when uploading files, and allows raising the parallel-upload limit, up to 10.
  8. // @include http://volafile.org/*
  9. // @include http://*.volafile.org/*
  10. // @include https://volafile.org/*
  11. // @include https://*.volafile.org/*
  12. // @grant none
  13. // @run-at document-end
  14. // @copyright 2021 Arnold François Lecherche
  15. // ==/UserScript==
  16. (function (w, d, M) {
  17. 'use strict';
  18. var a = false, nbRegEx = /^(?:(?:dl\d+|banger),)*(?:dl\d+|banger)|none$|^$/, commasRegExp = /,+$/,
  19. commaRegExp = /,/g, extRegExp = /\..+/, c, ulmenu, ub, r, up, k;
  20. function getCurrentProgressClass(t) {
  21. var server, blocklist, filespan, sinfo, x;
  22. if (this.upload.currentAttempt && this.upload.currentAttempt.info && this.upload.file.size > 1e7) {
  23. server = this.upload.currentAttempt.info.server;
  24. blocklist = new RegExp((c.ulblock || 'none').replace(commasRegExp, '').replace(commaRegExp, '\\\.|') + '\\\.');
  25. if (blocklist.test(server.replace(extRegExp, '.'))) {
  26. //r.extensions.chat.showMessage('Debug', 'skipping blacklisted server: ' + server, {'dontsave': true, 'staff': true});
  27. this.upload.tries -= 0.9;
  28. this.upload.currentAttempt.abort();
  29. } else {
  30. filespan = this.file.dom.nameElement;
  31. sinfo = filespan.querySelector('.sinfo') || filespan.appendChild(x = d.createElement('i'), (x.className = 'sinfo', x.style.color = 'rgba(255,255,255,0.53)'));
  32. sinfo.innerHTML = ' • ' + this.upload.currentAttempt.info.server;
  33. }
  34. }
  35. return 'progress_' + M.round(100 * this.lastProgress);
  36. }
  37. function remove() {
  38. if ('undefined' === typeof e) return;
  39. e.removeTimeout = null;
  40. e.forceRemove();
  41. }
  42. function setRemoveTimeout(t) {
  43. if (this.error) {
  44. this.file.dom.nameElement.innerHTML += ' &bull; [<b>UPLOAD FAILED</b>]';
  45. //r.extensions.chat.showMessage('Upload Failed', this.file.name, {'dontsave': true, 'staff': true});
  46. return;
  47. }
  48. if (this.removeTimeout) w.clearTimeout(this.removeTimeout);
  49. this.removeTimeout = w.setTimeout(remove, t);
  50. }
  51. function isUploading() {
  52. var uppy = [up.uploadQueue.uploadQueue, up.runningUploads], i = uppy.length, j;
  53. while (i--) {
  54. j = uppy[i].length;
  55. while (j--) {
  56. uppy[i][j].getCurrentProgressClass = getCurrentProgressClass;
  57. uppy[i][j].setRemoveTimeout = setRemoveTimeout;
  58. }
  59. }
  60. return this.runningUploads.length > 0 || this.uploadQueue.length() > 0;
  61. }
  62. function set_mcu() {
  63. var mcu = M.floor(prompt('config.max_concurrent_uploads', c.max_concurrent_uploads));
  64. if (mcu != mcu || mcu < 1 || mcu > 10) return;
  65. this.innerText = '⮅ ' + (c.max_concurrent_uploads = mcu);
  66. }
  67. function set_block() {
  68. var block = prompt('Enter a comma-separated list of server prefixes to block, e.g. "dl8" or "dl7,dl8" (without quotes).', c.ulblock);
  69. if (block === null || block === false || !nbRegEx.test(block)) return;
  70. this.innerText = '🚫 ' + (c.ulblock = block);
  71. }
  72. function init() {
  73. if (a) return k && w.clearInterval(k);
  74. else k = k || w.setInterval(init, 1000);
  75. c = w.config;
  76. if (!c) return;
  77. ulmenu = w.ulmenu || d.createElement('div');
  78. ub = d.getElementById('upload_container');
  79. r = w.RoomInstance;
  80. if (!r) return;
  81. up = r.extensions.upload;
  82. up.isUploading = isUploading;
  83. ulmenu.id = 'ulmenu';
  84. ulmenu.setAttribute('style', 'display:inline-block;font-size:0.9em');
  85. ulmenu.innerHTML = '<a class="button" id="ul_mcu" title="set max concurrent uploads">⮅</a> ' +
  86. '<a class="button" id="ul_block" title="set upload blacklist">🚫</a> &nbsp;';
  87. ub.insertBefore(ulmenu, ub.firstChild);
  88. d.getElementById('ul_mcu').addEventListener('click', set_mcu, false);
  89. d.getElementById('ul_block').addEventListener('click', set_block, false);
  90. a = true;
  91. if (k) w.clearInterval(k);
  92. }
  93. init();
  94. d.addEventListener('DOMContentLoaded', init, false);
  95. w.addEventListener('load', init, false);
  96. })(window, document, Math);