话不多说,直接上图片和油猴代码:
代码更新在28楼:
代码复制,如有更好的实现方式欢迎佬友们提出:
// ==UserScript==
// @name Linux.do按帖子创建时间排序
// @namespace http://tampermonkey.net/
// @version 1.0
// @description 在 Linux.do 网页上修改链接和增加新链接
// @author 马克思
// @match https://linux.do/*
// @match https://linux.do/latest
// @match https://linux.do/latest?order=created
// @grant none
// @icon https://www.google.com/s2/favicons?sz=64&domain=linux.do
// ==/UserScript==
(function() {
'use strict';
function modifyAndAddButtons() {
const latestButton = document.querySelector('a[href="/latest"][class="active"][aria-current="true"]');
if (latestButton && !latestButton.getAttribute('data-modified')) {
latestButton.textContent = '最新回复';
latestButton.setAttribute('data-modified', 'true');
const newlyCreatedButton = latestButton.cloneNode(true);
newlyCreatedButton.textContent = '最新创建';
newlyCreatedButton.href = '/latest?order=created';
newlyCreatedButton.removeAttribute('aria-current');
newlyCreatedButton.style.marginLeft = '10px';
newlyCreatedButton.setAttribute('data-modified', 'true');
latestButton.parentNode.insertBefore(newlyCreatedButton, latestButton.nextSibling);
}
}
const observer = new MutationObserver(function(mutationsList, observer) {
for(let mutation of mutationsList) {
if (mutation.type === 'childList') {
modifyAndAddButtons();
}
}
});
const config = { childList: true, subtree: true };
const targetNode = document.body;
observer.observe(targetNode, config);
modifyAndAddButtons();
})();