Skip to content

Instantly share code, notes, and snippets.

View luckylooke's full-sized avatar

Ctibor Laky luckylooke

View GitHub Profile
// Mouse vs touch detection, supporting devices which are capable of both
// by default set using touch for all touch enabled devices
let userUsesTouch =
'ontouchstart' in document.documentElement ||
navigator.maxTouchPoints > 0 ||
navigator.msMaxTouchPoints > 0;
if (userUsesTouch) {
catchMouse();
// taken from https://stackoverflow.com/questions/11849562/how-to-save-the-output-of-a-console-logobject-to-a-file
(function(console){
console.save = function(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
@luckylooke
luckylooke / fake_date.js
Last active July 22, 2022 13:53
fake Date in devTools for testing
// Context https://stackoverflow.com/a/72640597/861615
// Save the original `Date` function
const OriginalDate = Date;
const fakeDateArgs = [2022, 5, 3]; // beware month is 0 based
let fakeDate;
// Replace it with our own
Date = function Date(...args) {
// Called via `new`?
if (!new.target) {
@luckylooke
luckylooke / change_captcha_v2_lang.js
Created August 22, 2019 15:03
Changing reCAPTCHA v2 lang dynamically
function setCaptchaLang(lang) {
const container = document.getElementById('captcha_container');
// Get GoogleCaptcha iframe
const iframeGoogleCaptcha = container.querySelector('iframe');
// Get language code from iframe
const actualLang = iframeGoogleCaptcha.getAttribute("src").match(/hl=(.*?)&/).pop();
@luckylooke
luckylooke / recaptcha_fallback.js
Created August 21, 2019 13:24
Google recaptcha wrapper for grecaptcha.execute() with version 2 fallback.
function execute(action, callback) {
// create real promise, because execute method does not return the real one
// (missing documentation what actually returns)
const promise = new Promise((resolve, reject) => {
grecaptcha.ready(() =>
grecaptcha.execute(key, { action }).then(token => {
resolve(token);
},
reject)
);
@luckylooke
luckylooke / aliexpress-precheck.js
Created December 27, 2017 13:25
User Script - (userscript) precheck checkboxes in order detail
// ==UserScript==
// @name Aliexpress - precheck order detail
// @namespace https://aliexpress.com/
// @version 1.0.0
// @description precheck checkboxes in order detail
// @author luckylooke
// @match https://trade.aliexpress.com/order_detail.htm*
// @grant none
// ==/UserScript==
@luckylooke
luckylooke / aliexpress-feedback.js
Last active April 2, 2021 07:21
User script (userscript) prefill 5-star rating in aliexpress feedback
// ==UserScript==
// @name Aliexpress feedback
// @namespace https://feedback.aliexpress.com/
// @version 1.1.0
// @description prefill 5-star rating in aliexpress feedback
// @author luckylooke
// @match https://feedback.aliexpress.com/management/leaveFeedback.htm*
// @grant none
// ==/UserScript==
@luckylooke
luckylooke / design.md
Last active June 15, 2017 07:10
Modern js library design

Modern js library design

How to design library the most efficient way?

Problem description

I have an idea about ideal lib design. But seems to be not easy to achieve it. I want to support [standard ES6 module], also other common use cases supported by [UMD]. BUT there is one more use case I want to support and so there is where the problem begins. I want to be able to switch parts of a library to different implementation.

USE CASE 1 - ES6 module

The library is provided as pure standard ES6 module, without UMD or similar bundler specific wraps.

@luckylooke
luckylooke / spinner.html
Last active April 5, 2017 16:44 — forked from jiripudil/spinner.html
Pure JavaScript spinner
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Pure JS spinner</title>
<style>
#spinner { font-size: 6em; }
</style>
</head>
@luckylooke
luckylooke / installYoCloud9.rm
Created January 1, 2016 14:55
Installing yeoman in cloud9 enviroment
// install latest stable node
nvm install stable
// install yoman
npm install -g yo
// yoman automaticly check enviroment via yoman doctor, copypaste sugested command into terminal
echo "export NODE_PATH=$NODE_PATH:/home/ubuntu/.nvm/versions/node/v5.3.0/lib/node_modules" >> ~/.bashrc && source ~/.bashrc
// you can check again that everything is OK now
yo doctor