Skip to content

Instantly share code, notes, and snippets.

String.prototype.htmlEntities = function( reverse = 0 ){
let thisString = this;
let entities = [' ', '<', '>', '"', '\'', '¢', '£', '¥', '€', '©', '®'];
let htmlEntities = ['&nbsp;', '&lt;', '&gt;', '&quot;', '&apos;', '&cent;', '&pound;', '&yen;', '&euro;', '&copy;', '&reg;'];
if( reverse == 0 ){
thisString = thisString.replace(/&/g, 'ΠπϖⲠⲡhE');
for(let i = 0; i < 11; i++){
thisString = thisString.replace( new RegExp( entities[i] , 'g'), htmlEntities[i] ).replace(/ΠπϖⲠⲡhE/g, '&amp;');
//jQuery_if_landscape.js
let landscape = $(window).innerWidth() >= $(window).innerHeight() ? true : false;
//input: jsonToArray({a: 1, b: 2 , c: 3});
//output: [ ['a', 'b', 'c'], [1, 2, 3] ];
function jsonToArray(obj){
let returnArray = [];
let key = [];
let values = [];
for( let thisKey in obj ){
//console.log( thisKey + ': ' + obj[thisKey] );
key.push( thisKey );
values.push( obj[thisKey] );
<!doctype html>
<html lang="pt-BR">
<head>
<meta charset="utf-8" />
<title>align center with table-container</title>
<style>
body{
margin: 0;
padding: 0;
border: 0;
let array = ['a', 'b', 'c'];
array.forEach(function( item, index ){
console.log( item, index );
});
function mouseMoving(element, movementSpeed = 1) {
if (typeof element == 'string') {
element = $(element);
};
element.css({
'position': 'relative'
});
$(document).on('mousemove', function(event) {
let x = event.pageX * 100 / $(document).innerWidth();
let y = event.pageY * 100 / $(document).innerHeight();
//phone
let SPMaskBehavior=function(s){return 11===s.replace(/\D/g,'').length?'(00) 00000-0000':'(00) 0000-00009'},spOptions={onKeyPress:function(s,a,e,n){e.mask(SPMaskBehavior.apply({},arguments),n)}};$('.sp_celphones').mask(SPMaskBehavior,spOptions);
//jquery-mask-latin-characters
$('input[name="nome"]').mask(
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
{translation:{'A':{pattern:/[ \.a-zA-ZÀÁÂÃÄÅàáâãäåÈÉÊËèéêëÌÍÎÏìíîïÒÓÔÕÖòóôõöÙÚÛÜùúûüÇçÑñ]/,optional:true}}}
);
function waitBy(byThis, diffThis = 'undefined', maxWait = 10000){
return new Promise(function(resolve, reject){
if( typeof byThis == 'string' ){
let waitPromise = setInterval(function(){
if( typeof top[byThis] != diffThis ){
clearInterval(waitPromise);
resolve(true);
};
}, 10);
let waitPromiseReject = setTimeout(function(){