SH Permalinks for Comments

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

目前為 2020-08-16 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         SH Permalinks for Comments
// @namespace    ultrabenosaurus.ScribbleHub
// @version      0.2
// @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;

    var SHcommentPagination = document.querySelectorAll('div[class*="comments-pagination"] ul#pagination-mesh li:not(.active) a.page-link');
    if( SHcommentPagination.length > 0 ) {
        UBaddPaginationEvents(SHcommentPagination);
    }
    SHcommentPagination = null;
})();

function UBaddCommentPermalinks(SHcomments) {
    var permalinkTemplate = "<a class='com_date' title='%timestamp%' href='%perma%'>%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("%perma%", "#comment-"+commID).replace("%timestamp%", commTimestamp).replace("%when%", commWhen);

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

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

function UBaddPaginationEvents(SHcommentPagination) {
    for (var pag in SHcommentPagination) {
        if (SHcommentPagination.hasOwnProperty(pag)) {
            SHcommentPagination[pag].addEventListener("click", UBpaginationEvent, false);
        }
    }
    SHcommentPagination = pag = null;
}

function UBpaginationEvent() {
    setTimeout(function(){
        UBaddCommentPermalinks( document.querySelectorAll('div#comments div.comment_list_main li[id^="comment-"][class^="cmt_li_chp"]') );
        UBaddPaginationEvents( document.querySelectorAll('div[class*="comments-pagination"] ul#pagination-mesh li:not(.active) a.page-link') );
    }, 1000);
}