PageSourceSearch

https://www.tenman.or.jp/js/global.js?v=1787974273

js tenman.or.jp collected 2026-10-06 21:35:50 UTC 5,839 bytes, 138 lines download raw bytes

1(function () {
2    function init() {
3        // --- 1. Chrome 2回タップ問題対策 & スムーススクロール ---
4        document.addEventListener('touchstart', function () {}, {passive: true});
5        const scrollLinks = document.querySelectorAll('a[href^="#"]');
6        scrollLinks.forEach(link => {
7            link.addEventListener('click', function(e) {
8                const href = this.getAttribute('href');
9                const target = href === "#" || href === "" ? document.documentElement : document.querySelector(href);
10                if (target) {
11                    e.preventDefault();
12                    const offset = window.innerWidth <= 765 ? 60 : 0;
13                    const targetPosition = target.getBoundingClientRect().top + window.pageYOffset - offset;
14                    window.scrollTo({ top: targetPosition, behavior: 'smooth' });
15                }
16            });
17        });
18        // --- 2. ヘッダー ---
19        const header = document.querySelector('.g-headericon');
20        const bgTrigger = 500;    // 背景を出すpx
21        const hideTrigger = 200; // 出し入れ開始px
22        let lastScroll = 0;
23        window.addEventListener('scroll', () => {
24        const current = window.scrollY;
25        /* 背景のON/OFF */
26        if (current > bgTrigger) {
27            header.classList.add('is-scrolled');
28        } else {
29            header.classList.remove('is-scrolled');
30        }
31        /* 最上部では必ず表示 */
32        if (current < hideTrigger) {
33            header.classList.remove('is-hide');
34            lastScroll = current;
35            return;
36        }
37        /* スクロール方向判定 */
38        if (current > lastScroll) {
39            // 下スクロール
40            header.classList.add('is-hide');
41        } else {
42            // 上スクロール
43            header.classList.remove('is-hide');
44        }
45        lastScroll = current;
46        });
47
48        // --- 3. ハンバーガーメニュー ---
49        const menuBtn = document.querySelector(".g-menubutton");
50        const nav = document.getElementById("g-nav");
51
52        if (menuBtn && nav) {
53            menuBtn.addEventListener("click", function (e) {
54                e.stopPropagation();
55                this.classList.toggle("active");
56                nav.classList.toggle("panelactive");
57            });
58
59            nav.addEventListener("click", function () {
60                menuBtn.classList.remove("active");
61                this.classList.remove("panelactive");
62            });
63
64            // nav 内のリンクでも閉じる
65            nav.querySelectorAll("a").forEach(link => {
66                link.addEventListener("click", function () {
67                    menuBtn.classList.remove("active");
68                    nav.classList.remove("panelactive");
69                });
70            });
71        }
72
73        // --- 4. YouTube サムネイル軽量化 ---
74        document.querySelectorAll(".youtube").forEach((youtube) => {
75            const iframe = youtube.querySelector("iframe");
76            if (!iframe) return;
77
78            const url = iframe.getAttribute("data-src") || iframe.src;
79            const match = url.match(/[\/?=]([a-zA-Z0-9_-]{11})[&\?]?/);
80            if (!match) return;
81
82            const id = match[1];
83            youtube.innerHTML = `<img src="https://img.youtube.com/vi/${id}/maxresdefault.jpg" alt="サムネイル" style="cursor:pointer;">`;
84
85            youtube.addEventListener("click", function () {
86                const arrow = youtube.parentElement.querySelector(".arrow");
87                if (arrow) {
88                    arrow.style.transition = "opacity 0.2s ease";
89                    arrow.style.opacity = "0";
90                    setTimeout(() => arrow.remove(), 200);
91                }
92                youtube.innerHTML = `<iframe src="https://www.youtube.com/embed/${id}?autoplay=1&mute=1&controls=1&fs=0&rel=0&loop=1&playlist=${id}&modestbranding=1"
93                    frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>`;
94            });
95        });
96
97        // --- 5. スクロールイベント ---
98        const pageTop = document.getElementById('page-top');
99        const fadeElements = document.querySelectorAll('.fadeTrigger');
100
101        const checkFade = () => {
102            const scroll = window.scrollY;
103            const windowHeight = window.innerHeight;
104            if (pageTop) {
105                if (scroll >= 800) pageTop.classList.add('fadein');
106                else pageTop.classList.remove('fadein');
107            }
108            fadeElements.forEach(element => {
109                const elemPos = element.getBoundingClientRect().top + scroll;
110                if (scroll > elemPos - windowHeight + 0) {
111                    element.classList.add('is-active');
112                }
113            });
114        };
115
116        window.addEventListener('scroll', checkFade, {passive: true});
117
118        // --- 6. ローディング連動ロジック ---
119        const loadingScreen = document.getElementById("loading-screen");
120
121        if (!loadingScreen || loadingScreen.style.display === "none") {
122            // ローディング不要な場合(loading.js側で既にスキップ済み)
123            checkFade();
124        } else {
125            // ローディングが必要な場合(初回または更新): 実際の非表示タイミングはloading.js側が管理
126            loadingScreen.addEventListener("loading-hidden", function () {
127                // 背景が見え始める頃にフェードを開始
128                setTimeout(checkFade, 300);
129            }, { once: true });
130        }
131    }
132
133    if (document.readyState === "loading") {
134        document.addEventListener("DOMContentLoaded", init);
135    } else {
136        init();
137    }
138})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.