Spaces:
Running
Running
Update index.html
Browse files- index.html +19 -23
index.html
CHANGED
|
@@ -163,21 +163,8 @@
|
|
| 163 |
["dragleave","drop"].forEach(function(e){drop.addEventListener(e,function(v){v.preventDefault();drop.classList.remove("drag");});});
|
| 164 |
drop.addEventListener("drop",function(v){var f=v.dataTransfer.files&&v.dataTransfer.files[0];if(f){file.files=v.dataTransfer.files;show(f);}});
|
| 165 |
window.addEventListener("paste",function(e){var it=(e.clipboardData||{}).items||[];for(var i=0;i<it.length;i++){if(it[i].type.indexOf("image")===0){var f=it[i].getAsFile();file.files=null;show(f);var dt=new DataTransfer();dt.items.add(f);file.files=dt.files;}}});
|
| 166 |
-
//
|
| 167 |
-
|
| 168 |
-
function goUnfake(url){
|
| 169 |
-
try {
|
| 170 |
-
if (window.top === window.self) { window.location.href = url; return; }
|
| 171 |
-
window.top.location.href = url; // throws SecurityError in HF's iframe
|
| 172 |
-
} catch(e) { window.open(url, "_blank"); } // sandbox blocks same-tab -> new tab
|
| 173 |
-
}
|
| 174 |
-
document.addEventListener("click", function(e){
|
| 175 |
-
var a = e.target && e.target.closest ? e.target.closest("a[href^='http']") : null;
|
| 176 |
-
if (a && !e.defaultPrevented && !(e.metaKey || e.ctrlKey || e.shiftKey)) {
|
| 177 |
-
e.preventDefault();
|
| 178 |
-
goUnfake(a.href);
|
| 179 |
-
}
|
| 180 |
-
});
|
| 181 |
// Hand off the uploaded photo to UnFake's crop step via URL fragment
|
| 182 |
var form=document.getElementById("searchForm");
|
| 183 |
function compress(file, cb){
|
|
@@ -192,17 +179,26 @@
|
|
| 192 |
im.onerror=function(){ cb(null); };
|
| 193 |
im.src=URL.createObjectURL(file);
|
| 194 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
form.addEventListener("submit",function(e){
|
| 196 |
e.preventDefault();
|
| 197 |
var f=file.files&&file.files[0];
|
| 198 |
-
if(f){
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
});
|
| 207 |
document.getElementById("yr").textContent=new Date().getFullYear();
|
| 208 |
</script>
|
|
|
|
| 163 |
["dragleave","drop"].forEach(function(e){drop.addEventListener(e,function(v){v.preventDefault();drop.classList.remove("drag");});});
|
| 164 |
drop.addEventListener("drop",function(v){var f=v.dataTransfer.files&&v.dataTransfer.files[0];if(f){file.files=v.dataTransfer.files;show(f);}});
|
| 165 |
window.addEventListener("paste",function(e){var it=(e.clipboardData||{}).items||[];for(var i=0;i<it.length;i++){if(it[i].type.indexOf("image")===0){var f=it[i].getAsFile();file.files=null;show(f);var dt=new DataTransfer();dt.items.add(f);file.files=dt.files;}}});
|
| 166 |
+
// Are we embedded in Hugging Face's sandboxed iframe? (it blocks same-tab nav)
|
| 167 |
+
var inFrame = (function(){ try { return window.top !== window.self; } catch(e){ return true; } })();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
// Hand off the uploaded photo to UnFake's crop step via URL fragment
|
| 169 |
var form=document.getElementById("searchForm");
|
| 170 |
function compress(file, cb){
|
|
|
|
| 179 |
im.onerror=function(){ cb(null); };
|
| 180 |
im.src=URL.createObjectURL(file);
|
| 181 |
}
|
| 182 |
+
function openUnfake(url){
|
| 183 |
+
if (inFrame) { window.open(url, "_blank"); } // HF iframe: only new tab works
|
| 184 |
+
else { window.location.href = url; } // direct subdomain: same tab
|
| 185 |
+
}
|
| 186 |
form.addEventListener("submit",function(e){
|
| 187 |
e.preventDefault();
|
| 188 |
var f=file.files&&file.files[0];
|
| 189 |
+
if(!f){ openUnfake("https://unfake.pro"); return; }
|
| 190 |
+
// Open a blank tab NOW, inside the tap gesture, so mobile pop-up blockers
|
| 191 |
+
// allow it; navigate it to UnFake once compression finishes.
|
| 192 |
+
var tab = inFrame ? window.open("about:blank", "_blank") : null;
|
| 193 |
+
compress(f,function(d){
|
| 194 |
+
var url = d ? "https://unfake.pro/#photo="+encodeURIComponent(d) : "https://unfake.pro";
|
| 195 |
+
if (inFrame) {
|
| 196 |
+
if (tab && !tab.closed) { try { tab.location.href = url; return; } catch(err){} }
|
| 197 |
+
window.open(url, "_blank");
|
| 198 |
+
} else {
|
| 199 |
+
window.location.href = url;
|
| 200 |
+
}
|
| 201 |
+
});
|
| 202 |
});
|
| 203 |
document.getElementById("yr").textContent=new Date().getFullYear();
|
| 204 |
</script>
|