| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- (function () {
- "use strict";
- if (window.__ffkjPaginationJumpReady) return;
- window.__ffkjPaginationJumpReady = true;
- var paginationSelector = [
- ".news-pagination",
- ".inner-pagination",
- ".vc-pagination",
- ".edu-pagination",
- ".gjjx-pagination",
- ".laypage_main",
- "#layPage[data-total-items]"
- ].join(",");
- function toPositiveInt(value) {
- var number = parseInt(String(value || "").replace(/\D/g, ""), 10);
- return number > 0 ? number : 0;
- }
- function parsePageFromUrl(url) {
- try {
- return toPositiveInt(new URL(url, window.location.href).searchParams.get("page"));
- } catch (error) {
- return 0;
- }
- }
- function findActive(root) {
- return root.querySelector(".active, .is-active, .laypage_curr, .current, [aria-current='page']");
- }
- function findTotal(root) {
- var explicit = toPositiveInt(root.getAttribute("data-page-count"));
- if (explicit) return explicit;
- var totalItems = toPositiveInt(root.getAttribute("data-total-items"));
- var pageSize = toPositiveInt(root.getAttribute("data-page-size"));
- if (totalItems && pageSize) return Math.ceil(totalItems / pageSize);
- var summary = root.querySelector("[data-page-count], .page-summary, .laypage_total");
- if (summary) {
- explicit = toPositiveInt(summary.getAttribute("data-page-count"));
- if (explicit) return explicit;
- }
- var summaryMatch = (root.textContent || "").match(/共\s*(\d+)\s*页/);
- if (summaryMatch) return toPositiveInt(summaryMatch[1]);
- var total = 0;
- Array.prototype.forEach.call(root.querySelectorAll("[data-page], a[href]"), function (item) {
- total = Math.max(total, toPositiveInt(item.getAttribute("data-page")), parsePageFromUrl(item.getAttribute("href")));
- });
- Array.prototype.forEach.call(root.querySelectorAll("a[href]"), function (item) {
- if (/^(上一页|下一页|首页|尾页|«|»|<|>)$/.test((item.textContent || "").trim())) return;
- total = Math.max(total, toPositiveInt(item.textContent));
- });
- var active = findActive(root);
- if (active) {
- total = Math.max(total, toPositiveInt(active.getAttribute("data-page")) || toPositiveInt(active.textContent));
- }
- return total;
- }
- function findSummary(root) {
- return root.querySelector(".ffkj-page-summary, .page-summary, .edu-page-summary, .vc-page-summary");
- }
- function ensureSummary(root, total) {
- var summary = findSummary(root);
- if (summary) {
- if (!/共\s*\d+\s*页/.test(summary.textContent || "")) {
- summary.textContent = "共 " + total + " 页";
- }
- return;
- }
- if (/共\s*\d+\s*页/.test(root.textContent || "")) return;
- summary = document.createElement("span");
- summary.className = "ffkj-page-summary";
- summary.textContent = "共 " + total + " 页";
- root.insertBefore(summary, root.firstChild || null);
- }
- function normalizeSearchPage() {
- if (window.location.pathname.replace(/\/+$/, "") !== "/search") return;
- document.body.classList.add("ffkj-search-page");
- var sidebarSelectors = [
- ".department-column-nav",
- ".edu-sidebar",
- ".inner-side-panel",
- ".content-row > .content-left",
- ".news-sidebar",
- ".inner-sidebar",
- ".quick-nav",
- ".quick-navigation",
- ".side-nav"
- ].join(",");
- Array.prototype.forEach.call(document.querySelectorAll(sidebarSelectors), function (sidebar) {
- var layout = sidebar.parentElement;
- if (!layout) return;
- layout.classList.add("ffkj-search-single");
- sidebar.parentNode.removeChild(sidebar);
- });
- }
- function findCurrent(root, total) {
- var explicit = toPositiveInt(root.getAttribute("data-current-page"));
- if (explicit) return explicit;
- var active = findActive(root);
- if (active) {
- explicit = toPositiveInt(active.getAttribute("data-page")) || toPositiveInt(active.textContent);
- if (explicit) return explicit;
- }
- explicit = parsePageFromUrl(window.location.href);
- return explicit || 1;
- }
- function getAccent(root) {
- var themeVars = ["--red", "--brand", "--primary", "--theme-color", "--main-color", "--color-primary"];
- var candidates = [];
- var themeNode = root;
- while (themeNode) {
- var themeStyle = window.getComputedStyle(themeNode);
- for (var k = 0; k < themeVars.length; k += 1) {
- var themeValue = themeStyle.getPropertyValue(themeVars[k]).trim();
- addColorCandidate(candidates, themeValue, 120);
- }
- themeNode = themeNode.parentElement;
- }
- var themeSelectors = [".header-nav", ".main-nav", ".navbar", ".nav", "nav", ".header-wrap", ".header"];
- Array.prototype.forEach.call(document.querySelectorAll(themeSelectors.join(",")), function (item) {
- var navStyle = window.getComputedStyle(item);
- addColorCandidate(candidates, navStyle.backgroundColor, 80);
- addColorCandidate(candidates, navStyle.borderBottomColor, 60);
- addColorCandidate(candidates, navStyle.borderTopColor, 60);
- });
- var themeLinks = document.querySelectorAll(".header a, header a, .header-nav a, .main-nav a, .navbar a, nav a");
- Array.prototype.forEach.call(themeLinks, function (item) {
- var linkStyle = window.getComputedStyle(item);
- addColorCandidate(candidates, linkStyle.backgroundColor, 90);
- addColorCandidate(candidates, linkStyle.borderBottomColor, 50);
- addColorCandidate(candidates, linkStyle.color, 20);
- });
- var active = findActive(root);
- if (active) {
- var activeStyle = window.getComputedStyle(active);
- addColorCandidate(candidates, activeStyle.backgroundColor, 50);
- addColorCandidate(candidates, activeStyle.borderColor, 40);
- addColorCandidate(candidates, activeStyle.color, 30);
- }
- var firstLink = root.querySelector("a");
- if (firstLink) {
- var linkStyle = window.getComputedStyle(firstLink);
- addColorCandidate(candidates, linkStyle.borderColor, 20);
- addColorCandidate(candidates, linkStyle.backgroundColor, 20);
- addColorCandidate(candidates, linkStyle.color, 10);
- }
- var rootStyle = window.getComputedStyle(root);
- addColorCandidate(candidates, rootStyle.borderColor, 10);
- addColorCandidate(candidates, rootStyle.color, 5);
- candidates.sort(function (a, b) {
- return b.weight - a.weight;
- });
- if (candidates.length) return candidates[0].value;
- return "#0048AE";
- }
- function isUsableColor(value) {
- if (!value || value === "transparent" || value === "currentcolor") return false;
- if (/^rgba?\(/i.test(value)) {
- var parts = value.match(/[\d.]+/g) || [];
- if (parts.length > 3 && parseFloat(parts[3]) === 0) return false;
- if (parts.length >= 3) {
- var r = parseFloat(parts[0]);
- var g = parseFloat(parts[1]);
- var b = parseFloat(parts[2]);
- if ((r === 0 && g === 0 && b === 0) || (r === 255 && g === 255 && b === 255)) return false;
- }
- }
- return !window.CSS || !window.CSS.supports || window.CSS.supports("color", value);
- }
- function addColorCandidate(candidates, value, weight) {
- if (!isUsableColor(value)) return;
- var score = weight;
- if (/^rgba?\(/i.test(value)) {
- var parts = value.match(/[\d.]+/g) || [];
- if (parts.length >= 3) {
- var max = Math.max(parseFloat(parts[0]), parseFloat(parts[1]), parseFloat(parts[2]));
- var min = Math.min(parseFloat(parts[0]), parseFloat(parts[1]), parseFloat(parts[2]));
- var spread = max - min;
- var brightness = (max + min) / 2;
- if (spread > 80) score += 60;
- else if (spread > 25) score += 30;
- else if (spread > 8) score += 5;
- if (brightness > 245 && spread < 40) score -= 80;
- else if (brightness > 230 && spread < 80) score -= 30;
- }
- }
- candidates.push({ value: value, weight: score });
- }
- function getPageParam(root) {
- var explicit = root.getAttribute("data-page-param");
- if (explicit) return explicit;
- var container = root.closest && root.closest("#layPage[data-page-param]");
- if (container) return container.getAttribute("data-page-param");
- var scripts = document.getElementsByTagName("script");
- for (var i = 0; i < scripts.length; i += 1) {
- var source = scripts[i].textContent || "";
- if (!/laypage/i.test(source)) continue;
- var match = source.match(/\?(pageNo|currentPageNo|page|n)=/i);
- if (match) return match[1];
- }
- return "page";
- }
- function buildPageUrl(root, page) {
- var pageParam = getPageParam(root);
- var candidate = null;
- Array.prototype.forEach.call(root.querySelectorAll("a[href]"), function (link) {
- var href = link.getAttribute("href") || "";
- if (!candidate && href && !/^javascript:/i.test(href)) {
- try {
- if (new URL(href, window.location.href).searchParams.has(pageParam)) candidate = link.href;
- } catch (error) {}
- }
- });
- var url = new URL(candidate || window.location.href, window.location.href);
- url.pathname = url.pathname.replace(/;jsessionid=[^/?#]*/i, "");
- url.searchParams.set(pageParam, String(page));
- return url.href;
- }
- function enhance(root) {
- if (!root) return;
- if (root.querySelector(".ffkj-page-jump")) return;
- var legacyContainer = root.matches(".laypage_main") && root.closest("#layPage");
- if (legacyContainer && legacyContainer.querySelector(".ffkj-page-jump")) return;
- var total = findTotal(root);
- var current = findCurrent(root, total);
- var accent = getAccent(root);
- root.classList.add("pagination-jump-processed");
- root.style.setProperty("--ffkj-page-jump-accent", accent);
- if (total <= 1) return;
- ensureSummary(root, total);
- var form = document.createElement("form");
- form.className = "ffkj-page-jump";
- form.setAttribute("role", "search");
- form.setAttribute("aria-label", "页码跳转");
- form.setAttribute("novalidate", "");
- form.style.setProperty("--ffkj-page-jump-accent", accent);
- var label = document.createElement("label");
- label.textContent = "跳至";
- var input = document.createElement("input");
- input.type = "number";
- input.inputMode = "numeric";
- input.min = "1";
- input.max = String(total);
- input.value = String(current);
- input.setAttribute("aria-label", "输入页码,共 " + total + " 页");
- var suffix = document.createElement("span");
- suffix.textContent = "页";
- var submit = document.createElement("button");
- submit.type = "submit";
- submit.textContent = "确定";
- form.appendChild(label);
- form.appendChild(input);
- form.appendChild(suffix);
- form.appendChild(submit);
- form.addEventListener("submit", function (event) {
- event.preventDefault();
- var page = toPositiveInt(input.value);
- if (!page || page > total) {
- input.setAttribute("aria-invalid", "true");
- input.focus();
- return;
- }
- input.removeAttribute("aria-invalid");
- window.location.assign(buildPageUrl(root, page));
- });
- root.appendChild(form);
- root.setAttribute("data-ffkj-page-jump", "done");
- }
- function scan() {
- Array.prototype.forEach.call(document.querySelectorAll(paginationSelector), enhance);
- }
- function ready(fn) {
- if (document.readyState === "loading") {
- document.addEventListener("DOMContentLoaded", fn);
- } else {
- fn();
- }
- }
- function loadStyle() {
- if (document.querySelector("link[data-ffkj-page-jump-style]")) return;
- var link = document.createElement("link");
- link.rel = "stylesheet";
- link.href = "/main/ffkj-portal/pagination-jump.css?v=20261128-search-pages-r1";
- link.setAttribute("data-ffkj-page-jump-style", "true");
- document.head.appendChild(link);
- }
- loadStyle();
- ready(function () {
- normalizeSearchPage();
- scan();
- if (!window.MutationObserver) return;
- var timer = 0;
- new MutationObserver(function () {
- window.clearTimeout(timer);
- timer = window.setTimeout(scan, 30);
- }).observe(document.body, { childList: true, subtree: true });
- });
- })();
|