Git Hub - Unroll comments

Adds a button to load (unroll) all "hidden items" (comments).

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name     Git Hub - Unroll comments
// @description Adds a button to load (unroll) all "hidden items" (comments).
// @author   monnef
// @version  1
// @match    https://github.com/**
// @grant    none
// @namespace   monnef.eu
// @require  https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// ==/UserScript==


// settings

const workTime = 500;
const initDelay = 1000;
const scrollingEnabled = true;
const debugLogs = false;

// end of settings

const logPrefix = '[GHUC] ';
const log = (...xs) => console.log(logPrefix, ...xs);
const debug = (...xs) => debugLogs && console.debug(logPrefix, ...xs);

const scrollTo = (_, e) => scrollingEnabled && e.scrollIntoView({behavior: 'smooth', block: 'center'});

const getPagForm = () => $('.ajax-pagination-form');

const getPagBut = () => $('.ajax-pagination-btn');

const clickLoadMore = () => {
  debug('click load more button');
  getPagBut().click();
};

const work = () => {
  if(getPagForm()[0]) {
    const but = getPagBut();
    if (but.text().includes("Loading")) {
      debug("waiting until comments loading finishes...");
      but.each(scrollTo);
    } else {
	    clickLoadMore();
    }
    setTimeout(work, workTime);
  } else {
    debug('pagination form not found, assuming all comments are unrolled');
    $('.js-timeline-item').last().each(scrollTo);
  }
};

const init = () => {
  log('Git Hub - Unroll Comments by monnef is starting...')
  const but = $('<button/>')
    .text('Load all 🧻')
    .attr('title', '[GHUC] Git Hub - Unroll comments by monnef')
    .attr('class', 'btn mt-2')
    .click(() => {
      but.remove();
      work();
    });
  getPagForm().append(but);
  debug('initialized');
};

$(() => setTimeout(init, initDelay));