|
@@ -0,0 +1,292 @@
|
|
|
|
|
+(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));
|
|
|
|
|
+ });
|
|
|
|
|
+ return total;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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.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;
|
|
|
|
|
+
|
|
|
|
|
+ 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=20261123-all-list-v7";
|
|
|
|
|
+ link.setAttribute("data-ffkj-page-jump-style", "true");
|
|
|
|
|
+ document.head.appendChild(link);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ loadStyle();
|
|
|
|
|
+ ready(function () {
|
|
|
|
|
+ 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 });
|
|
|
|
|
+ });
|
|
|
|
|
+})();
|