Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var imageBlacklist = [] ;
- function loadImageBlacklist() { JSON.parse(localStorage.imageBlacklist || "[]").forEach(addToImageBlacklist); }
- function saveImageBlacklist() { localStorage.imageBlacklist = JSON.stringify(imageBlacklist); }
- function addToImageBlacklist(md5) { if (md5 && -1 === imageBlacklist.indexOf(md5)) imageBlacklist.push(md5); }
- function removeImageFromBlacklist(md5) { var index = imageBlacklist.indexOf(md5); if (-1 !== index) imageBlacklist.splice(index, 1); }
- function blacklistPostImages(post) { $(post).find('img.post-image').each(function (i, el) { var md5 = el.getAttribute('data-md5'); addToImageBlacklist(md5); $(el).addClass('nope'); }); }
- function removeBlacklistedImages() { $('img.post-image').each(function (i, el) { if (-1 !== imageBlacklist.indexOf(el.getAttribute('data-md5'))) { $(el).addClass('nope'); } }); }
- function onNopeClicked(event) { event.preventDefault(); event.stopPropagation(); loadImageBlacklist(); var post = $(event.target).closest('.post'); blacklistPostImages(post); removeBlacklistedImages(); saveImageBlacklist(); }
- function addNopeButtons() { $('.post').each(function(i, post) { if ($(post).find('input.nope').length === 0) { $(post).prepend("<input type='button' class='nope' onClick='onNopeClicked(event)' value='Nope'></input>"); } }) }
- setInterval(function () { loadImageBlacklist(); removeBlacklistedImages(); addNopeButtons(); }, 500);
- $('body').on('click', 'img.nope', function (event) { event.preventDefault(); event.stopPropagation(); $(this).removeClass('nope'); removeImageFromBlacklist(this.getAttribute('data-md5')); saveImageBlacklist(); });
Add Comment
Please, Sign In to add comment