Framed pages: the new tab's sign-in link carries the page's sponsor (?ref, /join/<tok>, /wall/<tok>)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-03 19:39:18 -05:00
parent 563ece9896
commit 3f758cdd38
20 changed files with 26 additions and 20 deletions
+7 -1
View File
@@ -269,9 +269,15 @@ window.IAP = (function () {
(function () {
var framed = false; try { framed = window.top !== window.self; } catch (e) { framed = true; }
if (!framed) return;
// the sponsor this page was opened for (?ref=, /join/<tok>, /wall/<tok>); its cookie was refused in the frame, so the
// new tab gets it in the link and the viral-link rule sets it there
var ref = ''; try { ref = new URLSearchParams(location.search).get('ref') || (location.pathname.match(/^\/(?:join|wall)\/([^/?#]+)/) || [])[1] || ''; } catch (e) {}
ref = String(ref).toLowerCase().replace(/[^a-z0-9_]/g, '').slice(0, 20);
document.addEventListener('click', function (e) {
var a = e.target && e.target.closest && e.target.closest('a[href]'); if (!a) return;
var h = a.getAttribute('href') || ''; if (h.charAt(0) === '#' || /^javascript:/i.test(h)) return;
if (a.host !== location.host || /^\/(my|join|signin|login|from|admin)(\/|$)/.test(a.pathname)) { a.target = '_blank'; a.rel = 'noopener'; }
var sign = a.host === location.host && /^\/(my|join|signin|login|from|admin)(\/|$)/.test(a.pathname);
if (sign && ref && a.pathname === '/my' && !/[?&]ref=/.test(a.search)) a.search = (a.search ? a.search + '&' : '?') + 'ref=' + ref;
if (sign || a.host !== location.host) { a.target = '_blank'; a.rel = 'noopener'; }
}, true);
})();