Fix Order of GitHub Dashboard

Orders entries on the GitHub dashboard page from the newest one to the oldest one on the page load.

目前為 2024-12-08 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Fix Order of GitHub Dashboard
// @namespace    http://prantlf.me/
// @version      1.2
// @description  Orders entries on the GitHub dashboard page from the newest one to the oldest one on the page load.
// @author       [email protected]
// @license      MIT
// @match        https://github.com/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=github.com
// @grant        none
// ==/UserScript==

(function() {
  'use strict';
  let retries = 20
  const interval = setInterval(reorder, 500)
  function reorder() {
    const feed = document.getElementById('conduit-feed-frame')
    if (!feed) {
      console.log('no articles found')
      if (!--retries) {
        clearInterval(interval)
      }
      return
    }
    clearInterval(interval)
    const articles = Array
      .from(feed.children)
      .filter(({ tagName }) => tagName === 'ARTICLE')
    for (const article of articles) {
      const div = article.nextElementSibling
      article.div = div
      const time = article.querySelector('relative-time')
      article.time = time && new Date(time.getAttribute('datetime')) || new Date
      article.remove()
      div.remove()
    }
    articles.sort((l, r) => l.time < r.time ? 1 : l.time > r.time ? -1 : 0)
    let current = feed.firstElementChild
    for (const article of articles) {
      const { div } = article
      current.insertAdjacentElement('afterend', article)
      article.insertAdjacentElement('afterend', div)
      delete article.div
      delete article.time
      current = div
    }
    console.log(articles.length, 'articles reordered')
  }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址