SH Permalinks for Comments

Convert the timestamps on ScribbleHub chapter comments into permalinks to make sharing comments easier.

À partir de 2020-08-16. Voir la dernière version.

// ==UserScript==
// @name         SH Permalinks for Comments
// @namespace    ultrabenosaurus.ScribbleHub
// @version      1.0
// @description  Convert the timestamps on ScribbleHub chapter comments into permalinks to make sharing comments easier.
// @author       Ultrabenosaurus
// @source       https://greasyfork.org/en/users/437117-ultrabenosaurus?sort=name
// @match        https://www.scribblehub.com/read/*/chapter/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var SHcomments = document.querySelectorAll('div#comments div.comment_list_main li[id^="comment-"][class^="cmt_li_chp"]');
    if( SHcomments.length > 0 ) {
        UBaddCommentPermalinks(SHcomments);
    }
    SHcomments = null;
})();

function UBaddCommentPermalinks(SHcomments) {
    var permalinkTemplate = "<a class='com_date' title='%timestamp%' href='%id%'>%when%</a>";

    for (var comm in SHcomments) {
        if (SHcomments.hasOwnProperty(comm)) {
            var commID = SHcomments[comm].id.split('-')[1];
            var commDate = SHcomments[comm].querySelectorAll('div.comment-author.chapter span.com_date')[0];

            var commTimestamp = commDate.title;
            var commWhen = commDate.textContent;
            var commLink = permalinkTemplate.replace("%id%", "#comment-"+commID).replace("%timestamp%", commTimestamp).replace("%when%", commWhen);

            commDate.insertAdjacentHTML("beforebegin", commLink);
            commDate.remove();

            commID = commDate = commTimestamp = commWhen = commLink = null;
        }
    }
    comm = permalinkTemplate = SHcomments = null;
}