Greasy Fork

Greasy Fork is available in English.

2ch過去ログ(タイピ)URL自動変更

kakoにリンクを変更

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         2ch過去ログ(タイピ)URL自動変更
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  kakoにリンクを変更
// @author       tube
// @match        https://kako.5ch.net/test/read.cgi/pc/*
// @match        https://kako.5ch.net/test/read.cgi/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=5ch.net
// @grant        none
// @license MIT
// ==/UserScript==


function hrefConvert(){
    let aTags = document.querySelectorAll('a');
    aTags.forEach((v) => {
        const HREF = v.href;

        // 変換済みスキップ
        if (HREF.startsWith('https://kako.5ch.net/test/read.cgi')) return;

        let url = null;

        if (HREF.endsWith('.html')) {
            const match = HREF.match(/\/(\d+)\.html$/);
            if (match) url = match[1];
        } else {
            const patterns = [/read\.cgi\/pc\/(\d+)/, /read\.cgi\?bbs=pc\&key=(\d+)/, /read\.cgi\/hobby\/(\d+)\.*/, /read\.cgi\/.+\/(\d+)\.*/ ];

            let match = patterns.find(pattern => HREF.match(pattern));
            if (match){
                url = HREF.match(match)[0]
            }

        }

        if (url) {
            //とりあえず背景変えてわかりやすくしとく
            v.href = locationChange(url);
            v.style.backgroundColor = '#b6b9ff';
        }
    });

    function locationChange(url) {
        return 'https://kako.5ch.net/test/' + url;
    }
}

window.addEventListener('load', () => {
    setTimeout(hrefConvert, 500);
});