Spaces:
Running
Running
Sign-in links open in a new tab inside the HF frame; pages are not cached
Browse files- challenge.html +2 -0
- server.py +3 -0
challenge.html
CHANGED
|
@@ -362,6 +362,8 @@ document.getElementById('f').onsubmit=async e=>{e.preventDefault();const d=Objec
|
|
| 362 |
render();
|
| 363 |
</script><script>/* HF shows this Space inside a frame that cannot navigate the whole page. Sign-in then opens in a new tab. */
|
| 364 |
(function(){var inF;try{inF=window.self!==window.top}catch(e){inF=true}if(!inF)return;
|
|
|
|
|
|
|
| 365 |
document.addEventListener("click",function(e){var a=e.target.closest&&e.target.closest('a[href="/login"],a[href="/logout"]');if(!a)return;
|
| 366 |
e.preventDefault();window.open(location.origin+a.getAttribute("href"),"_blank");
|
| 367 |
var n=document.getElementById("loginNewTab");if(!n){n=document.createElement("div");n.id="loginNewTab";n.style.cssText="position:fixed;left:50%;top:14px;transform:translateX(-50%);z-index:99;background:#111827;color:#fff;padding:9px 14px;border-radius:10px;font:600 13px system-ui,sans-serif";document.body.appendChild(n)}
|
|
|
|
| 362 |
render();
|
| 363 |
</script><script>/* HF shows this Space inside a frame that cannot navigate the whole page. Sign-in then opens in a new tab. */
|
| 364 |
(function(){var inF;try{inF=window.self!==window.top}catch(e){inF=true}if(!inF)return;
|
| 365 |
+
function fixLinks(){document.querySelectorAll('a[href="/login"],a[href="/logout"]').forEach(function(x){x.setAttribute("target","_blank");x.setAttribute("rel","opener")})}
|
| 366 |
+
fixLinks();new MutationObserver(fixLinks).observe(document.documentElement,{childList:true,subtree:true});
|
| 367 |
document.addEventListener("click",function(e){var a=e.target.closest&&e.target.closest('a[href="/login"],a[href="/logout"]');if(!a)return;
|
| 368 |
e.preventDefault();window.open(location.origin+a.getAttribute("href"),"_blank");
|
| 369 |
var n=document.getElementById("loginNewTab");if(!n){n=document.createElement("div");n.id="loginNewTab";n.style.cssText="position:fixed;left:50%;top:14px;transform:translateX(-50%);z-index:99;background:#111827;color:#fff;padding:9px 14px;border-radius:10px;font:600 13px system-ui,sans-serif";document.body.appendChild(n)}
|
server.py
CHANGED
|
@@ -153,6 +153,7 @@ class H(SimpleHTTPRequestHandler):
|
|
| 153 |
if f not in STATIC:
|
| 154 |
return self._json(404, {"error": "not found"})
|
| 155 |
self.path = "/" + f
|
|
|
|
| 156 |
return super().do_GET()
|
| 157 |
|
| 158 |
def do_POST(self):
|
|
@@ -197,6 +198,8 @@ class H(SimpleHTTPRequestHandler):
|
|
| 197 |
|
| 198 |
def end_headers(self):
|
| 199 |
self.send_header("X-Content-Type-Options", "nosniff")
|
|
|
|
|
|
|
| 200 |
super().end_headers()
|
| 201 |
|
| 202 |
def log_message(self, *a):
|
|
|
|
| 153 |
if f not in STATIC:
|
| 154 |
return self._json(404, {"error": "not found"})
|
| 155 |
self.path = "/" + f
|
| 156 |
+
self._static = True
|
| 157 |
return super().do_GET()
|
| 158 |
|
| 159 |
def do_POST(self):
|
|
|
|
| 198 |
|
| 199 |
def end_headers(self):
|
| 200 |
self.send_header("X-Content-Type-Options", "nosniff")
|
| 201 |
+
if getattr(self, "_static", False): # pages and scripts: always check for a newer copy
|
| 202 |
+
self.send_header("Cache-Control", "no-cache")
|
| 203 |
super().end_headers()
|
| 204 |
|
| 205 |
def log_message(self, *a):
|