Skip to content

Instantly share code, notes, and snippets.

@BubuInc
Last active November 10, 2019 05:28
Show Gist options
  • Select an option

  • Save BubuInc/1ccc473240eaf0108646 to your computer and use it in GitHub Desktop.

Select an option

Save BubuInc/1ccc473240eaf0108646 to your computer and use it in GitHub Desktop.
Taringa! Hide Shouts
// ==UserScript==
// @name Taringa! Oculta Shouts
// @namespace MangaReader
// @description Oculta shouts de texto, o de imagen, o de video, o de enlace
// @author http://www.taringa.net/MangaReader
// @include http://www.taringa.net/*
// @exclude http://www.taringa.net/
// @exclude http://www.taringa.net/posts/*
// @exclude http://www.taringa.net/post/*
// @icon http://i.imgur.com/OQ928Nw.png
// @version 1.3
// @grant none
// ==/UserScript==
if (document.getElementsByClassName('activity-element')[0] && !document.getElementsByClassName('shout-individual')[0]) {
//Agregar estilo
var styleText = '#ocWr{position:fixed;bottom:5px;right:0px;color:#333;background-color:#CCC;z-index:10000}#ocBtn{position:absolute;bottom:0px;right:0px;background-color:inherit;width:40px;height:40px;font-size:44px;text-align:center;line-height:40px;border-top-left-radius:9px;border-bottom-left-radius:9px;border:1px solid #A4A2A2;box-shadow:2px 1px 2px rgba(0,0,0,0.46);border-right-width:0px;cursor:pointer;-moz-user-select:none;-webkit-user-select:none}#ocBtn:hover{background-color:#DDD;color:#666}#ocPanel{position:absolute;bottom:0px;right:0px;width:158px;height:190px;background-color:inherit;border-bottom-left-radius:9px;border-top-left-radius:9px;border:1px solid #999;border-right-width:0px;font-size:15px;line-height:30px;text-align:left;padding-left:8px;font-weight:bold}#ocPanel label{display:inline;cursor:pointer;padding-left:15px}#ocPanel input{cursor:pointer}';
var style = document.createElement('style');
style.textContent = styleText;
document.head.appendChild(style);
//Agregar estilos individuales
ids = ['styleTexto','styleImagen','styleVideo','styleEnlace','styleReshout'];
for (var i = 0; i < ids.length; i++) {
var style = document.createElement('style');
style.id = ids[i];
document.head.appendChild(style);
}
//variables y elementos
window.ocPos = 0;
window.ocPosDif = 0;
window.timeout = null;
if (document.getElementById('Feed-list')) { // mi
window.shoutsParent = document.getElementById('Feed-list');
}else if(document.getElementById('shouts')){ // perfil - mi
window.shoutsParent = document.getElementById('shouts');
}else{ // perfil - actividad
window.shoutsParent = document.getElementById('last-activity-container');
}
window.styleTexto = document.getElementById('styleTexto');
window.styleImagen = document.getElementById('styleImagen');
window.styleVideo = document.getElementById('styleVideo');
window.styleEnlace = document.getElementById('styleEnlace');
window.styleReshout = document.getElementById('styleReshout');
//Estructura
var div = document.createElement('div');
div.id = "ocWr";
div.innerHTML = ''+
'<div id="ocBtn">+</div>'+
'<div id="ocPanel" style="display:none">'+
'<span style="white-space: nowrap;">Mostrar shout de tipo</span><br>'+
'<label><input id="ocTexto" type="checkbox" checked>Texto</label><br>'+
'<label><input id="ocImagen" type="checkbox" checked>Imagen</label><br>'+
'<label><input id="ocVideo" type="checkbox" checked>Video</label><br>'+
'<label><input id="ocEnlace" type="checkbox" checked>Enlace</label><br>'+
'<label><input id="ocReshout" type="checkbox" checked>Reshout</label><br>'+
'</div>';
document.body.appendChild(div);
// Abre y cierra panel
document.getElementById('ocBtn').onclick = function () {
document.getElementById('ocPanel').style.display='';
window.addEventListener('scroll', ocultarOCPanel);
};
window.ocultarOCPanel = function () {
document.getElementById('ocPanel').style.display='none';
window.removeEventListener('scroll', ocultarOCPanel);
};
// Controladores de checkbox
window.ocListener = function (event) {
clearTimeout(timeout);
window.removeEventListener('scroll', ocultarOCPanel);
getPos();
var el,clase;
switch(event.target.id){
case 'ocTexto': el = styleTexto; clase = "shout"; break;
case 'ocImagen': el = styleImagen; clase = "image"; break;
case 'ocVideo': el = styleVideo; clase = "video"; break;
case 'ocEnlace': el = styleEnlace; clase = "link"; break;
case 'ocReshout': el = styleReshout; clase = "reshout"; break;
}
if (event.target.checked) { el.textContent = '';} //encender
else{ el.textContent = '.activity-element.'+clase+'{display:none}';} //apagar
fixScroll();
timeout = setTimeout(function () { //Retraso xq el estilo se ejecuta despues
window.addEventListener('scroll', ocultarOCPanel);
},2000);
};
var ids = ['ocTexto','ocImagen','ocVideo','ocEnlace','ocReshout'];
for (var i = 0; i < ids.length; i++) {
document.getElementById(ids[i]).onchange = function(event){ocListener(event);};
document.getElementById(ids[i]).onmousedown = function(event){event.preventDefault();};
}
//Consigue la posicion
window.getPos = function () {
for (var i = 0; i < shoutsParent.children.length; i++) {
if (shoutsParent.children[i].offsetTop > window.pageYOffset) {
ocPos = i;
ocPosDif = shoutsParent.children[i].offsetTop - window.pageYOffset;
break;
}
}
}
//Restaura posicion
window.fixScroll = function () {
for (var i = ocPos; i < shoutsParent.children.length; i++) {
if (getComputedStyle(shoutsParent.children[i],null).display != 'none') {
window.scrollTo(window.pageXOffset,shoutsParent.children[i].offsetTop - ocPosDif);
break;
}
}
}
//Reconoce los reshouts
window.addReshoutClass = function () {
for (var i = 0; i < shoutsParent.children.length; i++) {
if (shoutsParent.children[i].querySelector('.alter')) {
shoutsParent.children[i].classList.add('reshout');
}
}
}
addReshoutClass();
var observer = new MutationObserver(function(mutations) { addReshoutClass();});
observer.observe(shoutsParent, {childList: true});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment