Greasy Fork

Greasy Fork is available in English.

5ch surfer

5chをちょっと見やすくするやつ

目前为 2023-06-15 提交的版本,查看 最新版本

// ==UserScript==
// @name         5ch surfer
// @namespace    http://tampermonkey.net/
// @version      0.1a
// @description  5chをちょっと見やすくするやつ
// @author       おれ
// @match        *://*.5ch.net/test/read.cgi/*/*/*
// @match        *://*.5ch.net/*/subback.html
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const TIMER = 0; // ページを更新する間隔をミリ秒単位で指定。不要なら0を指定してください

    // 自動アンカー
    window.autoanker = function (num) {
        let message = document.getElementsByClassName("formelem maxwidth")[2];
        message.value += `>>${num}`;
        // 自動スクロール
        let targetRect = message.getBoundingClientRect();
        let targetTop = targetRect.top + window.pageYOffset;
        window.scrollTo({
            top: targetTop,
            behavior: 'smooth'
        })
    }

    // クラシック版に飛ばす
    let path = location.pathname;
    if (path.indexOf('read.cgi') > -1) {
        let paths = path.split('/');
        if (paths[3] != 'c') {
            let newpath = `/test/read.cgi/c/${paths[3]}/${paths[4]}/${paths[5]}`;
            location.pathname = newpath;
        }
    }

    // すべてのリンクをクラシック版へ
    let links = document.links;
    for (let i = 0; i < links.length; i++) {
        let thread = links[i].href.split('/');
        let endpoint = thread[2] + '/' + thread[3] + '/' + thread[4];

        let regexp = /.*5ch\.net\/test\/read.cgi/;
        if (regexp.test(endpoint) && thread[5] != 'c') {
            links[i].setAttribute('href',`https://${thread[2]}/test/read.cgi/c/${thread[5]}/${thread[6]}/${thread[7]}`);
        }
    }

    // レス番を付与
    let post = document.getElementsByClassName("number");
    for (let i = 0; i < post.length; i++) {
        let anker = Number(post[i].innerHTML);
        post[i].setAttribute('onclick',`autoanker(${anker})`);
    }

    // 自動リロード
    if (TIMER != 0) {
        setTimeout(function() {
            location.reload();
        }, TIMER);
    }

})();