Code
dump
♻ Codump - Dumped codes ♻

♻ Scripts and snippets of code dumped to recycle over and over again. ♻

I wanted to share my codes with you all and the generations that come. Try and have fun with it! It gives me joy that I could help you create something. I'm happy you're one of the makers group. Trying to build codes and making a better world! ✌️😎

Close a menu or element when clicked anywhere

Often we have a menu, modal or any other element that we want to close when you click outside of it. Therefor this little snippet that’s using jQuery.

1
2
3
4
5
6
7
8
$('html').click(function (e) {
  var offTarget = $(".offTarget"); // you can add this class to button and menu so it stays clickable //
  if (!offTarget.is(e.target) && offTarget.has(e.target).length === 0) {
    if($('#menu').is(':visible')){
      $('#closeTrigger').trigger('click'); // simulate click on close button //
    }
  }
});

Discord.js v14 basic bot functions

For another project I wanted to write a discord bot. And in some development discords I have meet people having a hard time making one. So why not share it!? I made the bot public sooner then was planned to help those people. So it’s still in development.

Features
  • The new slash commands.
    • /serverinfo Information about the server.
    • /automsgmention Automated message with mention.
    • /code How to use code on discord.
    • /jsfiddle Ask to start a jsfiddle.
    • /kick Kick a member.
    • /ban Ban a member.
    • /warning Warn a member and store it in DB.
  • Auto roles.
  • Join and leave notification.
  • Notification when someone starts streaming on discord.
  • GitHub notifications. (Releases, push, pull and more depending on your gh webhook settings.)
  • Ticket channel system.

Looking for free bot hosting? https://codump.github.io/go/bot-hosting/

Using JSON to save and display your posts on GitHub pages

When using GitHub pages, you can’t use a PHP back-end to handle and store your posts. Therefore I made this script that uses a JSON file to store the data of my posts. And then displays it on the Codump GitHub page you are looking at right now. Yes, this post is also stored in a JSON file and processed by JavaScript to display it to you. (not true anymore, using jekyll now, yet it stays a handy script)

On click dynamically created elements

When an element is dynamically created in the document/website the normal $('.addedElement').click(function(e){ / click function doesn’t work. The snippet below will solve that issue for u. When clicked on any element, dynamically added or not, with the class addedElement will run the function.

1
2
3
$(document).on('click', '.addedElement', function(){
	alert('Clicked on dynamic added element'); // Change to function you want.
});

Codump | Cheers and enjoy recycling codes!
© 2022 -