Anaozinho / 4shared-cleaner

// ==UserScript==
// @name         4shared-cleaner
// @description  Aperte o botão no canto inferior-direito da tela e o script irá rodar todas as 84 páginas de Search do 4shared e eliminar duplicatas de /folder/, além de simplificar a interface. Testado apenas no Firefox.
// @license      MIT
// @version      2.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/Anaozinho/4shared-cleaner.meta.js
// @downloadURL  https://openuserjs.org/src/scripts/Anaozinho/4shared-cleaner.user.js
// @copyright 2017, Anaozinho (https://openuserjs.org/users/Anaozinho)
// ==/UserScript==

(function () {

  var urlis = window.location.href;

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

    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.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 = "PAUSADO";
        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.getElementsByClassName("MenuViews").length > 0) {
        changeViewModeAjax(2);
        clearInterval(loading);
      }

    }, 500);
  }

  setInterval(function () {
    var results = document.getElementsByClassName("jsSearchItemColumn").length - 1;
    var folderInfo = document.getElementsByClassName("jsFolderInfo");
    pages = results / 12;
    if (results % 12 === 0) {
      if (folderInfo.length > 1) {
        loop(results, folderInfo);
        titleFun();
      }
      else if (on && pages < 84) {
        document.getElementsByClassName("jsShowMoreResults")[0].click();
        titleFun();
      }
      else {
        if (pages >= 84) {
          document.title = "[FIM] " + pages + "/84 (" + found + "f / " + removed + "r)";
          document.getElementById("spanny").innerHTML = "FIM";
          document.getElementById("spanny").style.color = "#FF0000";
        }
        else {
          document.title = "[pause] " + pages + "/84 (" + found + "f / " + removed + "r)";
        }
      }
    }
  }, 100);

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

      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]) {
          folderInfo[1].parentElement.parentElement.parentElement.remove();
          removed++;
          broken = true;
          break;
        }
      }
      if (broken) break;
      found++;
      allURL.push(folderArray);
      folderInfo[1].parentElement.parentElement.innerHTML = "<a href=" + folderFullURL + " target='_blank' style='display: block; font-size:14px;position:relative; top:0px; padding:5px 5px; width:100%;height: 100%; width:100%; text-decoration: none; background-color: rgb(235,235,245);border-left: 6px solid red;word-wrap: break-word;'><span style='font-size:10px'>👤&nbsp;&nbsp;&nbsp;</span><span style='font-weight:bold'>" + userName + "</span><br><span style='font-size:14px'>⚑&nbsp;&nbsp;</span>" + folderArray + "<hr style='display: block; margin-top: 6px; margin-bottom:-1px;border-width: 1px; border-color: rgba(0,0,0,0.25);'><span style='font-family:Consolas;font-size:12px;'>" + folderCard + "</span></a>";
    }
  }

  function titleFun() {
    switch (fun) {
      case 0:
        document.title = "|.... " + pages + "/84 (" + found + "f / " + removed + "r)";
        fun++;
        break;
      case 1:
        document.title = ".|... " + pages + "/84 (" + found + "f / " + removed + "r)";
        fun++;
        break;
      case 2:
        document.title = ".|... " + pages + "/84 (" + found + "f / " + removed + "r)";
        fun++;
        break;
      case 3:
        document.title = "..|.. " + pages + "/84 (" + found + "f / " + removed + "r)";
        fun++;
        break;
      case 4:
        document.title = "...|. " + pages + "/84 (" + found + "f / " + removed + "r)";
        fun++;
        break;
      case 5:
        document.title = "....| " + pages + "/84 (" + found + "f / " + removed + "r)";
        fun = 0;
    }
  }

})();