SEO: a domain property (sc-domain:) covers every subdomain, so the shop, Gitea and forum were counted as the website. What ranks, the morning check, the Monday report, keywords, change candidates and the audit's traffic now read only the website's own host (with or without www). The report keeps pages worth a proposal apart from "Waiting for your yes", explains only moves past the thresholds, and says "places up/down". Also: - Feed summaries drop the posts' scripts and styles. - Spend you log can't be negative. - Test and check buttons can't be clicked twice while they run. - Previews show the site's web fonts and icon sprites. - Backups are read without leaving -wal/-shm files; deleting one removes them, and leftovers are swept at start. - The Overview's setup flags a CRM that Hermes can't reach. - Import now says what came in; adding a prospect that exists says so; prospects can be deleted. - Signal tags and brief addresses keep accented letters (Ü → u). - Page errors start with a capital; clearer messages for bad uploads, CRM retry and cancel, keywords, and the finished audit. - The module you're in stays unfolded in the sidebar. - A picked keyword can be unpicked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
181 lines
6.9 KiB
JavaScript
181 lines
6.9 KiB
JavaScript
// Small behaviours for Supermarket's pages. Loaded as a file because the
|
|
// Content-Security-Policy allows no inline scripts.
|
|
(function () {
|
|
"use strict";
|
|
|
|
// Show the fields for the chosen AI provider ([data-show-for]).
|
|
function syncProvider() {
|
|
var chosen = document.querySelector('input[data-toggle="provider"]:checked');
|
|
if (!chosen) return;
|
|
document.querySelectorAll("[data-show-for]").forEach(function (el) {
|
|
el.hidden = el.getAttribute("data-show-for") !== chosen.value;
|
|
});
|
|
}
|
|
|
|
document.addEventListener("change", function (e) {
|
|
if (e.target.matches('input[data-toggle="provider"]')) syncProvider();
|
|
});
|
|
|
|
// Press / to search (unless typing somewhere already).
|
|
document.addEventListener("keydown", function (e) {
|
|
if (e.key !== "/" || e.ctrlKey || e.metaKey || e.altKey) return;
|
|
var t = e.target;
|
|
if (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)) return;
|
|
var box = document.getElementById("search-box");
|
|
if (box) {
|
|
e.preventDefault();
|
|
box.focus();
|
|
box.select();
|
|
}
|
|
});
|
|
|
|
document.addEventListener("click", function (e) {
|
|
// The menu on narrow screens.
|
|
if (e.target.closest("[data-nav-toggle]")) {
|
|
document.body.classList.toggle("nav-open");
|
|
return;
|
|
}
|
|
if (e.target.closest("[data-nav-close]")) {
|
|
document.body.classList.remove("nav-open");
|
|
return;
|
|
}
|
|
// Copy a <pre>'s text: <button data-copy="id-of-pre">
|
|
var copy = e.target.closest("[data-copy]");
|
|
if (copy) {
|
|
var src = document.getElementById(copy.getAttribute("data-copy"));
|
|
if (src && navigator.clipboard) {
|
|
// A field's current value (with edits), else an element's text.
|
|
var value = "value" in src ? src.value : src.textContent;
|
|
navigator.clipboard.writeText(value).then(function () {
|
|
var label = copy.textContent;
|
|
copy.textContent = "Copied";
|
|
setTimeout(function () { copy.textContent = label; }, 1500);
|
|
});
|
|
}
|
|
return;
|
|
}
|
|
// Fill a field from a list: <button data-fill="field-name" data-value="v">
|
|
var fill = e.target.closest("[data-fill]");
|
|
if (fill) {
|
|
var field = document.querySelector('[name="' + fill.getAttribute("data-fill") + '"]');
|
|
if (field) {
|
|
field.value = fill.getAttribute("data-value");
|
|
field.focus();
|
|
}
|
|
}
|
|
});
|
|
|
|
// A select with data-autosubmit sends its form when it changes (inline
|
|
// handlers aren't allowed by the page's Content-Security-Policy).
|
|
document.addEventListener("change", function (e) {
|
|
var el = e.target;
|
|
if (el.hasAttribute && el.hasAttribute("data-autosubmit") && el.form) {
|
|
if (el.form.requestSubmit) el.form.requestSubmit(); else el.form.submit();
|
|
}
|
|
});
|
|
|
|
// Ask before submitting a form with data-confirm. A form with data-busy
|
|
// shows that text on the button that submitted it, and can't be sent twice,
|
|
// while a slow request (fetching, writing, publishing) runs. With
|
|
// data-busy-on, only that button's value counts as slow.
|
|
document.addEventListener("submit", function (e) {
|
|
var form = e.target;
|
|
// The button that submitted it can ask instead (one form, several actions).
|
|
var msg = (e.submitter && e.submitter.getAttribute("data-confirm")) || form.getAttribute("data-confirm");
|
|
if (msg && !window.confirm(msg)) {
|
|
e.preventDefault();
|
|
return;
|
|
}
|
|
var busy = form.getAttribute("data-busy");
|
|
if (!busy) return;
|
|
var btn = e.submitter;
|
|
var only = form.getAttribute("data-busy-on");
|
|
if (only && (!btn || btn.value !== only)) return;
|
|
if (form.dataset.sending) {
|
|
e.preventDefault();
|
|
return;
|
|
}
|
|
form.dataset.sending = "1";
|
|
if (btn) {
|
|
// A disabled button isn't submitted, so carry its value in a hidden field.
|
|
if (btn.name) {
|
|
var keep = document.createElement("input");
|
|
keep.type = "hidden";
|
|
keep.name = btn.name;
|
|
keep.value = btn.value;
|
|
form.appendChild(keep);
|
|
}
|
|
btn.textContent = busy;
|
|
setTimeout(function () { btn.disabled = true; }, 0);
|
|
}
|
|
});
|
|
|
|
// Live length of a post: <textarea data-count="x|linkedin" data-limit
|
|
// data-reserve> followed by its <p class="count">. X counts most characters
|
|
// outside Latin, punctuation and symbols as 2, like the server does.
|
|
function weighted(s) {
|
|
var n = 0;
|
|
for (var ch of s) {
|
|
var c = ch.codePointAt(0);
|
|
if (c <= 0x10ff || (c >= 0x2000 && c <= 0x200d) || (c >= 0x2010 && c <= 0x201f) || (c >= 0x2032 && c <= 0x2037)) n += 1;
|
|
else n += 2;
|
|
}
|
|
return n;
|
|
}
|
|
function count(area) {
|
|
var out = document.getElementById(area.getAttribute("aria-describedby"));
|
|
if (!out) return;
|
|
var limit = parseInt(area.getAttribute("data-limit"), 10);
|
|
var reserve = parseInt(area.getAttribute("data-reserve") || "0", 10);
|
|
var text = area.value.trim();
|
|
var n = area.getAttribute("data-count") === "x" ? weighted(text) + reserve : Array.from(text).length;
|
|
out.textContent = n + " / " + limit + (reserve ? " including the link" : "");
|
|
out.classList.toggle("over", n > limit);
|
|
}
|
|
document.addEventListener("input", function (e) {
|
|
if (e.target.matches("textarea[data-count]")) count(e.target);
|
|
});
|
|
|
|
document.addEventListener("DOMContentLoaded", syncProvider);
|
|
// Sidebar: each module's pages fold under a toggle. The module you're in
|
|
// is always open; the others stay as you last left them (closed at
|
|
// first). A folded module shows the sum of its pages' counts.
|
|
(function () {
|
|
var KEY = "supermarket.nav";
|
|
var state = {};
|
|
try { state = JSON.parse(localStorage.getItem(KEY)) || {}; } catch (e) {}
|
|
function set(sub, btn, open) {
|
|
sub.hidden = !open;
|
|
btn.setAttribute("aria-expanded", open ? "true" : "false");
|
|
btn.closest(".nav-row").classList.toggle("collapsed", !open);
|
|
}
|
|
document.querySelectorAll(".subnav[data-subnav]").forEach(function (sub) {
|
|
var btn = document.querySelector('.nav-toggle[aria-controls="' + sub.id + '"]');
|
|
if (!btn) return;
|
|
btn.hidden = false;
|
|
var sum = 0;
|
|
sub.querySelectorAll(".count-badge").forEach(function (b) { sum += parseInt(b.textContent, 10) || 0; });
|
|
var total = btn.closest(".nav-row").querySelector(".nav-sum");
|
|
if (total && sum > 0) {
|
|
total.textContent = sum;
|
|
total.title = sum + " waiting";
|
|
total.hidden = false;
|
|
}
|
|
if (sub.hasAttribute("data-current")) {
|
|
// The module you're in stays open: its chevron shows it, but doesn't fold it.
|
|
set(sub, btn, true);
|
|
btn.disabled = true;
|
|
btn.title = "Open while you're in it";
|
|
return;
|
|
}
|
|
set(sub, btn, state[sub.dataset.subnav] === true);
|
|
btn.addEventListener("click", function () {
|
|
var open = sub.hidden;
|
|
set(sub, btn, open);
|
|
state[sub.dataset.subnav] = open;
|
|
try { localStorage.setItem(KEY, JSON.stringify(state)); } catch (e) {}
|
|
});
|
|
});
|
|
})();
|
|
})();
|