Skip to content

Instantly share code, notes, and snippets.

View podgorniy's full-sized avatar

Dmitro Podgorniy podgorniy

View GitHub Profile
@podgorniy
podgorniy / .block
Last active February 27, 2020 22:31
X-Value Mouseover with Droplines
license: gpl-3.0

Create bookmarklet out of code below and click it on reddits gifs

javascript:(function%20()%20{'use%20strict';%20var%20links%20=%20document.querySelectorAll('.expando-button');%20for%20(var%20i%20=%200;%20i%20<%20links.length;%20i%20+=%201)%20{links[i].click();%20}%20}());void(0);
function in_the_morning () {
var now,
breakfast;
now = me.look_at_watch();
if (now > TOO_LATE || now < TOO_EARLY) {
try {
me.continue_sleeping();
} catch (err) {
me.do_stuff();
@podgorniy
podgorniy / iterate.js
Created April 23, 2012 08:10
Universal iterator through arrays, array-like objects and objects. Now to run through data, you do not need to care about data representation (array or object)
/*
exaple of use
var data, processed;
data = [10,20,30,40];
processed = iterate(data, function (val, i) {
console.log(val);
});
@podgorniy
podgorniy / wait_for.js
Created April 18, 2012 12:03
Some condition waiter with no blocking ui with synchronious first condition call.
/*
example of use: wait for jQuery load for 5 sec
wait_for(function (){
return window.jQuery;
}, function () {
$('body').addClass('js');
}, 5000);
*/
function wait_for (condition, callback, timeout, interval) {
@podgorniy
podgorniy / decorate.js
Created March 31, 2012 15:29
Safe javascript decorator
/*
Example of use
document.write = decorate (document.write, function () {
console.log(this === document);// true;
}, function () {
console.log('DOM is updated');
});
document.write = decorate (document.write, null, function () {
console.log('After document.write');
@podgorniy
podgorniy / class_name.js
Created March 19, 2012 14:51
Multiple class names search
/*
exaplme of use
has_class(document.body, 'main');
has_class(document.body, 'content wrapper js-on');
has_class(document.body, 'js-on content wrapper');
*/
function has_class (node, class_names) {
var classes, i;
@podgorniy
podgorniy / decorate.js
Created March 6, 2012 10:55
Simple function decorator
function decorate (initial, decorate_before, decorate_after) {
return function () {
var initial_call_result;
if (typeof decorate_before === 'function') {
decorate_before();
}
initial_call_result = initial.apply(this, arguments);
if (typeof decorate_after === 'function') {
decorate_after();
@podgorniy
podgorniy / get_computed_styles.js
Created January 3, 2012 18:36
Get object with computed styles from the node
/**
* Return object with computed styles
* @param {DOMNode} node
* @param {String|Array} styles_to_get "float colot padding-top" or ["float", "padding-top", "padding-bottom"]
* @return {Object} list of styles values {
* "float" : "none",
* "color" : "#000000"
* }
*/
function get_computed_styles(node, styles_to_get) {
@podgorniy
podgorniy / teplater.js
Created December 22, 2011 16:40
Простейший шаблонизатор
/**
* Using yajt('<div class="$class_name$">$data$</div>', {class_name: 'main', data: 'Hello, world'})
* @param {String} template string
* @param {Object} data key-value data storage
* @return {String}
*/
function yajt (template, data) {
"use strict";
var res;
res = template.replace(/\$([^\$]+)?\$/g, function (match_string, param_name) {