Skip to content

Instantly share code, notes, and snippets.

@pstachula-dev
Last active August 23, 2017 18:08
Show Gist options
  • Save pstachula-dev/dffd44bcbec0d17c9b6c957c0487bc52 to your computer and use it in GitHub Desktop.
Save pstachula-dev/dffd44bcbec0d17c9b6c957c0487bc52 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name GreenIsBad
// @namespace GreenIsBad
// @version 0.2
// @description Ukrywa wpisy/komentarze zielonek za spojlerami
// @author Feuer
// @match http://wykop.pl/*
// @match http://www.wykop.pl/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var ZielonkiWykopki = {
/**
* Bootstrap
*/
ready: function () {
this.mapComments();
this.moreComments();
},
/**
* Nasze dane
*/
data: {
toggleText: 'Geen Is Bad!',
comments: function () {
return document.querySelectorAll('.color-0');
},
moreComments: function () {
return document.querySelectorAll('.sub .color-0');
},
},
/**
* Mapuje komentarze po kliknieciu więcej
*/
moreComments: function () {
var self = this;
$(document).ajaxSuccess(function(e, xhr) {
var jsonData = xhr.responseJSON.operations;
if(jsonData && jsonData.length) {
var type = jsonData[0].type;
if(type === 'replace' || type === 'content') {
self.replaceComment({
data: document.querySelectorAll('.sub .color-0'),
handler: '.text'
});
}
}
});
},
/**
* Mapuje komentarze na stronie głównej
*/
mapComments: function () {
this.replaceComment({
data: this.data.comments(),
handler: 'div'
});
},
/**
* Podmienia komentarze zielonek
*/
replaceComment: function(options) {
var comments = options.data;
var handler = options.handler;
for (var i = 0; i < comments.length; i++) {
var oldContainer = $(comments[i]).parent().next(handler);
var oldContent = oldContainer.html();
var newContent = '';
var newContainer = 'gibHidden' + i;
if(typeof(oldContent) != 'undefined') {
newContent = oldContent.replace('data-original','src');
}
var greenIsBad = '';
greenIsBad += '<a onclick="$(\'#'+newContainer+'\').toggle()" href="javascript:void()" style="color:red;font-weight:bold">'+ this.data.toggleText +'</a>';
greenIsBad += '<div id="'+newContainer+'" style="display:none">' + newContent + '</div>';
oldContainer.html(greenIsBad);
}
}
};
ZielonkiWykopki.ready();
})();
@xmesaj2
Copy link

xmesaj2 commented Aug 8, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment