Greasy Fork

Greasy Fork is available in English.

Keylol Sticky Reply

Keylol 置顶热门回复

目前为 2021-06-09 提交的版本,查看 最新版本

// ==UserScript==
// @name         Keylol Sticky Reply
// @namespace    http://greasyfork.icu/users/34380
// @version      20210609
// @description  Keylol 置顶热门回复
// @match        https://keylol.com/t*
// @match        https://keylol.com/forum.php?mod=viewthread*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    var phr = document.querySelector('.steamcn_phr');
    var links = phr.querySelectorAll('.phr_quick_jump.phr_blue');
    for (var i = 0; i < links.length; i++) {
        var href = links[i].href;
        var pid = href.replace(/.*pid=(\d+)/, "$1");
        var num = links[i].innerText.replace('来自 #', '');
        if (num > 30) {
            insertPost(href, pid);
        } else {
            var post = document.querySelector('#post_' + pid);
            phr.parentNode.insertAdjacentElement('afterend', post);
        }
    }

    function insertPost(link, pid) {
        fetch(link).then(res => res.text()).then(text => {
            var post = (new DOMParser()).parseFromString(text, 'text/html').querySelector('#post_' + pid);
            phr.parentNode.insertAdjacentElement('afterend', post);
        })
    }
})();