Skip to content

Instantly share code, notes, and snippets.

@johnko
Last active December 15, 2015 04:29
Show Gist options
  • Save johnko/5201785 to your computer and use it in GitHub Desktop.
Save johnko/5201785 to your computer and use it in GitHub Desktop.
RedditQuickPreview After loading the script, opens a frame or window when you hover over links. Exclusions are in regex. Usage: - Make a bookmark with code, with a prefix of "javascript:". So your bookmark will look like "javascript:(function....." - Click that bookmark whenever you want to load the script.
(
function () {
"use strict";
/*global window, document, self*/
var type = "window", /*frame or window*/
exclude = /(pixel.reddit|irc:\/\/|reddit.com\/domain|\/compose|\/login|\/submit|\/password|\/gold|reddit.com\/user|reddit.com\/r\/[^\/]*\/?$)/i,
a = document.getElementsByTagName("a"),
myrdiv = document.createElement("div"),
myrframe = document.createElement("iframe"),
i = 0;
try { document.getElementById("content").style.margin = "0px"; } catch (e) {}
function resizeframe() {
myrdiv.style.width = (window.innerWidth - 720) + "px";
myrdiv.style.height = "98%";
}
window.onresize = function () {
resizeframe();
};
myrdiv.id = "myrdiv";
myrdiv.oncontextmenu = function () {
myrdiv.style.display = "none";
};
myrdiv.style.zIndex = "999";
myrdiv.style.background = "rgba(255,255,255,0.75)";
myrdiv.style.position = "fixed";
myrdiv.style.top = "0px";
myrdiv.style.left = "600px";
myrdiv.style.paddingLeft = "100px";
myrframe.id = "myrframe";
myrframe.style.border = "1px black dotted";
myrframe.style.zIndex = "999";
myrframe.style.width = "100%";
myrframe.style.height = "100%";
myrframe.style.webkitTransformOrigin = "0 0";
function zoom1() {
myrdiv.className = "zoom1";
myrframe.style.zoom = 1;
myrframe.style.webkitTransform = "scale(1)";
myrframe.style.width = "100%";
myrframe.style.height = "100%";
}
function zoom33() {
myrdiv.className = "zoom33";
myrframe.style.zoom = 1;
myrframe.style.webkitTransform = "scale(0.33)";
myrframe.style.width = "303%";
myrframe.style.height = "303%";
}
function zoom50() {
myrdiv.className = "zoom50";
myrframe.style.zoom = 1;
myrframe.style.webkitTransform = "scale(0.50)";
myrframe.style.width = "200%";
myrframe.style.height = "200%";
}
function zoom75() {
myrdiv.className = "zoom75";
myrframe.style.zoom = 1;
myrframe.style.webkitTransform = "scale(0.75)";
myrframe.style.width = "133%";
myrframe.style.height = "133%";
}
myrdiv.onmousedown = function () {
if (myrdiv.className.indexOf("zoom75") > -1) {
zoom50();
myrdiv.className = "zoom50c";
} else if (myrdiv.className.indexOf("zoom50") > -1) {
zoom33();
myrdiv.className = "zoom33c";
} else if (myrdiv.className.indexOf("zoom33") > -1) {
zoom1();
myrdiv.className = "zoom1c";
} else if (myrdiv.className.indexOf("zoom1") > -1) {
zoom75();
myrdiv.className = "zoom75c";
}
};
myrdiv.onmouseover = function () {
if (
(myrdiv.className !== "zoom33") &&
(myrdiv.className !== "zoom33c") &&
(myrdiv.className !== "zoom50c") &&
(myrdiv.className !== "zoom75c") &&
(myrdiv.className !== "zoom1c")
) {
zoom75();
}
};
myrframe.onmouseout = function () { zoom1(); };
for (i = 0; i < a.length; i += 1) {
if (!exclude.test(a[i])) {
if (a[i].href.replace("#", "") !== window.location.href) {
a[i].onmouseover = function () {
if (type.indexOf("frame") > -1) {
resizeframe();
document.getElementById("myrdiv").style.display = "block";
zoom1();
if (document.getElementById("myrframe").src !== this.href) {
document.getElementById("myrframe").src = this.href;
}
return false;
} else if (type.indexOf("window") > -1) {
window.open(this.href, "myrwindow", false);
}
};
}
}
}
myrdiv.appendChild(myrframe);
document.body.appendChild(myrdiv);
myrdiv.style.display = "none";
}
)();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment