Last active
August 23, 2017 18:08
-
-
Save pstachula-dev/dffd44bcbec0d17c9b6c957c0487bc52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/ald890/dffd44bcbec0d17c9b6c957c0487bc52#file-zielonki-js-L7-L8
zmienić to z http na https