Greasy Fork

SB/SV add threadmark at top of post

Add button to create threadmark at top of post

目前为 2023-03-20 提交的版本。查看 最新版本

// ==UserScript==
// @name        SB/SV add threadmark at top of post
// @namespace   https://greasyfork.org/en/users/13408-mistakenot
// @match       https://forums.spacebattles.com/threads/*
// @match       https://forums.sufficientvelocity.com/threads/*
// @grant       none
// @version     0.1
// @author      -
// @description Add button to create threadmark at top of post
// @license     Mozilla Public License, v. 2.0
// ==/UserScript==
 
(function () {
    // Make <li> tag with new link.
    const makeLink = (id, title, symbol) => {
        const newLink = document.createElement('a');
        newLink.href = '/posts/' + id + '/add-threadmark';
        newLink.title = title;
        newLink.setAttribute('data-xf-click', 'overlay');
        newLink.appendChild(document.createTextNode(symbol));
 
        const liTag = document.createElement('li');
        liTag.appendChild(newLink);
        return liTag;
    }
 
    // Get message ids from messageTags and make in hashLinks
    const messageTags = [...document.querySelectorAll('.message-attribution-opposite--list > li')]
    .filter(x => /^#[\d,]+$/.test(x.textContent.trim()));
    const ids = messageTags.map(x => x.closest('article').id);

    for (let i = 0; i < messageTags.length; i++) {
        // Add threadmark link to current post
        const currentPost = makeLink(ids[i].substring(8), "ADD THREADMARK", '⭐');
        messageTags[i].parentElement.insertBefore(currentPost, messageTags[i]);
    }
})();