Skip to content

Instantly share code, notes, and snippets.

View JokingChicken's full-sized avatar
🐔
Always working, just not on the things I should...

DanJ JokingChicken

🐔
Always working, just not on the things I should...
View GitHub Profile
@JokingChicken
JokingChicken / notifications.js
Last active September 19, 2018 10:53
simple notification handling
/*
* creator: Danj (https://github.com/DanBrothers)
* description: custom notification, made for easy configuration (works with mobile)
* license: MIT, please link to this if you copy (thanks)
*
* usage:
var customnotes = new customnotes({
enabled: true,
default: false
});
@JokingChicken
JokingChicken / presskey.js
Created July 12, 2018 21:46
press a key in html
function openf12() {
var keyboardEvent = document.createEvent("KeyboardEvent");
var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ? "initKeyboardEvent" : "initKeyEvent";
keyboardEvent[initMethod](
"keydown", // event type : keydown, keyup, keypress
true, // bubbles
true, // cancelable
window, // viewArg: should be window
@JokingChicken
JokingChicken / contextmenu.js
Last active September 11, 2018 12:17
custom right click menu for html (support for mobile)
/*
* creator: Danj (https://github.com/DanBrothers)
* description: contextmenu, made for easy configuration (contextmenu = the right-click menu)
* license: MIT, please link to this if you copy (thanks)
*
* usage:
var contextmenu = new contextmenu({
enabled: true
});
@JokingChicken
JokingChicken / changecssjs.html
Last active July 12, 2018 19:46
Modifying a stylesheet rule with CSSOM
<!-- Learn about this code on MDN: https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/Using_dynamic_styling_information -->
<html>
<head>
<title>Modifying a stylesheet rule with CSSOM</title>
<style type="text/css">
.test {
background-color: red;
}
@JokingChicken
JokingChicken / imgtobase64.js
Last active July 1, 2018 09:25
encode and decode img from base64
/*
* creator: Danj (https://github.com/DanBrothers)
* description: encode and decode img from base64
* license: MIT, please link to this if you copy (thanks)
*
* usage:
var base64 = getBase64FromImage(document.getElementById("imageid"));
var img = getImageFromBase64(base64);
*/
@JokingChicken
JokingChicken / logger.js
Last active November 20, 2018 10:22
a custom logger for js
/*
* creator: Danj (https://github.com/DanBrothers)
* description: logger, made for easly configuration
* license: MIT, please link to this if you copy (thanks)
*
* usage:
var console = new Logger({
enabled: true,
enabledebug:true,
customfunction: function(e){
@JokingChicken
JokingChicken / sort.js
Created June 19, 2018 20:39
sort a object by a objectkey
/*
* creator: Danj (https://github.com/DanBrothers)
* description: sort a array by key values
* license: MIT, please link to this if you copy (thanks)
*
* usage:
//returns a sorted array
sortby(array, {
desc: true,
prop: "name",
@JokingChicken
JokingChicken / makerandomid.js
Last active September 11, 2018 09:04
create string of random characters
//make a random id with specified length, and get chars out of specified string
function makeid(length, string) {
var text = "";
//the list of chars to pick chars for id
var possible = (string ? string : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
//iterate over every char, with default length of 8 characters
while (text.length < (length ? length : 8)) {
//add a random picked char from "possible"
@JokingChicken
JokingChicken / Uploaderprogress.html
Last active September 11, 2018 10:02
When uploading something get the procentage
<script>
/*usage:
request("get", "https://github.com/DanBrothers/danbrothers.github.io/blob/master/js/main.js", null,
function(status, data) {
if(status==="percent") {
console.log("file progress: " + data + "%");
}
if(...) {
@JokingChicken
JokingChicken / getdiff.js
Last active June 17, 2018 21:40
check diffrence between two arrays
/*
* creator: Danj (https://github.com/DanBrothers)
* description: check diffrence between two arrays
* license: MIT, please link to this if you copy (thanks)
*
* usage:
//returns array of diffrences
diff(arrayone, arraytwo);
//can also be used to check two files, by creating two arrays of the two files