Dogolinha / MeuOuroDiário

// ==UserScript==
// @name         MeuOuroDiário
// @description  AVISO: É aconselhável deixar uma janela (não uma aba) do browser apenas para a página de garimpo, caso contrário, a velocidade será substancialmente menor. Aperte o botão ali embaixo e espere o programa rodar as 84 páginas, ou não. Testado apenas no Firefox.
// @license      MIT
// @version      1.0
// @namespace    http://tampermonkey.net/
// @author       Anãozinho
// @match        https://www.4shared.com/web/*
// @match        https://www.4shared.com/folder/*
// @match        https://www.4shared.com//folder/*
// @updateURL https://openuserjs.org/meta/Dogolinha/MeuOuroDiário.meta.js
// @copyright 2018, Dogolinha (https://openuserjs.org/users/Dogolinha)
// ==/UserScript==

(function () {

  var urlis = window.location.href;
  var endOk = false;

  if (urlis.indexOf("/web/") != -1) {

    if (urlis.split("&")[1] != "sort=time%2Cdesc") {
      window.location.href = urlis.split("&")[0] + "&" + "sort=time%2Cdesc";
    }

    var elem = document.getElementById('tiptip_holder');
    elem.id = 'notAnymore';
    elem.className = '';
    elem.innerHTML = '<span id="spanny" style="position:relative; display: inline-block; width: 100%; text-align: center; font-family: Verdana; color: #FF0000; font-weight: bold; font-size: 12px; top:3px; left: auto">PAUSADO</span>';
    elem.style.cssText = 'cursor: pointer; position: fixed; height: 27px; width: 130px; right:10px; bottom: 10px; z-index: 1000; border-radius: 4px; box-shadow: 2px 2px 4px rgba(0,0,0,0.25); background-color: white;';

    var allURL = [];
    var found = 0;
    var removed = 0;
    var pages = 0;

    var on = false;
    var fun = 0;

    document.getElementsByClassName("jsSidebar")[0].remove();
    document.getElementsByClassName("jsReklBlock")[0].remove();
    document.getElementsByClassName("jsChangeView")[0].remove();

    if (document.body.className.match('thumb-view')) {
      document.body.classList.remove("thumb-view");
      document.body.classList.add("list-view");
    }

    document.getElementsByClassName("jsSearchResHolder")[0].classList.remove("col-md-8");
    document.getElementsByClassName("jsSearchResHolder")[0].classList.add("col-md-12");

    document.getElementById("notAnymore").addEventListener("click", function () {
      if (!on) {
        on = true;
        document.getElementById("spanny").innerHTML = "GARIMPANDO";
        document.getElementById("spanny").style.color = "#00aa00";
      }
      else {
        on = false;
        document.getElementById("spanny").innerHTML = "PARADO";
        document.getElementById("spanny").style.color = "#FF0000";
      }
    });
  }
  else if (urlis.indexOf("//folder") == -1) {
    window.location.href = urlis.replace("/folder", "//folder");
  }
  else {
    var loading = setInterval(function () {
      if (document.getElementById("account-loading")) {
        changeViewModeAjax(2);
        clearInterval(loading);
      }
    }, 500);
  }

  setInterval(function () {
    var results = document.getElementsByClassName("jsSearchItemColumn").length - 1;
    var folderInfo = document.getElementsByClassName("jsFolderInfo");
    pages = results / 12;
    var titleE = pages + "/84 (" + found + " resultados)";
    if (results % 12 === 0) {
      if (folderInfo.length > 1) {
        loop(results, folderInfo);
        titleFun(titleE);
      }
      else if (on && pages < 84) {
        document.getElementsByClassName("jsShowMoreResults")[0].click();
        titleFun(titleE);
      }
      else {
        if (pages >= 84) {
          document.title = "[FIM] " + titleE;
          document.getElementById("spanny").innerHTML = "FIM";
          document.getElementById("spanny").style.color = "#FF0000";
          if (endOk == false) {
            alert("Fim!");
          }
          endOk = true;
        }
        else {
          document.title = "[PAUSE] " + titleE;
        }
      }
    }
  }, 100);

  function loop(results, folderInfo) {
    var broken = false;
    folderInfo = document.getElementsByClassName("jsFolderInfo");
    for (var j = 0; j < folderInfo.length; j++) {

      var imgURL = "";
      var userName = folderInfo[1].parentElement.getElementsByClassName("jsUserInfo")[0].innerHTML;
      var folderURL = folderInfo[1].getAttribute("href");
      var folderCard = folderURL.split("/").pop().split(".")[0];
      var folderArray = folderURL.split("/")[2];
      var folderFullURL = folderInfo[1].href.replace("/folder", "//folder");

      if (folderCard == "#") {
        folderInfo[1].parentElement.parentElement.parentElement.remove();
        removed++;
        break;
      }
      for (var i = 0; i < allURL.length; i++) {
        if (folderArray == allURL[i]) {
          imgURL = folderInfo[1].parentElement.parentElement.parentElement.getElementsByClassName("jsFileThumb")[0].style.backgroundImage.split('"')[1];
          document.getElementById(folderArray).getElementsByClassName("imgSet")[0].innerHTML += "<img src='" + imgURL + "' class='imgSetImg' style='display: inline-block; margin-top:5px; margin-right:5px; width:64px; height: 64px'>"
          folderInfo[1].parentElement.parentElement.parentElement.remove();
          removed++;
          broken = true;
          break;
        }
      }
      if (broken) break;
      found++;
      allURL.push(folderArray);
      folderInfo[1].parentElement.parentElement.parentElement.style.height = "auto";
      folderInfo[1].parentElement.parentElement.parentElement.style.minHeight = "160px";
      folderInfo[1].parentElement.parentElement.style.height = "100%";
      folderInfo[1].parentElement.parentElement.style.width = "auto";
      folderInfo[1].parentElement.parentElement.parentElement.id = folderArray;
      folderInfo[1].parentElement.parentElement.style.position = "relative";
      folderInfo[1].parentElement.parentElement.style.left = "0px";
      folderInfo[1].parentElement.parentElement.style.minHeight = "160px";
      folderInfo[1].parentElement.parentElement.parentElement.getElementsByClassName("jsFileThumb")[0].setAttribute("href", folderFullURL);
      folderInfo[1].parentElement.parentElement.innerHTML = "<div style='display: block; font-size:14px;position:relative; top:0px; padding:5px 5px; width:100%;height: 100%; width:100%; text-decoration: none;word-wrap: break-word;'><span style='font-size:10px;'>👤&nbsp;&nbsp;&nbsp;</span><span style='font-weight:bold; color: #3A5FCD;'>" + userName + "</span><br><span style='font-size:14px'>⚑&nbsp;&nbsp;</span>" + folderArray + "<hr style='display: block; margin-top: 6px; margin-bottom:4px;border-width: 1px; border-color: rgba(0,0,0,0.25);'><div class='imgSet' style='font-family:Consolas;font-size:12px;'></div></div><a href=" + folderFullURL + " target='_blank' style='position:absolute; display: block; left:0px; top:0px; width: 100%; height: 100%'></a>";
    }
  }

  function titleFun(titleE) {
    switch (fun) {
      case 0:
        document.title = "|.... " + titleE;
        fun++;
        break;
      case 1:
        document.title = ".|... " + titleE;
        fun++;
        break;
      case 2:
        document.title = ".|... " + titleE;
        fun++;
        break;
      case 3:
        document.title = "..|.. " + titleE;
        fun++;
        break;
      case 4:
        document.title = "...|. " + titleE;
        fun++;
        break;
      case 5:
        document.title = "....| " + titleE;
        fun = 0;
    }
  }

})();