Skip to content

Instantly share code, notes, and snippets.

@kcubero27
Last active June 4, 2021 01:12
Show Gist options
  • Save kcubero27/00180ee6c1cddec34de5a7ce34643b23 to your computer and use it in GitHub Desktop.
Save kcubero27/00180ee6c1cddec34de5a7ce34643b23 to your computer and use it in GitHub Desktop.

Hack your friends with JavaScript

Random orientations

Array.prototype.slice.call(  
  document.querySelectorAll(
    'div,p,span,img,a,body')).map(function(tag){
    tag.style['transform'] = 'rotate(' + (
    Math.floor(Math.random() * 3) - 1) + 'deg)';
});

Change colors

var allDivs = document.querySelectorAll('div');

for(var i = 0; i < allDivs.length; i++){  
  allDivs[i].style['background-color'] = 'black';
  allDivs[i].style['color'] = 'green';
  allDivs[i].style['font-family'] = 'Monospace';
}

Cat pictures

Array.prototype.slice.call(  
  document.querySelectorAll('img')).map(function(tag){
    tag.src = 'http://bit.ly/2okYTfn';
});

Rotate content after 5 seconds

setTimeout(function(){  
 document.onmousemove = document.onkeypress = 
 function(){
     document.body.style['transition'] = 'transform 3s';
     document.body.style['transform'] = 'rotate(180deg)';
 }
}, 5000);

Opacity from a due date

https://github.com/kleampa/not-paid/blob/master/not-paid.js

Change stackoverflow comments

$('.post-text').text('Not today')
$('.comment-copy').text('Not today')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment