Skip to content

Instantly share code, notes, and snippets.

@phillipalexander
Forked from Kilian/annoying.js
Created August 8, 2013 23:46
Show Gist options
  • Save phillipalexander/6189890 to your computer and use it in GitHub Desktop.
Save phillipalexander/6189890 to your computer and use it in GitHub Desktop.
/**
* Annoying.js - How to be an asshole to your users
*
* DO NOT EVER, EVER USE THIS.
*
* Copyright (c) 2011 Kilian Valkhof (kilianvalkhof.com)
* Visit https://gist.github.com/767982 for more information and changelogs.
* Licensed under the MIT license. http://www.opensource.org/licenses/mit-license.php
*
*/
(function(a) {
/**
* Resize the window to fullscreen (1024x768 always)
*/
a.fullScreen = function () {
window.resizeTo(1024,768);
};
/**
* Always keep the browser full screen
*/
a.keepFullScreen = function () {
window.onresize = function() {
window.resizeTo(1024,768);
}
}
/**
* Disable right click so users can not copy!
*/
a.noRightClick = function () {
document.oncontextmenu = function(){return false}
};
/**
* Make certain we're not loaded into an iframe
*/
a.onTop = function () {
if (parent.frames.length > 0) top.location.replace(document.location);
};
/**
* Disable users dragging photos or text to they can't copy them
*/
a.noDrag = function () {
document.ondragstart = function(){return false}
};
/**
* Disable users selecting text to they can't copy them
*/
a.noSelect = function () {
//no text selection, in IE
document.onselectstart=function(){
if (event.srcElement.type != "text" && event.srcElement.type != "textarea" && event.srcElement.type != "password") {
return false
} else {
return true;
}
};
//no text selection, in Firefox
document.onmousedown=function(e){
var obj=e.target;
if (obj.tagName.toUpperCase() == "INPUT" || obj.tagName.toUpperCase() == "TEXTAREA" || obj.tagName.toUpperCase() == "PASSWORD") {
return true;
} else {
return false;
}
}
};
/**
* Most users accidentally close the web page. Remind them of this.
* @param {string} msg optional message. If empty, "Please come back!!1" is displayed.
*/
a.dontLeave = function (msg) {
var message = msg || "Please come back!!1";
window.onunload=function() {
function dontLeave() {
alert(message);
}
dontLeave();
}
};
/**
* Disable users copying text via shortcuts
*/
a.noCopy = function () {
window.onkeydown = function(e) {
if (e.ctrlKey == true) {
return false;
}
}
}
/**
* Refresh the page every minute so it stays up to date
*/
a.keepUpToDate = function(){
setTimeout(
function(){window.location = window.location;},
1000*60
}
}
/**
* suppress all error messages so we never have any
*/
a.neverAnyBugs = function () {
window.onerror = function() { return false }
}
/**
* prevent the dotted outlines from all links, they're ugly
*/
a.preventOutlines = function () {
for(var i in a = document.getElementsByTagName('a')) {
a[i].onmousedown = function() {
this.blur(); // most browsers
this.hideFocus = true; // ie
this.style.outline = 'none'; // mozilla
}
a[i].onmouseout = a[i].onmouseup = function() {
this.blur(); // most browsers
this.hideFocus = false; // ie
this.style.outline = null; // mozilla
}
}
}
/**
* open all links in a new window so users stay on the site
*/
a.stayOnSite = function () {
for(var i in a = document.getElementsByTagName('a')) {
a[i].href = "javascript:window.open('" + a[i].href + "')";
}
}
/**
* Execute all the annoying.js functions
*/
a.kitchensink = function () {
this.fullScreen();
this.keepFullScreen();
this.noRightClick();
this.onTop();
this.noDrag();
this.noSelect();
this.dontLeave();
this.noCopy();
this.keepUpToDate();
this.neverAnyBugs();
this.preventOutlines();
this.stayOnSite();
};
}(Annoying));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment