Skip to content

Instantly share code, notes, and snippets.

View luckylooke's full-sized avatar

Ctibor Laky luckylooke

View GitHub Profile
@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)
);
// 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();
@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) {
// 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 / 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 / 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 / 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 / angularMergePolyfill.js
Last active November 27, 2017 07:56
angular.merge polyfill for angular < 1.4.0
if (!angular.merge) {
angular.merge = (function mergePollyfill() {
function setHashKey(obj, h) {
if (h) {
obj.$$hashKey = h;
} else {
delete obj.$$hashKey;
}
}
@luckylooke
luckylooke / cellAutoVoronoi.js
Last active October 6, 2017 00:01
Rewriten library cellauto to make it work on diagrams generated by Raymond Hill voronoi library( https://github.com/gorhill/Javascript-Voronoi )
// rewriten from http://sanojian.github.io/cellauto/
function CellAutoVoronoiCell(index) {
this.index = index;
this.delays = [];
}
CellAutoVoronoiCell.prototype.process = function(neighbors) {
return;
};
@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.