Skip to content

Instantly share code, notes, and snippets.

@6david9
Last active April 14, 2023 07:01
Show Gist options
  • Save 6david9/4af3a064d349e336c5d0dccdf384bbe1 to your computer and use it in GitHub Desktop.
Save 6david9/4af3a064d349e336c5d0dccdf384bbe1 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name v2ex_comment
// @namespace http://tampermonkey.net/
// @version 0.1
// @description simplify comment cell.
// @author 6david9
// @match https://*.v2ex.com/t/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=v2ex.com
// @require https://code.jquery.com/jquery-3.6.3.min.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
/* globals jQuery, $, waitForKeyElements */
const comment_container = $("#Main > div:nth-child(4)");
if (comment_container.length == 0) {
return;
}
const cells = comment_container.find("div.cell");
for (let i = 0; i < cells.length; ++i) {
const cell = cells[i];
const titleElem = $(cell).find("strong>a");
const commentElem = $(cell).find(".reply_content");
const timeElem = $(cell).find("span.ago");
let replacedCell = $("<div></div>").addClass("cell");
let infoLine = $("<div></div>");
if (typeof(titleElem) !== "undefined" && titleElem.length > 0) {
const aElem = titleElem.first().attr({"target": "_blank"});
const titleSpan = $("<span style='margin-right: 5px; font-size: 12px;'></span>").append(aElem[0]);
infoLine.append(titleSpan);
}
if (typeof(timeElem) !== "undefined" && timeElem.length > 0) {
const timeSpan = $("<span style='color: lightgray; font-size: 12px;'><span>").append(timeElem.first().attr("title"));
infoLine.append(timeSpan);
}
if (typeof(commentElem) !== "undefined" && commentElem.length > 0) {
const commentSpan = $("<span></span>").append(commentElem.first().text());
replacedCell.append(commentSpan);
}
replacedCell.append(infoLine);
$(cell).replaceWith(replacedCell);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment