From 99520a0b433a7fcab55ad6168862e1e633fc41bc Mon Sep 17 00:00:00 2001 From: Jan Dvorak Date: Fri, 7 Nov 2014 14:45:42 +0100 Subject: [PATCH] first version that needs to be a userscript --- se-chat-iframe-popup.user.js | 73 ++++++++++++++++++++++++++++++++++++ so-post-monitor.user.js | 3 +- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 se-chat-iframe-popup.user.js diff --git a/se-chat-iframe-popup.user.js b/se-chat-iframe-popup.user.js new file mode 100644 index 0000000..7d4f571 --- /dev/null +++ b/se-chat-iframe-popup.user.js @@ -0,0 +1,73 @@ +// ==UserScript== +// @name Stack Exchange hover popup +// @description Shows a popup with a SE question when a link to the question is hovered in the chat +// @require http://cherne.net/brian/resources/jquery.hoverIntent.minified.js +// @include http://*stackexchange.com/* +// @include http://*stackoverflow.com/* +// @include http://*mathoverflow.com/* +// @include http://*serverfault.com/* +// @include http://*superuser.com/* +// @include http://*stackapps.com/* +// @include http://*askubuntu.com/* +// @version 2.2 +// ==/UserScript== +$(function(){ + var currentFrame = null; + $("body").click(function(){ + if(currentFrame) currentFrame.parentNode.removeChild(currentFrame); + currentFrame = null; + }); + $("#chat").hoverIntent({ + selector: ".content a", + out: function(){console.log("out");}, + over: function(event){ + console.log("in %o", this); + if(isSeDomain(this.host)){ + console.log("domain matches"); + var overlay = document.createElement("div"); + overlay.style.background = "rgba(0, 0, 0, 0.5)"; + overlay.style.position = "fixed"; + overlay.style.top = 0; + overlay.style.left = 0; + overlay.style.right = 0; + overlay.style.bottom = 0; + + var frame = document.createElement("iframe"); + + currentFrame = document.createElement("div"); + currentFrame.style.margin = 5; + currentFrame.style.border = "3px solid black"; + currentFrame.style.borderRadius = 5; + currentFrame.style.padding = 10; + currentFrame.appendChild(overlay); + currentFrame.appendChild(frame); + console.log("%o appended", currentFrame); + + GM_xmlhttpRequest({ + url: link.href, + onload: function(response){ + frame.document.documentElement.innerHTML = response.data; + document.body.appendChild(currentFrame); + } + }); + } + } + }); + function isSeDomain(host){ + var hosts = ["stackexchange.com", + "stackoverflow.com", + "mathoverflow.com", + "serverfault.com", + "superuser.com", + "stackapps.com", + "askubuntu.com"] + host = host.match(/\w+\.\w+$/)[0]; + return !!~hosts.indexOf(host); + } +}()); + +/* + var s = document.createElement("script"); + s.src = "http://cherne.net/brian/resources/jquery.hoverIntent.minified.js"; + document.head.appendChild(s); +*/ \ No newline at end of file diff --git a/so-post-monitor.user.js b/so-post-monitor.user.js index b44db6f..005fe38 100644 --- a/so-post-monitor.user.js +++ b/so-post-monitor.user.js @@ -9,7 +9,7 @@ // @include http://*superuser.com/* // @include http://*stackapps.com/* // @include http://*askubuntu.com/* -// @version 2.1 +// @version 2.2 // ==/UserScript== (function () { @@ -175,6 +175,7 @@ }); setInterval(UpdateTask.updateAll, UPDATE_TIMEOUT); + $(document).on("visibilitychange", UpdateTask.updateAll); /// timer functions