NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name 4shinfinito // @namespace http://tampermonkey.net/ // @updateURL https://openuserjs.org/meta/poots/4shinfinito.meta.js // @downloadURL https://openuserjs.org/src/scripts/poots/4shinfinito.user.js // @version 0.78 // @description Infinite Scroll no Search com a listagem em modo 'miniatura' + Visualização Alternativa de Pastas + opcoes // @author poots // @collaborator garimpador // @match https://search.4shared.com/q/* // @match https://www.4shared.com/q/* // @match https://www.4shared.com/folder/* // @match https://www.4shared.com//folder/* // @match https://search.4shared.com/network/listAllSearchFiles.jsp* // @match https://www.4shared.com/web/q* // @require https://code.jquery.com/jquery-2.2.4.min.js // @grant none // ==/UserScript== (function ($, undefined) { $(function () { var optsElem, itemSelector, separador, arrBlockedUsers, filtroUsers = [], labelUsers = [], filtrosPasta = []; optsElem = $('.row.header-row'); var tab = window.location.toString().indexOf('listAllSearchFiles.jsp') > 0 ? true : false; var optsStyle = "width:"+optsElem.css('width')+";display:inline-block;text-align:right;cursor:pointer"; var fillStyle = "width:"+optsElem.css('width'); var dOptsSent = "Filtra as pastas com o nome Sent, do Whatsapp"; var dOptsAggr = "Carrega todas as páginas automaticamente"; var dOptsBr = "Bloqueia conteúdo não brasileiro"; var vOptsAggr = (localStorage.getItem('vOptsAggr') === 'true'); var vOptsBr = (localStorage.getItem('vOptsBr') === 'true'); var vOptsSent = (localStorage.getItem('vOptsSent') === 'true'); var aOpts = "<a id='optsAggr' title='"+dOptsAggr+"'>Carregamento agressivo: "+(vOptsAggr === true ? "ON" : "OFF")+" </a>"; var lista = $("#list_view").is('.cheked_view'); var pontoCarrega = $('.pagerOn').length <= 0 ? null : $('.pagerOn').offset().top; var triggered = false; var isFolder = window.location.href.search("/folder/") !== -1; var patr = /[IMG|VID]+-\d+-WA(\d+)/i; var res = patr.exec(window.location.href); var stop = false; var handlerFireRegexpHide; var regexpFiltered = false; filtrosPastaMngr = {}; MutationObserver = window.MutationObserver || window.WebKitMutationObserver; filtrosPastaMngr.persiste = function() { localStorage.setItem('filtrosPasta', JSON.stringify(filtrosPastaMngr.filtros)); filtrosPastaMngr.filtros = JSON.parse(localStorage.getItem('filtrosPasta')); //console.log(filtrosPastaMngr.filtros); } filtrosPastaMngr.adicionaItem = function(item) { filtrosPastaMngr.filtros.push(item); filtrosPastaMngr.persiste(); } filtrosPastaMngr.removeItem = function(index) { filtrosPastaMngr.filtros.splice(index, 1); filtrosPastaMngr.persiste(); } filtrosPastaMngr.mudaItem = function(index, val) { if (typeof(filtrosPastaMngr.filtros[index]) !== 'undefined') { filtrosPastaMngr.filtros[index][1] = val; filtrosPastaMngr.persiste(); } } filtrosPastaMngr.init = function() { if (localStorage.getItem('filtrosPasta') === null) { localStorage.setItem('filtrosPasta', JSON.stringify([["^FB_", true]])); } filtrosPastaMngr.filtros = JSON.parse(localStorage.getItem('filtrosPasta')); } filtrosPastaMngr.init(); if (localStorage.getItem('vOptsAggr') === null) { localStorage.setItem('vOptsAggr', false); } if (localStorage.getItem('vOptsBr') === null) { localStorage.setItem('vOptsBr', false); } if (localStorage.getItem('vOptsSent') === null) { localStorage.setItem('vOptsSent', false); } if (localStorage.getItem('blockedUsers') !== null) { arrBlockedUsers = JSON.parse(localStorage.getItem('blockedUsers')); } if (tab) { itemSelector = 'table.listView tr:has(td.simpleThumb)'; separador = $(itemSelector+':first').next('tr'); $(".mainHeader").css('height', 'auto'); $("body").append($("<div />").css({'position':'fixed', 'right':'5px','top' : '5px', 'z-index': '100', 'max-height': '50%', 'overflow': 'auto'}).prop('id','filtrosInfini')); $("#filtrosInfini").prepend("<a id='restartInfini' style='width: 100%;display: inline-block;' href='"+$(".pagerOn").next('td').find('a').attr('href')+"'>Reload</a>"); $(itemSelector).addClass('processing'); aOpts += "<br /><a id='optsBr' title='"+dOptsBr+"'>Conteúdo brasileiro: "+(vOptsBr === true ? "ON" : "OFF")+" </a>"; } else { itemSelector = '.jsSearchItemColumn.jsVisibleItemColumn'; //optsElem = $(".blueBox.signed .centered.clearFix"); } aOpts += "<br /><a id='optsSent' title='"+dOptsSent+"'>Filtrar pasta sent: "+(vOptsSent === true ? "ON" : "OFF")+" </a>"; optsElem.append('<div style="'+fillStyle+'"></div><div style="'+optsStyle+'">'+aOpts+'</div>'); processBlocked(); if (vOptsAggr && tab && (!$(itemSelector).length)) { carregaProximaPagina(); } if ((res !== null) && (typeof(res[1]) !== 'undefined')) { var t = parseInt(res[1]); t++; var sufixo = ("0".repeat(4-(t.toString().length)))+t; var novaUrl = window.location.href.replace(/WA\d+/, "WA"+sufixo); var ar = $("<a/>").attr('href', novaUrl).html("WA"+sufixo).attr('id', "proximo"); $(".results-info").after(ar); $(document).on('keydown', 'body', function(e){ if (e.keyCode == 38) { $("#proximo")[0].click(); } else if (e.keyCode == 40) { //sim, eu sei res = patr.exec(window.location.href); if ((res !== null) && (typeof(res[1]) !== 'undefined')) { var t = parseInt(res[1]); if (t >= 1) { var oldSufixo = ("0".repeat(4-(t.toString().length)))+t; t--; var sufixo = ("0".repeat(4-(t.toString().length)))+t; var novaUrl = window.location.href.replace(/WA\d+/, "WA"+oldSufixo); var ar = $("<a/>").attr('href', novaUrl).html("WA"+oldSufixo).attr('id', "proximo"); $("#proximo").replaceWith(ar); window.location.href = window.location.href.toString().replace("WA"+oldSufixo, "WA"+sufixo); } } } }); setTimeout(proximo, 50); } if (isFolder) { var link = window.location.href.replace("/folder", "//folder"); $(".d1mainButtons .centered").append("<a href='" + link + "' class='d1btn floatRight' style='background: #2679d3 !important; color: #fff !important;'>Visualização Alternativa</a>"); if ($(".actionButtons").length) { buildFiltrosPanel(); } } $(window).scroll(function () { pontoCarrega = tab ? pontoCarrega : ($(".pagerHolder.jsPagerWrapper").offset().top+$(".pagerHolder.jsPagerWrapper").height()); if ((($(this).scrollTop() + $(window).height()) >= pontoCarrega) && (!triggered) && (!window.$.active)) { carregaProximaPagina(); } }); $(document).on("click", "#filtrosRegexp", function(){ $("#filtrosRegexpContainer").toggle(); }); $(document).on("click", "#regexpSubmit", function(){ var rxval = $("input[name='regexVal']").val(); var valid = false; if (rxval.length > 0) { try { var rx = new RegExp(rxval); valid = true; } catch(e) { valid = false; } if (valid) { //console.log("/"+rxval+"/ is a valid Regexp"); var r = [rxval, true]; filtrosPastaMngr.adicionaItem(r); buildFiltrosPanel(); } else { alert(rxval+" é um RegExp inválido"); } } }); $(document).on('change', '.userCb', function(){ var uid = getUid($(this).next('a').prop('href')); if (localStorage.getItem('blockedUsers') === null) { localStorage.setItem('blockedUsers', JSON.stringify([])); } arrBlockedUsers = JSON.parse(localStorage.getItem('blockedUsers')); if ($(this).is(':checked')) { var index = arrBlockedUsers.indexOf(uid); if (index > -1) { arrBlockedUsers.splice(index, 1); } } else { arrBlockedUsers.push(uid); } localStorage.setItem('blockedUsers', JSON.stringify(arrBlockedUsers)); arrBlockedUsers = JSON.parse(localStorage.getItem('blockedUsers')); processBlocked(); }); $(document).on('click', "#proximo", function(ev){ res = patr.exec(window.location.href); if ((res !== null) && (typeof(res[1]) !== 'undefined')) { var t = parseInt(res[1]); t++; t++; var sufixo = ("0".repeat(4-(t.toString().length)))+t; var novaUrl = window.location.href.replace(/WA\d+/, "WA"+sufixo); var ar = $("<a/>").attr('href', novaUrl).html("WA"+sufixo).attr('id', "proximo"); $("#proximo").replaceWith(ar); } }); $(document).on('click', '.removeFiltro', function() { var ind = $(this).index('#filtrosRegexpContainer .removeFiltro'); filtrosPastaMngr.removeItem(ind); buildFiltrosPanel(); }); $(document).on('change', "input[type='checkbox'][name^='regexp']", function() { var val = $(this).is(':checked'); var ind = $(this).index("#filtrosRegexpContainer input[type='checkbox']"); filtrosPastaMngr.mudaItem(ind, val); buildFiltrosPanel(); }); $("#optsAggr").on('click', function(ev) { ev.preventDefault(); localStorage.setItem('vOptsAggr', !vOptsAggr); vOptsAggr = !vOptsAggr; $("#optsAggr").html("Carregamento agressivo: "+((vOptsAggr) === true ? "ON" : "OFF")); if (vOptsAggr && tab && (!$(itemSelector).length)) { carregaProximaPagina(); } }); $("#optsBr").on('click', function(ev) { ev.preventDefault(); localStorage.setItem('vOptsBr', !vOptsBr); vOptsBr = !vOptsBr; $("#optsBr").html("Conteúdo brasileiro: "+((vOptsBr) === true ? "ON" : "OFF")); if (vOptsBr) { processBlocked(); } }); $("#optsSent").on('click', function(ev) { ev.preventDefault(); localStorage.setItem('vOptsSent', !vOptsSent); vOptsSent = !vOptsSent; $("#optsSent").html("Filtrar pasta sent: "+((vOptsSent) === true ? "ON" : "OFF")); if (vOptsSent) { processBlocked(); } }); function buildFiltrosPanel() { $("#filtrosRegexpHolder").remove(); $("#filtrosRegexp").remove(); var panelHolder = $("<div>").css("position", "relative").attr("id", "filtrosRegexpHolder"); var container = $("<div>").css("cursor", "normal").css("position", "absolute").css("height", "200px").css("width", "200px").css("border", "1px solid #aeaeae").css("display", "none").css("z-index", "100").css("top", "50px").attr("id", "filtrosRegexpContainer").addClass('menu-gray-button'); panelHolder.append(container); var btnFiltros = $("<li>").addClass('menu-gray-button floatLeft').attr('id', 'filtrosRegexp'); var lbl = $("<a>").text('Filtros'); var inp = $("<input />").attr('name', 'regexVal').css('margin', '10px 0 0 10px').attr('placeholder', 'Filtro Regexp'); var subm = $("<input />").attr('type', 'button').val('+').css('margin', '10px 0 0 10px').attr('id', 'regexpSubmit'); btnFiltros.append(lbl); container.append(inp); container.append(subm); for (var k in filtrosPastaMngr.filtros) { if (filtrosPastaMngr.filtros.hasOwnProperty(k)) { var linkRemove = $("<a class='removeFiltro'>X</a>").css('margin-right', '8px'); var s = $("<span>").html(filtrosPastaMngr.filtros[k][0]).css('width', '100%').css('display', 'inline-block').css('box-sizing', 'border-box').css('padding-left', '10px'); s.prepend(linkRemove); var inp = $("<input />").attr('type', 'checkbox').attr('name', 'regexp['+k+']').val(k).css('margin-left', '3px'); if (filtrosPastaMngr.filtros[k][1] == true) { inp.attr('checked', 'checked'); } s.append(inp); container.append(s); } } $(".actionButtons").prepend(btnFiltros); $(".actionButtons").prepend(panelHolder); } function regexpHide() { var refreshThumbs = false; for (var f in filtrosPastaMngr.filtros) { if (filtrosPastaMngr.filtros[f][1] === true) { try { var r = new RegExp(filtrosPastaMngr.filtros[f][0]); $("#jsFilesTable .jsCanPreview .thumbFilename > .thumbFilenameText > .jsName").each(function(){ if (r.exec($(this).html()) !== null) { $(this).parent().parent().parent().remove(); refreshThumbs = true; } }); removeFromAccFacade(r); refreshThumbs = regexpFiltered = true; } catch (e) { console.log(e); } } } if (refreshThumbs) { AccountFacade.fillFileListThumbnails(); } } function removeFromAccFacade(r) { var found = false; for (var i = 0; i < AccountFacade.info.files.length; i++) { if (r.exec(AccountFacade.info.files[i].name) !== null) { AccountFacade.info.files.splice(i, 1); found = true; } } if (found) { removeFromAccFacade(r); } else { return; } } function getUid(href) { var rUid = /www\.4shared\.com\/u\/([\w|\-]+)\//i; var ret = rUid.exec(href); return ret[1]; } function processBlocked() { if (vOptsSent) { if (tab) { $(itemSelector+":not(:has(.sfolder))").next('tr').remove(); $(itemSelector+":not(:has(.sfolder))").remove(); $(itemSelector+" .fname:has(span) span a:not(:contains('Sent'))").parent().parent().parent().parent().parent().next('tr').remove(); $(itemSelector+" .fname:has(span) span a:not(:contains('Sent'))").parent().parent().parent().parent().parent().remove(); } else { $(itemSelector+" .jsFolderInfo:not(:visible)").parent().parent().parent().parent().remove(); $(itemSelector+" .jsFolderInfo:not(:contains('Sent'))").parent().parent().parent().remove(); $(".jsSearchItemColumn.jsVisibleItemColumn:not(:has(.cat-item))").remove(); } } if (tab) { pontoCarrega = $('.pagerOn').offset().top; } else { if ($(".pagerHolder.jsPagerWrapper").length) { pontoCarrega = $(".pagerHolder.jsPagerWrapper").offset().top+$(".pagerHolder.jsPagerWrapper").height(); } } } function proximo() { if ((($(".blue.medium").length) && (!stop)) || ((!$(".user").length)) && ($('#grid_view').is('.cheked_view')) && (!$("td.pager").length)) { $("#proximo")[0].click(); } if ($("td.pager").length && vOptsAggr && (!$(".user").length)) { carregaProximaPagina(); } } function carregaProximaPagina() { if (vOptsBr || vOptsSent) { processBlocked(); } var proximoLink = $('.pagerOn').next('td').find('a').attr('href'); triggered = true; if (tab) { $("#restartInfini").attr('href', proximoLink); if (typeof(proximoLink) !== 'undefined') { $.ajax({ 'url' : proximoLink, 'success' : function(data){ if (!lista) { var novoPager = $("table:has(.pager):last", data); var maisItems = $(itemSelector, data); $(maisItems).addClass('processing'); if ($(itemSelector).length) { if (!tab) { $(itemSelector+':last').after(maisItems); } else { $('table.listView.res_table > tbody > tr:last').after(maisItems); $(itemSelector+'.processing:first').nextAll('tr').before(separador[0].outerHTML); $('table.listView.res_table > tbody > tr:last').after(separador[0].outerHTML); } } else { $('.thumbView.clearFix').append(maisItems); } $("table:has(.pager):last").replaceWith(novoPager); triggered = false; pontoCarrega = $('.pagerOn').offset().top; if (vOptsBr || vOptsSent) { processBlocked(); } if (vOptsAggr) { carregaProximaPagina(); } } } }); } else if (vOptsAggr && $("#proximo").length && ($("td.pager").length && $("td.pagerOn").is('td:not(.next):last')) && (!$(".user").length)) { $("#proximo")[0].click(); } } else { if ($('.jsPagerNext:visible').length) { $(".jsShowMoreResults").trigger('click'); } } } function afterThumbsLoaded() { regexpHide(); } if (isFolder) { var observer = new MutationObserver(function(mutations, observer){ var nodesAdded = 0; triggered = true; mutations.forEach(function(mutation) { if (mutation.addedNodes.length) { for (var i = 0; i < mutation.addedNodes.length; i++) { if (mutation.addedNodes[i].className.indexOf("thumbFilenameText") >= 0) { if (!regexpFiltered) { window.clearTimeout(handlerFireRegexpHide); handlerFireRegexpHide = window.setTimeout(afterThumbsLoaded, 500); } } } } }); }); if ($("#includeFileList").length) { observer.observe($("#includeFileList")[0],{subtree:true, childList:true, attributes:false, characterData:true}); } } if (!tab) { var observerTab = new MutationObserver(function(mutations, observer){ var nodesAdded = 0; triggered = true; mutations.forEach(function(mutation) { if (mutation.addedNodes.length) { if ($(mutation.previousSibling).is(itemSelector)) { nodesAdded++; } } }); triggered = false; if (nodesAdded) { if (vOptsBr || vOptsSent) { processBlocked(); } if (vOptsAggr && !window.$.active && !triggered) { carregaProximaPagina(); } } $(".file-info:has(.jsFolderInfo:visible):not(:has(.visualizacaoAlt)) .add-to-acc").each(function(){ var link = $(this).parent().find('.jsFolderInfo').attr('href'); $(this).before("<a href='https://www.4shared.com/" + link + "' class='d1btn floatRight visualizacaoAlt' style='background: #2679d3 !important; color: #fff !important;position:absolute;right:12px;padding:5px;border-radius: 5px;z-index:99' target='_blank'>Visualização Alternativa</a>"); }); }); if ($(".jsSearchResHolder").length) { observerTab.observe($(".jsSearchResHolder")[0],{subtree:false, childList:true, attributes:false, characterData:true}); } } }); })(window.jQuery.noConflict(true));